Add Plugin.uninstall callback support (#555)

* Add Plugin.uninstall callback support

https://github.com/SteamDeckHomebrew/decky-loader/issues/536

* Remove empty deck.sh
This commit is contained in:
Wayne Heaney
2024-03-13 15:59:22 -07:00
committed by AAGaming
parent 6b06bae250
commit a1a29616e5
3 changed files with 23 additions and 6 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ class PluginBrowser:
# logger.debug("current plugins: %s", snapshot_string) # logger.debug("current plugins: %s", snapshot_string)
if name in self.plugins: if name in self.plugins:
logger.debug("Plugin %s was found", name) logger.debug("Plugin %s was found", name)
self.plugins[name].stop() self.plugins[name].stop(uninstall=True)
logger.debug("Plugin %s was stopped", name) logger.debug("Plugin %s was stopped", name)
del self.plugins[name] del self.plugins[name]
logger.debug("Plugin %s was removed from the dictionary", name) logger.debug("Plugin %s was removed from the dictionary", name)
+2 -2
View File
@@ -97,9 +97,9 @@ class PluginWrapper:
self._listener_task = create_task(self._response_listener()) self._listener_task = create_task(self._response_listener())
return self return self
def stop(self): def stop(self, uninstall: bool = False):
self._listener_task.cancel() self._listener_task.cancel()
async def _(self: PluginWrapper): 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() await self._socket.close_socket_connection()
create_task(_(self)) create_task(_(self))
@@ -138,12 +138,29 @@ class SandboxedPlugin:
self.log.error("Failed to unload " + self.name + "!\n" + format_exc()) self.log.error("Failed to unload " + self.name + "!\n" + format_exc())
exit(0) 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) data = loads(message)
if "stop" in data: if "stop" in data:
self.log.info("Calling Loader unload function.") self.log.info("Calling Loader unload function.")
await self._unload() await self._unload()
if data.get('uninstall'):
self.log.info("Calling Loader uninstall function.")
await self._uninstall()
get_event_loop().stop() get_event_loop().stop()
while get_event_loop().is_running(): while get_event_loop().is_running():
await sleep(0) await sleep(0)