diff options
| author | marios8543 <marios8543@gmail.com> | 2023-10-18 00:04:14 +0300 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2023-10-31 23:18:23 +0200 |
| commit | 8dc6f19d2b7b245d15d89ee14aba7c10ad9b7215 (patch) | |
| tree | 25da0d5725e1850d243f24c203c1c16a56b608f2 /backend/src | |
| parent | 321242b0d9bf737dff931be8cedd6a1590a3be5a (diff) | |
| download | decky-loader-8dc6f19d2b7b245d15d89ee14aba7c10ad9b7215.tar.gz decky-loader-8dc6f19d2b7b245d15d89ee14aba7c10ad9b7215.zip | |
Run response_listener task
Diffstat (limited to 'backend/src')
| -rw-r--r-- | backend/src/plugin/plugin.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/backend/src/plugin/plugin.py b/backend/src/plugin/plugin.py index b7d0a44a..d5f79d42 100644 --- a/backend/src/plugin/plugin.py +++ b/backend/src/plugin/plugin.py @@ -1,3 +1,4 @@ +from asyncio import Task, create_task from json import dumps, load, loads from logging import getLogger from os import path @@ -31,12 +32,12 @@ class PluginWrapper: self.sandboxed_plugin = SandboxedPlugin(self.name, self.passive, self.flags, self.file, self.plugin_directory, self.plugin_path, self.version, self.author) #TODO: Maybe somehow make LocalSocket not require on_new_message to make this more clear self.socket = LocalSocket(self.sandboxed_plugin.on_new_message) - self.sandboxed_plugin.start(self.socket) + self.listener_task: Task[Any] def __str__(self) -> str: return self.name - async def response_listener(self): + async def _response_listener(self): while True: line = await self.socket.read_single_line() if line != None: @@ -52,4 +53,15 @@ class PluginWrapper: await self.socket.write_single_line(dumps({ "method": method_name, "args": kwargs, "id": request.id }, ensure_ascii=False)) self.method_call_requests[request.id] = request - return await request.wait_for_result()
\ No newline at end of file + return await request.wait_for_result() + + async def start(self): + self.sandboxed_plugin.start(self.socket) + self.listener_task = create_task(self._response_listener()) + + async def stop(self): + self.listener_task.cancel() + async def _(self: PluginWrapper): + await self.socket.write_single_line(dumps({ "stop": True }, ensure_ascii=False)) + await self.socket.close_socket_connection() + create_task(_(self))
\ No newline at end of file |
