Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
32 changes: 30 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions plugin-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions plugin-template/artwork/README.md
Original file line number Diff line number Diff line change
@@ -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**.
6 changes: 6 additions & 0 deletions plugin-template/artwork/service-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions plugin-template/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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/",
Expand Down
Binary file added plugin-template/src/main/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions plugin-template/src/main/resources/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"versionName": "1.0.0",
"host": "wizestream",
"apiVersion": "2.0",
"icon": "icon.png",
"minHostVersionCode": 1052000,
"minAndroidSdk": 24,
"requiredCapabilities": ["profile-preferences"],
Expand Down
Loading