diff --git a/app/src/androidTest/java/org/schabi/newpipe/plugin/PipePipePackageCompatibilityTest.kt b/app/src/androidTest/java/org/schabi/newpipe/plugin/PipePipePackageCompatibilityTest.kt index 6bf465f3e00..975b37f8f1c 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/plugin/PipePipePackageCompatibilityTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/plugin/PipePipePackageCompatibilityTest.kt @@ -7,6 +7,8 @@ package org.schabi.newpipe.plugin import android.content.Context import android.content.SharedPreferences +import android.graphics.BitmapFactory +import android.graphics.drawable.BitmapDrawable import android.os.Bundle import android.os.Parcel import androidx.preference.PreferenceManager @@ -361,6 +363,13 @@ class PipePipePackageCompatibilityTest { } assertEquals("wizestream", fixture.manifest.host) assertEquals("2.0", fixture.manifest.apiVersion) + assertEquals("icon.png", fixture.manifest.icon) + val encodedIcon = requireNotNull(PluginPackage.readIcon(fixture.file, fixture.manifest)) + val expectedIcon = requireNotNull(BitmapFactory.decodeByteArray(encodedIcon, 0, encodedIcon.size)) + val loadedIcon = PluginManager.getIcon(context, fixture.service.serviceId) as BitmapDrawable + assertEquals(256, loadedIcon.bitmap.width) + assertEquals(256, loadedIcon.bitmap.height) + assertTrue("The native service uses its signed package artwork", expectedIcon.sameAs(loadedIcon.bitmap)) assertEquals(1_772_767_428, fixture.service.serviceId) assertEquals("https://example.invalid/profile-fixture", fixture.service.baseUrl) assertEquals(profile.id, fixture.service.javaClass.getMethod("getBoundProfileId").invoke(fixture.service)) diff --git a/docs/plugins.md b/docs/plugins.md index 4baf58c84bc..91a783a2118 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -237,6 +237,7 @@ Its core fields are: "versionName": "1.0.0", "host": "wizestream", "apiVersion": "2.0", + "icon": "icon.png", "minHostVersionCode": 1052000, "minAndroidSdk": 24, "requiredCapabilities": ["profile-preferences"], @@ -283,8 +284,35 @@ settings and credentials; the host binds it to that profile. String and Boolean settings declared in `plugin.json` are rendered by the host. The context exposes their defaults and a change-listener interface. The settings screen also offers a restart -because some implementations cache their configuration. Optional icons are supported. Theme -color metadata is parsed, but this host retains WizeStream's own application theme. +because some implementations cache their configuration. Theme color metadata is parsed, but this +host retains WizeStream's own application theme. + +### Service icons + +A plugin can supply its service icon through the existing manifest field: + +```json +"icon": "icon.png" +``` + +Place that image at `src/main/resources/icon.png`, or use another package-relative +resource path and declare the same path in the manifest. The native template includes +an editable example vector and a 256 × 256 PNG. Replace the example with a +**single-color image on a transparent background**. The service selector tints its +icons, so an opaque background would hide the artwork under that tint. + +The encoded image must be no larger than **256 KiB**, with width and height each at +most **512 pixels**. PNG is recommended. The template's `pluginPackage` task checks +that the declared raster exists in the final archive, fits these limits, and decodes +successfully. An omitted or unusable icon falls back to the generic plugin symbol +without preventing an otherwise valid service from loading. + +WizeStream reads the image from the verified signed package and uses it in service +selection, the selected-service header, and relevant service pickers. No icon +download or additional plugin API is needed. Installation or update still requires a +restart before the new service artwork appears. Treat an icon change like any other +published package update: retain the plugin ID and signing key, increase `versionCode`, +and publish the matching signed package and catalog together. ### Shared libraries and packaging diff --git a/plugin-template/README.md b/plugin-template/README.md index 892c537ee59..35e8597960a 100644 --- a/plugin-template/README.md +++ b/plugin-template/README.md @@ -55,6 +55,25 @@ Set `ANDROID_HOME`, or put `sdk.dir=/absolute/path/android-sdk` in a local, untr Use `-PpluginSigningKey=/private/path/key.pk8` and `-PpluginPublicKey=/private/path/public.der` if keys are stored elsewhere. +## Give the service its own icon + +Replace `src/main/resources/icon.png` with your service's **square, single-color PNG +on a transparent background**. The sample is 256 × 256; the host accepts at most +512 × 512 pixels and 256 KiB. Do not add an opaque background: the service selector +tints the image for the active theme. The editable sample is +[`artwork/service-icon.svg`](artwork/service-icon.svg); rendering instructions are in +[artwork/README.md](artwork/README.md). + +Keep `"icon": "icon.png"` in `plugin.json`, or update it to the exact package-relative +path under `src/main/resources`. `pluginPackage` checks the final archive for the +declared image, validates its encoded size and dimensions, and decodes it before the +package can be signed. No new host API or remote icon URL is required. A missing icon +uses WizeStream's generic plugin symbol. + +After installation or update, restart WizeStream to load the new icon. Preserve the +plugin ID and signing key, and increase `versionCode` when changing artwork in an +already published plugin. + ## Replace the sample 1. Choose a permanent, unique `pluginId` and a service name that WizeStream does not already provide. diff --git a/plugin-template/artwork/README.md b/plugin-template/artwork/README.md new file mode 100644 index 00000000000..9637ace6dd8 --- /dev/null +++ b/plugin-template/artwork/README.md @@ -0,0 +1,18 @@ +# Example service icon + +`service-icon.svg` is the editable source for `../src/main/resources/icon.png`. +The PNG is a **256 × 256**, single-color image on a transparent background. WizeStream +tints service icons to match its light and dark themes; keep the background transparent. + +The SVG is original example artwork from WizeStream contributors, licensed under GPL-3.0-or-later. + +Render the checked-in PNG after changing the vector: + +```sh +inkscape artwork/service-icon.svg --export-type=png --export-width=256 --export-height=256 --export-filename=src/main/resources/icon.png +``` + +The build packages the existing PNG; it does not require Inkscape. The manifest's +`"icon": "icon.png"` refers to the path inside the signed `.ppp` archive. +`pluginPackage` checks that the declared raster is present, decodes successfully, is at +most **256 KiB**, and has dimensions no larger than **512 × 512**. diff --git a/plugin-template/artwork/service-icon.svg b/plugin-template/artwork/service-icon.svg new file mode 100644 index 00000000000..51efd625cc2 --- /dev/null +++ b/plugin-template/artwork/service-icon.svg @@ -0,0 +1,6 @@ + + Example streaming service icon + + + + diff --git a/plugin-template/build.gradle.kts b/plugin-template/build.gradle.kts index 8b73a9924a7..5fb2b16b53a 100644 --- a/plugin-template/build.gradle.kts +++ b/plugin-template/build.gradle.kts @@ -18,6 +18,7 @@ import java.security.spec.X509EncodedKeySpec import java.util.Base64 import java.util.Properties import java.util.zip.ZipFile +import javax.imageio.ImageIO plugins { `java-library` @@ -153,6 +154,30 @@ val pluginPackage by tasks.registering(Zip::class) { doLast { ZipFile(archiveFile.get().asFile).use { zip -> check(zip.getEntry("plugin.json") != null && zip.getEntry("classes.dex") != null) + (pluginManifest["icon"] as? String)?.let { iconPath -> + val iconEntry = checkNotNull(zip.getEntry(iconPath)) { + "Plugin package is missing its declared icon: $iconPath" + } + check(iconEntry.size in 1..(256L * 1024L)) { + "Plugin icon must be at most 256 KiB" + } + zip.getInputStream(iconEntry).use { source -> + ImageIO.createImageInputStream(source).use { imageInput -> + val readers = ImageIO.getImageReaders(imageInput) + check(readers.hasNext()) { "Plugin icon must be a decodable raster; use PNG" } + val reader = readers.next() + try { + reader.input = imageInput + check(reader.getWidth(0) in 1..512 && reader.getHeight(0) in 1..512) { + "Plugin icon dimensions must be at most 512 by 512 pixels" + } + check(reader.read(0) != null) { "Plugin icon cannot be decoded" } + } finally { + reader.dispose() + } + } + } + } val forbidden = listOf( "org/schabi/newpipe/", "kotlin/", diff --git a/plugin-template/src/main/resources/icon.png b/plugin-template/src/main/resources/icon.png new file mode 100644 index 00000000000..66280930f0f Binary files /dev/null and b/plugin-template/src/main/resources/icon.png differ diff --git a/plugin-template/src/main/resources/plugin.json b/plugin-template/src/main/resources/plugin.json index 66cab0c1c7e..b7f014fdbc2 100644 --- a/plugin-template/src/main/resources/plugin.json +++ b/plugin-template/src/main/resources/plugin.json @@ -5,6 +5,7 @@ "versionName": "1.0.0", "host": "wizestream", "apiVersion": "2.0", + "icon": "icon.png", "minHostVersionCode": 1052000, "minAndroidSdk": 24, "requiredCapabilities": ["profile-preferences"],