IDesktopPlugin.kt 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. package org.mjdev.desktop.plugins
  2. import org.mjdev.desktop.context.IDesktopContext
  3. import org.mjdev.desktop.plugins.remote.RemoteDocument
  4. import org.mjdev.desktop.plugins.remote.RemoteVariables
  5. /**
  6. * Contract implemented by every desktop widget plugin.
  7. *
  8. * A plugin describes its look as a [RemoteDocument] (data, not code) and feeds it live values
  9. * through [variables]; the desktop renders both with its own player. External plugins are jars
  10. * that register an implementation in `META-INF/services/org.mjdev.desktop.plugins.IDesktopPlugin`
  11. * and carry a `plugin.json` ([PluginMetadata]) at the jar root. One plugin per jar.
  12. */
  13. interface IDesktopPlugin {
  14. /** The widget layout. Read once when the plugin is enabled. */
  15. val document: RemoteDocument
  16. /** Period in milliseconds between two calls of [variables]. */
  17. val refreshMs: Long
  18. get() = PluginDefaults.DEFAULT_REFRESH_MS
  19. /** Produces the current values the [document] binds to. Called off the UI thread. */
  20. fun variables(context: IDesktopContext): RemoteVariables
  21. /** Called after the user enabled the plugin. */
  22. fun onEnabled() {}
  23. /** Called after the user disabled the plugin; release resources here. */
  24. fun onDisabled() {}
  25. }