Plugin Permissions
Plugins declare the capabilities they need in their manifest. Users choose what to grant when they enable a plugin. This guide covers declarations, permission checks, denials, and the authorization lifecycle. For project setup, see the Developer Quickstart.
Declare Permissions in Gradle
import com.xuncorp.spw.workshop.gradle.PluginPermission
spmod {
PluginClass = "com.example.MyPlugin"
PluginId = "com.example.my-plugin"
PluginVersion = "1.0.0"
PluginPermissions = listOf(PluginPermission.KEY_BINDINGS, PluginPermission.LIBRARY_READ)
}import com.xuncorp.spw.workshop.gradle.PluginPermission
spmod { config ->
config.PluginClass = 'com.example.MyPlugin'
config.PluginId = 'com.example.my-plugin'
config.PluginVersion = '1.0.0'
config.PluginPermissions = [PluginPermission.KEY_BINDINGS, PluginPermission.LIBRARY_READ]
}PluginPermissions is a List<PluginPermission>. It defaults to an empty list, and leaving it unset or setting it to null requests no permissions. The list accepts the Gradle plugin's enum values and deduplicates repeated entries. Strings cause a compilation error in Kotlin DSL. In Groovy, the dynamic list reports a configuration error for strings or null entries.
| Gradle enum | Manifest value | API constant | Capability |
|---|---|---|---|
PluginPermission.KEY_BINDINGS | key-bindings | PluginPermission.KEY_BINDINGS | Register in-app shortcuts and allow users to configure global shortcuts with hasGlobal. |
PluginPermission.LIBRARY_READ | library-read | PluginPermission.LIBRARY_READ | Read metadata, file paths, favorite status, and embedded artwork, including queries about the current track. |
PluginPermission.LIBRARY_WRITE | library-write | PluginPermission.LIBRARY_WRITE | Write library data. Reserved for future APIs. |
PluginPermission.CLASS_TRANSFORM | class-transform | PluginPermission.CLASS_TRANSFORM | Register host method and UI hooks that change player behavior. This is the highest-risk permission. Grant it only to plugins you fully trust. |
Read and write are separate permissions. Declare only what the plugin uses. Current library queries require LIBRARY_READ.
Method and UI Hooks
With CLASS_TRANSFORM declared and granted, a plugin can use WorkshopApi.hookRegistrar to register method and UI hooks. Disabling or uninstalling the plugin, or revoking its permission, stops new callbacks and restores the original behavior. The manifest identifier is class-transform.
See Direct Hook API for the Kotlin DSL, Java callbacks, and restrictions. The host handles bytecode transformation.
Check Permissions and Handle Denials
WorkshopApi.manager.isPermissionGranted(permission) checks a permission synchronously for the actual caller. It can run on any thread and neither prompts the user nor loads the plugin. It returns false if the permission was undeclared or denied, if the caller is unrecognized, or if the calling class loader has been unloaded. Caching or passing a manager reference does not change the caller used for the check.
Import com.xuncorp.spw.workshop.api.PluginPermission in runtime code and com.xuncorp.spw.workshop.gradle.PluginPermission in Gradle. In these examples, the plugin supplies openPanel() and registers the shortcut on the thread running start().
override fun start() {
if (WorkshopApi.manager.isPermissionGranted(PluginPermission.KEY_BINDINGS)) {
try {
WorkshopApi.manager.keyBindingManager.register(
actionId = "open-panel",
title = "Open panel",
defaultShortcut = null,
handler = Runnable { openPanel() }
)
} catch (denied: PluginPermissionDeniedException) {
// Keep other plugin features available without the shortcut.
}
}
}@Override
public void start() {
if (WorkshopApi.manager().isPermissionGranted(PluginPermission.KEY_BINDINGS)) {
try {
WorkshopApi.manager().getKeyBindingManager().register(
"open-panel",
"Open panel",
null,
false,
this::openPanel
);
} catch (PluginPermissionDeniedException denied) {
// Keep other plugin features available without the shortcut.
}
}
}If the permission was undeclared or denied, register synchronously throws PluginPermissionDeniedException. Its pluginId and permission identify the caller and required permission. It extends SecurityException, with Java getters getPluginId() and getPermission(). Caller attribution, registration timing, and parameter constraints still apply. Unregistering and closing registration handles require no permission.
Read the Music Library
WorkshopApi.library requires LIBRARY_READ for getTrackById, getAllTracks, getTracks, and getCoverById. When permission is denied, the call returns a failed CompletionStage without starting a read. The host identifies the plugin on the calling thread and checks permission and load identity again before reading and before delivering the result. Caching or passing a Library reference does not transfer authorization.
if (WorkshopApi.manager
.isPermissionGranted(PluginPermission.LIBRARY_READ)
) {
WorkshopApi.library.getTracks(afterId = null, limit = 20)
.whenComplete { tracks, failure ->
val cause = (failure as? java.util.concurrent.CompletionException)?.cause ?: failure
when (cause) {
null -> tracks.forEach { println(it.title) }
is PluginPermissionDeniedException -> println("Library read permission is unavailable")
else -> cause.printStackTrace()
}
}
}if (WorkshopApi.manager()
.isPermissionGranted(PluginPermission.LIBRARY_READ)
) {
WorkshopApi.library()
.getTracks(null, 20)
.whenComplete((tracks, failure) -> {
Throwable cause = failure instanceof java.util.concurrent.CompletionException
? failure.getCause() : failure;
if (cause == null) {
tracks.forEach(track -> System.out.println(track.getTitle()));
} else if (cause instanceof PluginPermissionDeniedException) {
System.out.println("Library read permission is unavailable");
} else {
cause.printStackTrace();
}
});
}Use the initial check to decide which features to offer, and still handle failures from the actual operation. Playback.getCurrentMediaItem() also requires LIBRARY_READ, even with no current track. It throws synchronously if permission is missing at the time of the call. A denial during the query is reported as the cause of a CompletionException. New calls from unrecognized or unloaded classes are denied with a pluginId of unknown.
Disabling a plugin preserves its grants, and accepted queries can still finish. Revoking access or uninstalling a plugin before delivery causes the query to fail. After a plugin with the same ID is reloaded, old calls and classes retain their original authorization context. Snapshots already delivered remain available. Cancelling a converted future may leave the underlying read running.
User Choices and Lifecycle
- On first enable, the player shows requested permissions and their purpose in the enable dialog. New permissions are unchecked by default. A user can enable a plugin without granting them. Use permission checks to keep available features working. An unhandled registration denial causes startup to fail
- After confirmation, the player saves the grant and denial choices, then calls
start(). Cancelling the dialog preserves saved choices - Restarts, disabling, and ordinary updates preserve decisions. Users can change them by disabling the plugin and adjusting the checkboxes when enabling it again
- When an update adds permissions, automatic startup pauses until the user reviews them. The same applies when a dependency is waiting for review
- Unknown permissions appear as unsupported and cannot be granted
- Deleting a local plugin or unsubscribing on Steam clears decisions, and reinstalling requires fresh approval. Unloading the class loader as part of an update preserves decisions
- Declare permissions for every protected capability you use and handle user denials
The permission query has a JVM default implementation that returns false, preserving compatibility with older Manager implementations. Consumers need an API JAR that contains the method.
Permissions control capabilities offered by Workshop API. Plugins run inside the host JVM, so these declarations and checks do not isolate plugins in an operating system sandbox.
See also Developer Quickstart, Plugin Configuration, and Direct Hook API.
