diff options
| author | AAGaming <aa@mail.catvibers.me> | 2022-08-24 23:51:20 -0400 |
|---|---|---|
| committer | AAGaming <aa@mail.catvibers.me> | 2022-08-24 23:51:20 -0400 |
| commit | 79db0c779d6942c6bdc6823a5faef57b5307f7b3 (patch) | |
| tree | 3ba46c46750d7cdfc04f6c14191e0dd1177c170f /backend | |
| parent | fe2b6b02831c918c25d88604df94d8d2f360b75a (diff) | |
| download | decky-loader-79db0c779d6942c6bdc6823a5faef57b5307f7b3.tar.gz decky-loader-79db0c779d6942c6bdc6823a5faef57b5307f7b3.zip | |
Settings API for loader, preview branch select
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/main.py | 7 | ||||
| -rw-r--r-- | backend/settings.py | 38 | ||||
| -rw-r--r-- | backend/utilities.py | 9 |
3 files changed, 47 insertions, 7 deletions
diff --git a/backend/main.py b/backend/main.py index a5730fbd..41ecfc77 100644 --- a/backend/main.py +++ b/backend/main.py @@ -18,6 +18,7 @@ from injector import inject_to_tab, tab_has_global_var from loader import Loader from updater import Updater from utilities import Utilities +from settings import SettingsManager # Ensure USER and GROUP vars are set first. # TODO: This isn't the best way to do this but supports the current @@ -48,9 +49,6 @@ async def chown_plugin_dir(_): if code_chown != 0 or code_chmod != 0: logger.error(f"chown/chmod exited with a non-zero exit code (chown: {code_chown}, chmod: {code_chmod})") -def remote_debugging_allowed(): - return path.exists(HOMEBREW_PATH + "/allow_remote_debugging") - class PluginManager: def __init__(self) -> None: self.loop = get_event_loop() @@ -62,6 +60,7 @@ class PluginManager: }) self.plugin_loader = Loader(self.web_app, CONFIG["plugin_path"], self.loop, CONFIG["live_reload"]) self.plugin_browser = PluginBrowser(CONFIG["plugin_path"], self.web_app, self.plugin_loader.plugins) + self.settings = SettingsManager("loader", path.join(HOMEBREW_PATH, "settings")) self.utilities = Utilities(self) self.updater = Updater(self) @@ -70,7 +69,7 @@ class PluginManager: self.web_app.on_startup.append(chown_plugin_dir) self.loop.create_task(self.loader_reinjector()) self.loop.create_task(self.load_plugins()) - if not remote_debugging_allowed(): + if not self.settings.getSetting("cef_forward", False): self.loop.create_task(stop_systemd_unit(REMOTE_DEBUGGER_UNIT)) self.loop.set_exception_handler(self.exception_handler) self.web_app.add_routes([get("/auth/token", self.get_auth_token)]) diff --git a/backend/settings.py b/backend/settings.py new file mode 100644 index 00000000..03718dab --- /dev/null +++ b/backend/settings.py @@ -0,0 +1,38 @@ +from os import path, mkdir +from json import load, dump + +class SettingsManager: + def __init__(self, name, settings_directory) -> None: + self.path = path.join(settings_directory, name + ".json") + + if not path.exists(settings_directory): + mkdir(settings_directory) + + self.settings = {} + + try: + open(self.path, "x") + except FileExistsError as e: + self.read() + pass + + def read(self): + try: + with open(self.path, "r") as file: + self.settings = load(file) + except Exception as e: + print(e) + pass + + def commit(self): + with open(self.path, "w+") as file: + dump(self.settings, file, indent=4) + + def getSetting(self, key, default): + if key in self.settings: + return self.settings[key] + return default + + def setSetting(self, key, value): + self.settings[key] = value + self.commit()
\ No newline at end of file diff --git a/backend/utilities.py b/backend/utilities.py index 9c0c6388..e06e770d 100644 --- a/backend/utilities.py +++ b/backend/utilities.py @@ -20,7 +20,8 @@ class Utilities: "remove_css_from_tab": self.remove_css_from_tab, "allow_remote_debugging": self.allow_remote_debugging, "disallow_remote_debugging": self.disallow_remote_debugging, - "remote_debugging_allowed": self.remote_debugging_allowed + "set_setting": self.set_setting, + "get_setting": self.get_setting } if context: @@ -138,9 +139,11 @@ class Utilities: "result": e } + async def get_setting(self, key, default): + return self.context.settings.getSetting(key, default) - async def remote_debugging_allowed(self): - return await helpers.is_systemd_unit_active(helpers.REMOTE_DEBUGGER_UNIT) + async def set_setting(self, key, value): + return self.context.settings.setSetting(key, value) async def allow_remote_debugging(self): await helpers.start_systemd_unit(helpers.REMOTE_DEBUGGER_UNIT) |
