diff options
| author | Wayne Heaney <42350981+wheaney@users.noreply.github.com> | 2024-03-13 15:59:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-13 23:59:22 +0100 |
| commit | 34fb7bb5383084dde5e60bba2c27c273d94cc664 (patch) | |
| tree | d0e858f6057e6e90a4de854469fc5f0f3b63b57e | |
| parent | 4a7e9a5f3dc8fa1ab4789ac8396b030d72e1facc (diff) | |
| download | decky-loader-34fb7bb5383084dde5e60bba2c27c273d94cc664.tar.gz decky-loader-34fb7bb5383084dde5e60bba2c27c273d94cc664.zip | |
Add Plugin.uninstall callback support (#555)
* Add Plugin.uninstall callback support
https://github.com/SteamDeckHomebrew/decky-loader/issues/536
* Remove empty deck.sh
| -rw-r--r-- | backend/src/browser.py | 2 | ||||
| -rw-r--r-- | backend/src/plugin.py | 25 |
2 files changed, 22 insertions, 5 deletions
diff --git a/backend/src/browser.py b/backend/src/browser.py index 025e8fe7..63652898 100644 --- a/backend/src/browser.py +++ b/backend/src/browser.py @@ -138,7 +138,7 @@ class PluginBrowser: # logger.debug("current plugins: %s", snapshot_string) if name in self.plugins: logger.debug("Plugin %s was found", name) - self.plugins[name].stop() + self.plugins[name].stop(uninstall=True) logger.debug("Plugin %s was stopped", name) del self.plugins[name] logger.debug("Plugin %s was removed from the dictionary", name) diff --git a/backend/src/plugin.py b/backend/src/plugin.py index b57bc5f7..f232451b 100644 --- a/backend/src/plugin.py +++ b/backend/src/plugin.py @@ -78,7 +78,7 @@ class PluginWrapper: # append the plugin's `py_modules` to the recognized python paths syspath.append(path.join(environ["DECKY_PLUGIN_DIR"], "py_modules")) - + #TODO: FIX IN A LESS CURSED WAY keys = [key.replace("src.", "") for key in sysmodules if key.startswith("src.")] for key in keys: @@ -113,12 +113,29 @@ class PluginWrapper: self.log.error("Failed to unload " + self.name + "!\n" + format_exc()) exit(0) + async def _uninstall(self): + try: + self.log.info("Attempting to uninstall with plugin " + self.name + "'s \"_uninstall\" function.\n") + if hasattr(self.Plugin, "_uninstall"): + await self.Plugin._uninstall(self.Plugin) + self.log.info("Uninstalled " + self.name + "\n") + else: + self.log.info("Could not find \"_uninstall\" in " + self.name + "'s main.py" + "\n") + except: + self.log.error("Failed to uninstall " + self.name + "!\n" + format_exc()) + exit(0) + async def _on_new_message(self, message : str) -> str|None: data = loads(message) if "stop" in data: self.log.info("Calling Loader unload function.") await self._unload() + + if data.get('uninstall'): + self.log.info("Calling Loader uninstall function.") + await self._uninstall() + get_event_loop().stop() while get_event_loop().is_running(): await sleep(0) @@ -141,12 +158,12 @@ class PluginWrapper: multiprocessing.Process(target=self._init).start() return self - def stop(self): + def stop(self, uninstall: bool = False): if self.passive: return async def _(self: PluginWrapper): - await self.socket.write_single_line(dumps({ "stop": True }, ensure_ascii=False)) + await self.socket.write_single_line(dumps({ "stop": True, "uninstall": uninstall }, ensure_ascii=False)) await self.socket.close_socket_connection() get_event_loop().create_task(_(self)) @@ -155,7 +172,7 @@ class PluginWrapper: if self.passive: raise RuntimeError("This plugin is passive (aka does not implement main.py)") async with self.method_call_lock: - # reader, writer = + # reader, writer = await self.socket.get_socket_connection() await self.socket.write_single_line(dumps({ "method": method_name, "args": kwargs }, ensure_ascii=False)) |
