Skip to content

Commit

Permalink
fix plugin uninstall dialog issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AAGaming00 committed Jun 27, 2024
1 parent 107b9ab commit d71fb79
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions 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(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)
Expand Down Expand Up @@ -249,15 +249,15 @@ 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:
current_plugin_order = self.settings.getSetting("pluginOrder")
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:
Expand Down
10 changes: 5 additions & 5 deletions backend/decky_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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")
Expand All @@ -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] = {}
Expand Down
2 changes: 1 addition & 1 deletion backend/decky_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 5 additions & 7 deletions backend/decky_loader/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
self._listener_task.cancel()
1 change: 1 addition & 0 deletions frontend/src/components/modals/PluginUninstallModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PluginUninstallModal: FC<PluginUninstallModalProps> = ({ 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}
Expand Down

0 comments on commit d71fb79

Please sign in to comment.