generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
63 lines (52 loc) · 2.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
from settings import SettingsManager
# Get environment variable
settingsDir = os.environ["DECKY_PLUGIN_SETTINGS_DIR"]
settings = SettingsManager(name="settings", settings_directory=settingsDir)
settings.read()
class Plugin:
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
pass
# Function called first during the unload process, utilize this to handle your plugin being removed
async def _unload(self):
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"
),
)
async def settings_load(self, key: str, defaults):
decky_plugin.logger.info("Get {}".format(key))
return settings.getSetting(key, defaults)
async def settings_save(self, key: str, value):
decky_plugin.logger.info("Set {}: {}".format(key, value))
return settings.setSetting(key, value)