summaryrefslogtreecommitdiff
path: root/backend/decky_loader/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'backend/decky_loader/plugin')
-rw-r--r--backend/decky_loader/plugin/plugin.py19
-rw-r--r--backend/decky_loader/plugin/sandboxed_plugin.py29
2 files changed, 31 insertions, 17 deletions
diff --git a/backend/decky_loader/plugin/plugin.py b/backend/decky_loader/plugin/plugin.py
index 8648a5d6..bed92f34 100644
--- a/backend/decky_loader/plugin/plugin.py
+++ b/backend/decky_loader/plugin/plugin.py
@@ -81,6 +81,13 @@ class PluginWrapper:
def __str__(self) -> str:
return self.name
+ def get_display_name(self) -> str:
+ """Returns plugin name with version if available, formatted for logging."""
+ if self.version:
+ return f"{self.name} (v{self.version})"
+
+ return self.name
+
async def _response_listener(self):
while self._socket.active:
try:
@@ -92,7 +99,7 @@ class PluginWrapper:
elif res["type"] == SocketMessageType.RESPONSE.value:
self._method_call_requests.pop(res["id"]).set_result(res)
except CancelledError:
- self.log.info(f"Stopping response listener for {self.name}")
+ self.log.info(f"Stopping response listener for {self.get_display_name()}")
await self._socket.close_socket_connection()
# Cancel the request so that WSRouter can perform cleanup
@@ -107,7 +114,7 @@ class PluginWrapper:
async def execute_legacy_method(self, method_name: str, kwargs: Dict[Any, Any]):
if not self.legacy_method_warning:
self.legacy_method_warning = True
- self.log.warning(f"Plugin {self.name} is using legacy method calls. This will be removed in a future release.")
+ self.log.warning(f"Plugin {self.get_display_name()} is using legacy method calls. This will be removed in a future release.")
if self.passive:
raise RuntimeError("This plugin is passive (aka does not implement main.py)")
@@ -142,7 +149,7 @@ class PluginWrapper:
start_time = time()
if self.passive:
return
- self.log.info(f"Shutting down {self.name}")
+ self.log.info(f"Shutting down {self.get_display_name()}")
pending: set[Task[None]] | None = None;
@@ -162,16 +169,16 @@ class PluginWrapper:
for pending_task in pending:
pending_task.cancel()
- self.log.info(f"Plugin {self.name} has been stopped in {time() - start_time:.1f}s")
+ self.log.info(f"Plugin {self.get_display_name()} has been stopped in {time() - start_time:.1f}s")
except Exception as e:
- self.log.error(f"Error during shutdown for plugin {self.name}: {str(e)}\n{format_exc()}")
+ self.log.error(f"Error during shutdown for plugin {self.get_display_name()}: {str(e)}\n{format_exc()}")
async def kill_if_still_running(self):
start_time = time()
while self.proc and self.proc.is_alive():
elapsed_time = time() - start_time
if elapsed_time >= 5:
- self.log.warning(f"Plugin {self.name} still alive 5 seconds after stop request! Sending SIGKILL!")
+ self.log.warning(f"Plugin {self.get_display_name()} still alive 5 seconds after stop request! Sending SIGKILL!")
self.terminate(True)
await sleep(0.1)
diff --git a/backend/decky_loader/plugin/sandboxed_plugin.py b/backend/decky_loader/plugin/sandboxed_plugin.py
index 20da747e..675eb464 100644
--- a/backend/decky_loader/plugin/sandboxed_plugin.py
+++ b/backend/decky_loader/plugin/sandboxed_plugin.py
@@ -45,6 +45,13 @@ class SandboxedPlugin:
self.log = getLogger("sandboxed_plugin")
+ def get_display_name(self) -> str:
+ """Returns plugin name with version if available, formatted for logging."""
+ if self.version:
+ return f"{self.name} (v{self.version})"
+
+ return self.name
+
def initialize(self, socket: LocalSocket):
self._socket = socket
@@ -125,51 +132,51 @@ class SandboxedPlugin:
get_event_loop().create_task(self.Plugin._main(self.Plugin))
get_event_loop().create_task(socket.setup_server(self.on_new_message))
except:
- self.log.error("Failed to start " + self.name + "!\n" + format_exc())
+ self.log.error(f"Failed to start {self.get_display_name()}!\n{format_exc()}")
sys.exit(0)
try:
get_event_loop().run_forever()
except SystemExit:
pass
except:
- self.log.error("Loop exited for " + self.name + "!\n" + format_exc())
+ self.log.error(f"Loop exited for {self.get_display_name()}!\n{format_exc()}")
finally:
get_event_loop().close()
async def _unload(self):
try:
- self.log.info("Attempting to unload with plugin " + self.name + "'s \"_unload\" function.\n")
+ self.log.info(f"Attempting to unload with plugin {self.get_display_name()}'s \"_unload\" function.\n")
if hasattr(self.Plugin, "_unload"):
if self.api_version > 0:
await self.Plugin._unload()
else:
await self.Plugin._unload(self.Plugin)
- self.log.info("Unloaded " + self.name + "\n")
+ self.log.info(f"Unloaded {self.get_display_name()}\n")
else:
- self.log.info("Could not find \"_unload\" in " + self.name + "'s main.py" + "\n")
+ self.log.info(f"Could not find \"_unload\" in {self.get_display_name()}'s main.py\n")
except:
- self.log.error("Failed to unload " + self.name + "!\n" + format_exc())
+ self.log.error(f"Failed to unload {self.get_display_name()}!\n{format_exc()}")
pass
async def _uninstall(self):
try:
- self.log.info("Attempting to uninstall with plugin " + self.name + "'s \"_uninstall\" function.\n")
+ self.log.info(f"Attempting to uninstall with plugin {self.get_display_name()}'s \"_uninstall\" function.\n")
if hasattr(self.Plugin, "_uninstall"):
if self.api_version > 0:
await self.Plugin._uninstall()
else:
await self.Plugin._uninstall(self.Plugin)
- self.log.info("Uninstalled " + self.name + "\n")
+ self.log.info(f"Uninstalled {self.get_display_name()}\n")
else:
- self.log.info("Could not find \"_uninstall\" in " + self.name + "'s main.py" + "\n")
+ self.log.info(f"Could not find \"_uninstall\" in {self.get_display_name()}'s main.py\n")
except:
- self.log.error("Failed to uninstall " + self.name + "!\n" + format_exc())
+ self.log.error(f"Failed to uninstall {self.get_display_name()}!\n{format_exc()}")
pass
async def shutdown(self):
if not self.shutdown_running:
self.shutdown_running = True
- self.log.info(f"Calling Loader unload function for {self.name}.")
+ self.log.info(f"Calling Loader unload function for {self.get_display_name()}.")
await self._unload()
if self.uninstalling: