2023-02-19 22:43:09 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# The decky plugin module is located at decky-loader/plugin
|
|
|
|
# For easy intellisense checkout the decky-loader code one directory up
|
|
|
|
# or add the `decky-loader/plugin` path to `python.analysis.extraPaths` in `.vscode/settings.json`
|
|
|
|
import decky_plugin
|
2022-08-25 02:06:26 +01:00
|
|
|
|
|
|
|
|
2022-04-22 23:42:11 +01:00
|
|
|
class Plugin:
|
|
|
|
# A normal method. It can be called from JavaScript using call_plugin_function("method_1", argument1, argument2)
|
|
|
|
async def add(self, left, right):
|
|
|
|
return left + right
|
|
|
|
|
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
|
|
|
async def _main(self):
|
2023-02-19 22:43:09 +00:00
|
|
|
decky_plugin.logger.info("Hello World!")
|
|
|
|
|
2024-07-24 23:01:55 +01:00
|
|
|
# Function called first during the unload process, utilize this to handle your plugin being stopped, but not
|
|
|
|
# completely removed
|
2022-10-23 02:48:59 +01:00
|
|
|
async def _unload(self):
|
2024-07-24 23:01:55 +01:00
|
|
|
decky_plugin.logger.info("Goodnight World!")
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Function called after `_unload` during uninstall, utilize this to clean up processes and other remnants of your
|
|
|
|
# plugin that may remain on the system
|
|
|
|
async def _uninstall(self):
|
2023-02-19 22:43:09 +00:00
|
|
|
decky_plugin.logger.info("Goodbye World!")
|
2022-04-22 23:42:11 +01:00
|
|
|
pass
|
2023-02-19 22:43:09 +00:00
|
|
|
|
|
|
|
# Migrations that should be performed before entering `_main()`.
|
|
|
|
async def _migration(self):
|
|
|
|
decky_plugin.logger.info("Migrating")
|
|
|
|
# Here's a migration example for logs:
|
|
|
|
# - `~/.config/decky-template/template.log` will be migrated to `decky_plugin.DECKY_PLUGIN_LOG_DIR/template.log`
|
|
|
|
decky_plugin.migrate_logs(os.path.join(decky_plugin.DECKY_USER_HOME,
|
|
|
|
".config", "decky-template", "template.log"))
|
|
|
|
# Here's a migration example for settings:
|
|
|
|
# - `~/homebrew/settings/template.json` is migrated to `decky_plugin.DECKY_PLUGIN_SETTINGS_DIR/template.json`
|
|
|
|
# - `~/.config/decky-template/` all files and directories under this root are migrated to `decky_plugin.DECKY_PLUGIN_SETTINGS_DIR/`
|
|
|
|
decky_plugin.migrate_settings(
|
|
|
|
os.path.join(decky_plugin.DECKY_HOME, "settings", "template.json"),
|
|
|
|
os.path.join(decky_plugin.DECKY_USER_HOME, ".config", "decky-template"))
|
|
|
|
# Here's a migration example for runtime data:
|
|
|
|
# - `~/homebrew/template/` all files and directories under this root are migrated to `decky_plugin.DECKY_PLUGIN_RUNTIME_DIR/`
|
|
|
|
# - `~/.local/share/decky-template/` all files and directories under this root are migrated to `decky_plugin.DECKY_PLUGIN_RUNTIME_DIR/`
|
|
|
|
decky_plugin.migrate_runtime(
|
|
|
|
os.path.join(decky_plugin.DECKY_HOME, "template"),
|
|
|
|
os.path.join(decky_plugin.DECKY_USER_HOME, ".local", "share", "decky-template"))
|