-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
121 lines (89 loc) · 2.78 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import asyncio
import os
import decky
from settings import SettingsManager
from typing import TypeVar
Initialized = False
T = TypeVar("T")
def log(txt):
decky.logger.info(txt)
def warn(txt):
decky.logger.warn(txt)
def error(txt):
decky.logger.error(txt)
class Plugin:
demo: str
settings: SettingsManager
async def logMessage(self, message, level):
if level == 0:
log(message)
elif level == 1:
warn(message)
elif level == 2:
error(message)
# * Plugin settings getters
async def get_demo(self) -> dict[str, dict] | None:
"""
Waits until demo is loaded, then returns demo
:return: The demo string
"""
while Plugin.users_dict is None:
await asyncio.sleep(0.1)
return Plugin.demo
# TODO: define additional settings getters here
# * Plugin settings setters
async def set_demo(self, demo: str):
Plugin.demo = demo
await Plugin.set_setting(self, "demo", Plugin.demo)
# Core Plugin methods
async def read(self) -> None:
"""
Reads the json from disk
"""
Plugin.settings.read()
# TODO: assign your settings to plugin properties here
Plugin.demo = await Plugin.get_setting(self, "demo", "Show Toast")
# TODO: define additional settings setters here
# Plugin settingsManager wrappers
async def get_setting(self, key, default: T) -> T:
"""
Gets the specified setting from the json
:param key: The key to get
:param default: The default value
:return: The value, or default if not found
"""
return Plugin.settings.getSetting(key, default)
async def set_setting(self, key, value: T) -> T:
"""
Sets the specified setting in the json
:param key: The key to set
:param value: The value to set it to
:return: The new value
"""
Plugin.settings.setSetting(key, value)
return value
def del_setting(self, key) -> None:
"""
Deletes the specified setting in the json
"""
del Plugin.settings.settings[key]
Plugin.settings.commit()
pass
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
global Initialized
if Initialized:
return
Initialized = True
Plugin.settings = SettingsManager(name="settings", settings_directory=os.environ["DECKY_PLUGIN_SETTINGS_DIR"])
await Plugin.read(self)
log("Initializing QuickStart.")
# Function called first during the unload process, utilize this to handle your plugin being removed
async def _unload(self):
decky.logger.info("Unloading Plugin.")
# Function called when the plugin is uninstalled
async def _uninstall(self):
decky.logger.info("Uninstalling Plugin.")
# Migrations that should be performed before entering `_main()`.
async def _migration(self):
pass