summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorPhilipp Richter <richterphilipp.pops@gmail.com>2023-02-19 22:43:09 +0000
committerGitHub <noreply@github.com>2023-02-19 14:43:09 -0800
commit39f7aadf70ce9da779d3138183ce82ba10c0fd53 (patch)
tree5d6b27380f0bf2d75d00c55d2c8c6c0b7dccf406 /main.py
parentb05ecd55e7d049e0951b53fbe4aa2f329f9db905 (diff)
downloaddecky-bazzite-buddy-39f7aadf70ce9da779d3138183ce82ba10c0fd53.tar.gz
decky-bazzite-buddy-39f7aadf70ce9da779d3138183ce82ba10c0fd53.zip
Add support for the 'decky_plugin' module exposed by decky-loader (#16)
* Add support for the 'decky_plugin' module exposed by decky-loader * Make versioned 'decky_plugin.pyi' stub interface and 'py_modules' support available * Add rule to ignore 'decky_plugin.py'
Diffstat (limited to 'main.py')
-rw-r--r--main.py39
1 files changed, 29 insertions, 10 deletions
diff --git a/main.py b/main.py
index c0ec3ff..882cb30 100644
--- a/main.py
+++ b/main.py
@@ -1,11 +1,10 @@
-import logging
+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
-logging.basicConfig(filename="/tmp/template.log",
- format='[Template] %(asctime)s %(levelname)s %(message)s',
- filemode='w+',
- force=True)
-logger=logging.getLogger()
-logger.setLevel(logging.INFO) # can be changed to logging.DEBUG for debugging issues
class Plugin:
# A normal method. It can be called from JavaScript using call_plugin_function("method_1", argument1, argument2)
@@ -14,9 +13,29 @@ class Plugin:
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
- logger.info("Hello World!")
-
+ decky_plugin.logger.info("Hello World!")
+
# Function called first during the unload process, utilize this to handle your plugin being removed
async def _unload(self):
- logger.info("Goodbye World!")
+ decky_plugin.logger.info("Goodbye World!")
pass
+
+ # 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"))