Files
saphid--frame-control/examples/framey-settings/main.py
T
Alex SouthwellandSAPHID 289a971c90 Add Decky settings sample for Framey plugin authors (#233)
* Provide Decky automatic JSX runtime in Framey panel

* Add Decky settings sample for Framey authors

* Use official Decky settings path in sample backend

---------

Co-authored-by: SAPHID <saphid@users.noreply.github.com>
2026-10-25 09:39:01 +00:00

42 lines
1.4 KiB
Python

"""Small, unprivileged Decky backend for the Framey author example."""
import json
import os
from pathlib import Path
import tempfile
import decky
def settings_file():
# Decky provides this per-plugin path through its official Python module.
return Path(decky.decky_SETTINGS_DIR) / 'settings.json'
class Plugin:
async def get_setting(self, key: str, default=False):
if key != 'enabled':
raise ValueError('Unknown setting')
try:
stored = json.loads(settings_file().read_text())
except FileNotFoundError:
return default
return stored.get(key, default)
async def set_setting(self, key: str, value: bool):
if key != 'enabled' or type(value) is not bool:
raise ValueError('Expected an enabled boolean')
target = settings_file()
target.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
temporary = None
try:
with tempfile.NamedTemporaryFile('w', encoding='utf-8', dir=target.parent,
prefix='.settings-', delete=False) as output:
temporary = Path(output.name)
json.dump({'enabled': value}, output)
output.write('\n')
temporary.chmod(0o600)
os.replace(temporary, target)
finally:
if temporary is not None:
temporary.unlink(missing_ok=True)
return True