mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 16:57:50 +00:00
Added support for passive plugins (that don't implement main.py)
This commit is contained in:
@@ -83,6 +83,8 @@ class Loader:
|
|||||||
else:
|
else:
|
||||||
self.plugins[plugin.name].stop(self.loop)
|
self.plugins[plugin.name].stop(self.loop)
|
||||||
self.plugins.pop(plugin.name, None)
|
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.plugins[plugin.name] = plugin.start(self.loop)
|
||||||
self.logger.info(f"Loaded {plugin.name}")
|
self.logger.info(f"Loaded {plugin.name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -94,7 +96,7 @@ class Loader:
|
|||||||
def import_plugins(self):
|
def import_plugins(self):
|
||||||
self.logger.info(f"import plugins from {self.plugin_path}")
|
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:
|
for directory in directories:
|
||||||
self.logger.info(f"found plugin: {directory}")
|
self.logger.info(f"found plugin: {directory}")
|
||||||
self.import_plugin(path.join(self.plugin_path, directory, "main.py"), directory)
|
self.import_plugin(path.join(self.plugin_path, directory, "main.py"), directory)
|
||||||
@@ -176,4 +178,4 @@ class Loader:
|
|||||||
async def refresh_iframe(self):
|
async def refresh_iframe(self):
|
||||||
tab = await get_tab("QuickAccess")
|
tab = await get_tab("QuickAccess")
|
||||||
await tab.open_websocket()
|
await tab.open_websocket()
|
||||||
return await tab.evaluate_js("reloadIframe()", False)
|
return await tab.evaluate_js("reloadIframe()", False)
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ class PluginWrapper:
|
|||||||
self.tile_view_html = json["tile_view_html"] if "tile_view_html" in json else ""
|
self.tile_view_html = json["tile_view_html"] if "tile_view_html" in json else ""
|
||||||
self.flags = json["flags"]
|
self.flags = json["flags"]
|
||||||
|
|
||||||
|
self.passive = not path.isfile(self.file)
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
|
if self.passive:
|
||||||
|
return
|
||||||
setuid(0 if "root" in self.flags else 1000)
|
setuid(0 if "root" in self.flags else 1000)
|
||||||
spec = spec_from_file_location("_", self.file)
|
spec = spec_from_file_location("_", self.file)
|
||||||
module = module_from_spec(spec)
|
module = module_from_spec(spec)
|
||||||
@@ -62,6 +66,8 @@ class PluginWrapper:
|
|||||||
await sleep(0)
|
await sleep(0)
|
||||||
|
|
||||||
def start(self, loop):
|
def start(self, loop):
|
||||||
|
if self.passive:
|
||||||
|
return self
|
||||||
executor = ProcessPoolExecutor()
|
executor = ProcessPoolExecutor()
|
||||||
loop.run_in_executor(
|
loop.run_in_executor(
|
||||||
executor,
|
executor,
|
||||||
@@ -70,6 +76,8 @@ class PluginWrapper:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def stop(self, loop):
|
def stop(self, loop):
|
||||||
|
if self.passive:
|
||||||
|
return
|
||||||
async def _(self):
|
async def _(self):
|
||||||
await self._open_socket_if_not_exists()
|
await self._open_socket_if_not_exists()
|
||||||
self.writer.write((dumps({"stop": True})+"\n").encode("utf-8"))
|
self.writer.write((dumps({"stop": True})+"\n").encode("utf-8"))
|
||||||
@@ -77,6 +85,8 @@ class PluginWrapper:
|
|||||||
loop.create_task(_(self))
|
loop.create_task(_(self))
|
||||||
|
|
||||||
async def execute_method(self, method_name, kwargs):
|
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:
|
async with self.method_call_lock:
|
||||||
await self._open_socket_if_not_exists()
|
await self._open_socket_if_not_exists()
|
||||||
self.writer.write(
|
self.writer.write(
|
||||||
|
|||||||
Reference in New Issue
Block a user