-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (52 loc) · 2.02 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
import decky # type: ignore
import json
import os
metadata_file_name = "metadata.json"
class Plugin:
async def get_file_size(self, route: str):
return os.path.getsize(route)
async def get_file_creation_time(self, route: str):
return os.path.getctime(route)
async def save_metadata(self, data):
with open(
os.path.join(decky.DECKY_PLUGIN_RUNTIME_DIR, metadata_file_name),
"w",
encoding="utf-8",
) as file:
json.dump(data, file, ensure_ascii=False, indent=2)
async def get_metadata(self):
with open(
os.path.join(decky.DECKY_PLUGIN_RUNTIME_DIR, metadata_file_name), "r"
) as file:
return json.load(file)
async def _create_metadata_file_if_needed(self):
if not os.path.exists(
os.path.join(decky.DECKY_PLUGIN_RUNTIME_DIR, metadata_file_name)
):
with open(
os.path.join(decky.DECKY_PLUGIN_RUNTIME_DIR, metadata_file_name), "w"
) as file:
json.dump(
{
"syncIntervalDays": 1,
"lastSyncDate": None,
"gamesMetadata": [],
},
file,
ensure_ascii=False,
indent=2,
)
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
decky.logger.info("Hello, World!")
await self._create_metadata_file_if_needed()
# Function called first during the unload process, utilize this to handle your plugin being stopped, but not
# completely removed
async def _unload(self):
decky.logger.info("Goodnight, World!")
pass
# Function called after `_unload` during uninstall, utilize this to clean up processes and other remnants of your
# plugin that may remain on the system
async def _uninstall(self):
decky.logger.info("Goodbye, World!")
pass