diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/src/loader.py | 5 | ||||
| -rw-r--r-- | backend/src/localplatform/localsocket.py | 7 | ||||
| -rw-r--r-- | backend/src/plugin/plugin.py | 4 | ||||
| -rw-r--r-- | backend/src/plugin/sandboxed_plugin.py | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/backend/src/loader.py b/backend/src/loader.py index 162cf498..7567912c 100644 --- a/backend/src/loader.py +++ b/backend/src/loader.py @@ -22,6 +22,10 @@ from .plugin.plugin import PluginWrapper Plugins = dict[str, PluginWrapper] ReloadQueue = Queue[Tuple[str, str, bool | None] | Tuple[str, str]] +#TODO: Remove placeholder method +async def log_plugin_emitted_message(message: Any): + getLogger().debug(f"EMITTED MESSAGE: " + str(message)) + class FileChangeHandler(RegexMatchingEventHandler): def __init__(self, queue: ReloadQueue, plugin_path: str) -> None: super().__init__(regexes=[r'^.*?dist\/index\.js$', r'^.*?main\.py$']) # type: ignore @@ -143,6 +147,7 @@ class Loader: if plugin.passive: self.logger.info(f"Plugin {plugin.name} is passive") self.plugins[plugin.name] = plugin.start() + self.plugins[plugin.name].set_emitted_message_callback(log_plugin_emitted_message) self.logger.info(f"Loaded {plugin.name}") if not batch: self.loop.create_task(self.dispatch_plugin(plugin.name, plugin.version)) diff --git a/backend/src/localplatform/localsocket.py b/backend/src/localplatform/localsocket.py index 2ef039ee..93b1ea18 100644 --- a/backend/src/localplatform/localsocket.py +++ b/backend/src/localplatform/localsocket.py @@ -18,6 +18,7 @@ class UnixSocket: self.socket = None self.reader = None self.writer = None + self.server_writer = None async def setup_server(self): self.socket = await asyncio.start_unix_server(self._listen_for_method_call, path=self.socket_addr, limit=BUFFER_LIMIT) @@ -90,8 +91,14 @@ class UnixSocket: writer.write(message.encode("utf-8")) await writer.drain() + + async def write_single_line_server(self, message: str): + if self.server_writer is None: + return + await self._write_single_line(self.server_writer, message) async def _listen_for_method_call(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter): + self.server_writer = writer while True: def _(task: asyncio.Task[str|None]): diff --git a/backend/src/plugin/plugin.py b/backend/src/plugin/plugin.py index befd1569..6c338106 100644 --- a/backend/src/plugin/plugin.py +++ b/backend/src/plugin/plugin.py @@ -50,8 +50,8 @@ class PluginWrapper: res = loads(line) if res["id"] == "0": create_task(self.emitted_message_callback(res["payload"])) - return - self._method_call_requests.pop(res["id"]).set_result(res) + else: + self._method_call_requests.pop(res["id"]).set_result(res) except: pass diff --git a/backend/src/plugin/sandboxed_plugin.py b/backend/src/plugin/sandboxed_plugin.py index c437f249..c3656980 100644 --- a/backend/src/plugin/sandboxed_plugin.py +++ b/backend/src/plugin/sandboxed_plugin.py @@ -132,7 +132,7 @@ class SandboxedPlugin: return dumps(d, ensure_ascii=False) async def emit_message(self, message: Dict[Any, Any]): - await self._socket.write_single_line(dumps({ + await self._socket.write_single_line_server(dumps({ "id": "0", "payload": message }))
\ No newline at end of file |
