diff options
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 50 |
1 files changed, 29 insertions, 21 deletions
@@ -1,41 +1,49 @@ 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 - +# For easy intellisense checkout the decky-loader code repo +# and add the `decky-loader/plugin/imports` path to `python.analysis.extraPaths` in `.vscode/settings.json` +import decky +import asyncio 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): + # A normal method. It can be called from the TypeScript side using @decky/api. + async def add(self, left: int, right: int) -> int: return left + right + async def long_running(self): + await asyncio.sleep(15) + await decky.emit("test_event", "Hello from the backend!", True, 2) + # Asyncio-compatible long-running code, executed in a task when the plugin is loaded async def _main(self): - decky_plugin.logger.info("Hello World!") + self.loop = asyncio.get_event_loop() + decky.logger.info("Hello World!") # Function called first during the unload process, utilize this to handle your plugin being removed async def _unload(self): - decky_plugin.logger.info("Goodbye World!") + decky.logger.info("Goodbye World!") pass + async def start_timer(self): + self.loop.create_task(self.long_running()) + # Migrations that should be performed before entering `_main()`. async def _migration(self): - decky_plugin.logger.info("Migrating") + decky.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` will be migrated to `decky.decky_LOG_DIR/template.log` + decky.migrate_logs(os.path.join(decky.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")) + # - `~/homebrew/settings/template.json` is migrated to `decky.decky_SETTINGS_DIR/template.json` + # - `~/.config/decky-template/` all files and directories under this root are migrated to `decky.decky_SETTINGS_DIR/` + decky.migrate_settings( + os.path.join(decky.DECKY_HOME, "settings", "template.json"), + os.path.join(decky.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")) + # - `~/homebrew/template/` all files and directories under this root are migrated to `decky.decky_RUNTIME_DIR/` + # - `~/.local/share/decky-template/` all files and directories under this root are migrated to `decky.decky_RUNTIME_DIR/` + decky.migrate_runtime( + os.path.join(decky.DECKY_HOME, "template"), + os.path.join(decky.DECKY_USER_HOME, ".local", "share", "decky-template")) |
