Skip to content

Commit

Permalink
Add Plugin.uninstall callback support (#555)
Browse files Browse the repository at this point in the history
* Add Plugin.uninstall callback support

#536

* Remove empty deck.sh
  • Loading branch information
wheaney authored and AAGaming00 committed Apr 22, 2024
1 parent 6b06bae commit a1a2961
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/decky_loader/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def uninstall_plugin(self, name: str):
# 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)
Expand Down
4 changes: 2 additions & 2 deletions backend/decky_loader/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def start(self):
self._listener_task = create_task(self._response_listener())
return self

def stop(self):
def stop(self, uninstall: bool = False):
self._listener_task.cancel()
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()
create_task(_(self))
23 changes: 20 additions & 3 deletions backend/decky_loader/plugin/sandboxed_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def initialize(self, socket: LocalSocket):

# 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 for key in sysmodules if key.startswith("decky_loader.")]
for key in keys:
Expand Down Expand Up @@ -138,12 +138,29 @@ async def _unload(self):
self.log.error("Failed to unload " + self.name + "!\n" + format_exc())
exit(0)

async def on_new_message(self, message : str) -> str | None:
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)
Expand All @@ -166,4 +183,4 @@ async def on_new_message(self, message : str) -> str | None:
d["res"] = str(e)
d["success"] = False
finally:
return dumps(d, ensure_ascii=False)
return dumps(d, ensure_ascii=False)

0 comments on commit a1a2961

Please sign in to comment.