summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortza <marios8543@gmail.com>2022-04-13 22:47:22 +0300
committertza <marios8543@gmail.com>2022-04-13 22:47:22 +0300
commitf685eeb4207e972d98d5e1f92ec0a74cf38a3f85 (patch)
treeda52161af80af7e8f21015488999d42f9d93b151
parent6250fafa6e35277d3f30cb23b11193da18adee6c (diff)
downloaddecky-loader-f685eeb4207e972d98d5e1f92ec0a74cf38a3f85.tar.gz
decky-loader-f685eeb4207e972d98d5e1f92ec0a74cf38a3f85.zip
Added support for passive plugins (that don't implement main.py)
-rw-r--r--plugin_loader/loader.py6
-rw-r--r--plugin_loader/plugin.py10
2 files changed, 14 insertions, 2 deletions
diff --git a/plugin_loader/loader.py b/plugin_loader/loader.py
index 9523d73d..74c99442 100644
--- a/plugin_loader/loader.py
+++ b/plugin_loader/loader.py
@@ -83,6 +83,8 @@ class Loader:
else:
self.plugins[plugin.name].stop(self.loop)
self.plugins.pop(plugin.name, None)
+ if plugin.passive:
+ self.logger.info(f"Plugin {plugin.name} is passive")
self.plugins[plugin.name] = plugin.start(self.loop)
self.logger.info(f"Loaded {plugin.name}")
except Exception as e:
@@ -94,7 +96,7 @@ class Loader:
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, "main.py"))]
+ 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)
@@ -176,4 +178,4 @@ class Loader:
async def refresh_iframe(self):
tab = await get_tab("QuickAccess")
await tab.open_websocket()
- return await tab.evaluate_js("reloadIframe()", False) \ No newline at end of file
+ return await tab.evaluate_js("reloadIframe()", False)
diff --git a/plugin_loader/plugin.py b/plugin_loader/plugin.py
index cd737c72..04feeb27 100644
--- a/plugin_loader/plugin.py
+++ b/plugin_loader/plugin.py
@@ -22,7 +22,11 @@ class PluginWrapper:
self.tile_view_html = json["tile_view_html"] if "tile_view_html" in json else ""
self.flags = json["flags"]
+ self.passive = not path.isfile(self.file)
+
def _init(self):
+ if self.passive:
+ return
setuid(0 if "root" in self.flags else 1000)
spec = spec_from_file_location("_", self.file)
module = module_from_spec(spec)
@@ -62,6 +66,8 @@ class PluginWrapper:
await sleep(0)
def start(self, loop):
+ if self.passive:
+ return self
executor = ProcessPoolExecutor()
loop.run_in_executor(
executor,
@@ -70,6 +76,8 @@ class PluginWrapper:
return self
def stop(self, loop):
+ if self.passive:
+ return
async def _(self):
await self._open_socket_if_not_exists()
self.writer.write((dumps({"stop": True})+"\n").encode("utf-8"))
@@ -77,6 +85,8 @@ class PluginWrapper:
loop.create_task(_(self))
async def execute_method(self, method_name, kwargs):
+ if self.passive:
+ raise RuntimeError("This plugin is passive (aka does not implement main.py)")
async with self.method_call_lock:
await self._open_socket_if_not_exists()
self.writer.write(