generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
64 lines (49 loc) · 1.71 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
#!/usr/bin/env python
import logging
import typing
from settings import SettingsManager # type: ignore
import decky # type: ignore
# Setup environment variables
settingsDir = decky.DECKY_PLUGIN_SETTINGS_DIR
loggingDir = decky.DECKY_PLUGIN_LOG_DIR
logger = decky.logger
# Setup backend logger
logger.setLevel(logging.DEBUG)
logger.info("[backend] Settings path: {}".format(settingsDir))
settings = SettingsManager(name="settings", settings_directory=settingsDir)
settings.read()
class SetSettingOptions(typing.TypedDict):
key: str
value: typing.Any
class GetSettingOptions(typing.TypedDict):
key: str
defaults: typing.Any
class Plugin:
@classmethod
async def _main(cls):
logger.info("[backend] Loading CheatDeck!")
@classmethod
async def _unload(cls):
logger.info("[backend] Unloading CheatDeck!")
@classmethod
async def _uninstall(cls):
logger.info("[backend] Uninstalling CheatDeck!")
@classmethod
async def settings_read(cls):
logger.info("[backend] Reading settings")
return settings.read()
@classmethod
async def settings_commit(cls):
logger.info("[backend] Saving settings")
return settings.commit()
@classmethod
async def settings_getSetting(cls, data: GetSettingOptions):
logger.info("[backend] Get {}".format(data["key"]))
return settings.getSetting(data["key"], data["defaults"])
@classmethod
async def settings_setSetting(cls, data: SetSettingOptions):
logger.info("[backend] Set {}: {}".format(data["key"], data["value"]))
return settings.setSetting(data["key"], data["value"])
@classmethod
async def get_env(cls, env: str):
return getattr(decky, env)