generated from SteamDeckHomebrew/decky-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
58 lines (47 loc) · 1.81 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
import asyncio
import asyncio.subprocess
import logging
import typing
import decky # type: ignore
import settings # type: ignore
HOME_DIR = decky.DECKY_HOME
PARENT_DIR = decky.DECKY_PLUGIN_DIR
logger = decky.logger
logger.setLevel(logging.DEBUG)
logging.info(f"ControllerTools main.py https://github.com/alphamercury/ControllerTools")
logger.info("[backend] Settings path: {}".format(decky.DECKY_PLUGIN_SETTINGS_DIR))
settings = settings.SettingsManager(name="settings", settings_directory=decky.DECKY_PLUGIN_SETTINGS_DIR)
settings.read()
class Plugin:
BACKEND_PROC: typing.Optional[asyncio.subprocess.Process] = None
@classmethod
async def _main(cls):
cls.BACKEND_PROC = await asyncio.subprocess.create_subprocess_exec(
PARENT_DIR + "/bin/backend",
f"{decky.DECKY_PLUGIN_SETTINGS_DIR}/settings.json",
decky.DECKY_PLUGIN_LOG,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
@classmethod
async def _unload(cls):
if cls.BACKEND_PROC is not None:
cls.BACKEND_PROC.terminate()
await cls.BACKEND_PROC.wait()
cls.BACKEND_PROC = None
@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, key: str, defaults: typing.Any):
logger.info("[backend] Get {}".format(key))
return settings.getSetting(key, defaults)
@classmethod
async def settings_setSetting(cls, key: str, value: typing.Any):
logger.info("[backend] Set {}: {}".format(key, value))
return settings.setSetting(key, value)