diff --git a/backend/decky_loader/browser.py b/backend/decky_loader/browser.py index 66e711179..28a591a02 100644 --- a/backend/decky_loader/browser.py +++ b/backend/decky_loader/browser.py @@ -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(uninstall=True) + await 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) @@ -249,7 +249,7 @@ async def _install(self, artifact: str, name: str, version: str, hash: str): if ret: logger.info(f"Installed {name} (Version: {version})") if name in self.loader.plugins: - self.loader.plugins[name].stop() + await self.loader.plugins[name].stop() self.loader.plugins.pop(name, None) await sleep(1) if not isInstalled: @@ -257,7 +257,7 @@ async def _install(self, artifact: str, name: str, version: str, hash: str): current_plugin_order.append(name) self.settings.setSetting("pluginOrder", current_plugin_order) logger.debug("Plugin %s was added to the pluginOrder setting", name) - self.loader.import_plugin(path.join(plugin_dir, "main.py"), plugin_folder) + await self.loader.import_plugin(path.join(plugin_dir, "main.py"), plugin_folder) else: logger.fatal(f"Failed Downloading Remote Binaries") else: diff --git a/backend/decky_loader/loader.py b/backend/decky_loader/loader.py index 90c54211b..7881e4b1a 100644 --- a/backend/decky_loader/loader.py +++ b/backend/decky_loader/loader.py @@ -140,7 +140,7 @@ async def handle_frontend_bundle(self, request: web.Request): with open(path.join(self.plugin_path, plugin.plugin_directory, "dist/index.js"), "r", encoding="utf-8") as bundle: return web.Response(text=bundle.read(), content_type="application/javascript") - def import_plugin(self, file: str, plugin_directory: str, refresh: bool | None = False, batch: bool | None = False): + async def import_plugin(self, file: str, plugin_directory: str, refresh: bool | None = False, batch: bool | None = False): try: async def plugin_emitted_event(event: str, args: Any): self.logger.debug(f"PLUGIN EMITTED EVENT: {event} with args {args}") @@ -152,7 +152,7 @@ async def plugin_emitted_event(event: str, args: Any): self.logger.info(f"Plugin {plugin.name} is already loaded and has requested to not be re-loaded") return else: - self.plugins[plugin.name].stop() + await self.plugins[plugin.name].stop() self.plugins.pop(plugin.name, None) if plugin.passive: self.logger.info(f"Plugin {plugin.name} is passive") @@ -168,18 +168,18 @@ async def plugin_emitted_event(event: str, args: Any): async def dispatch_plugin(self, name: str, version: str | None, load_type: int = PluginLoadType.ESMODULE_V1.value): await self.ws.emit("loader/import_plugin", name, version, load_type) - def import_plugins(self): + async def import_plugins(self): self.logger.info(f"import plugins from {self.plugin_path}") directories = [i for i in listdir(self.plugin_path) if path.isdir(path.join(self.plugin_path, i)) and path.isfile(path.join(self.plugin_path, i, "plugin.json"))] for directory in directories: self.logger.info(f"found plugin: {directory}") - self.import_plugin(path.join(self.plugin_path, directory, "main.py"), directory, False, True) + await self.import_plugin(path.join(self.plugin_path, directory, "main.py"), directory, False, True) async def handle_reloads(self): while True: args = await self.reload_queue.get() - self.import_plugin(*args) # pyright: ignore [reportArgumentType] + await self.import_plugin(*args) # pyright: ignore [reportArgumentType] async def handle_plugin_method_call_legacy(self, plugin_name: str, method_name: str, kwargs: Dict[Any, Any]): res: Dict[Any, Any] = {} diff --git a/backend/decky_loader/main.py b/backend/decky_loader/main.py index d8479f1d9..a1e683dac 100644 --- a/backend/decky_loader/main.py +++ b/backend/decky_loader/main.py @@ -101,7 +101,7 @@ async def get_auth_token(self, request: Request): async def load_plugins(self): # await self.wait_for_server() logger.debug("Loading plugins") - self.plugin_loader.import_plugins() + await self.plugin_loader.import_plugins() if self.settings.getSetting("pluginOrder", None) == None: self.settings.setSetting("pluginOrder", list(self.plugin_loader.plugins.keys())) logger.debug("Did not find pluginOrder setting, set it to default") diff --git a/backend/decky_loader/plugin/plugin.py b/backend/decky_loader/plugin/plugin.py index 61b5ca4f6..94e411bc8 100644 --- a/backend/decky_loader/plugin/plugin.py +++ b/backend/decky_loader/plugin/plugin.py @@ -108,11 +108,9 @@ def start(self): self._listener_task = create_task(self._response_listener()) return self - def stop(self, uninstall: bool = False): + async def stop(self, uninstall: bool = False): + if hasattr(self, "_socket"): + await self._socket.write_single_line(dumps({ "stop": True, "uninstall": uninstall }, ensure_ascii=False)) + await self._socket.close_socket_connection() if hasattr(self, "_listener_task"): - self._listener_task.cancel() - async def _(self: PluginWrapper): - if hasattr(self, "_socket"): - await self._socket.write_single_line(dumps({ "stop": True, "uninstall": uninstall }, ensure_ascii=False)) - await self._socket.close_socket_connection() - create_task(_(self)) \ No newline at end of file + self._listener_task.cancel() \ No newline at end of file diff --git a/frontend/src/components/modals/PluginUninstallModal.tsx b/frontend/src/components/modals/PluginUninstallModal.tsx index a1b745e9b..f943ad9c9 100644 --- a/frontend/src/components/modals/PluginUninstallModal.tsx +++ b/frontend/src/components/modals/PluginUninstallModal.tsx @@ -21,6 +21,7 @@ const PluginUninstallModal: FC = ({ name, title, butt // we invalidate here so if you re-install it, you won't have an out-of-date hidden filter await DeckyPluginLoader.frozenPluginsService.invalidate(); await DeckyPluginLoader.hiddenPluginsService.invalidate(); + closeModal?.(); }} strTitle={title} strOKButtonText={buttonText}