diff options
| author | marios8543 <marios8543@gmail.com> | 2023-11-14 22:50:16 +0200 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2023-11-14 22:50:16 +0200 |
| commit | 2a343037d733e4d63c8cc6cd4b642260bc2d25b9 (patch) | |
| tree | 038c676e85088569bb2b662e3f85d8feac4ed214 /backend/decky_loader/plugin/binary_plugin.py | |
| parent | 5a633fdd8284dd1a2b6f3c95806f033ef4a4becf (diff) | |
| download | decky-loader-marios8543/custom-backends.tar.gz decky-loader-marios8543/custom-backends.zip | |
Infrastructure for custom backend supportmarios8543/custom-backends
Diffstat (limited to 'backend/decky_loader/plugin/binary_plugin.py')
| -rw-r--r-- | backend/decky_loader/plugin/binary_plugin.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/backend/decky_loader/plugin/binary_plugin.py b/backend/decky_loader/plugin/binary_plugin.py new file mode 100644 index 00000000..d1b8cea9 --- /dev/null +++ b/backend/decky_loader/plugin/binary_plugin.py @@ -0,0 +1,54 @@ +from asyncio import StreamReader, create_task, sleep, create_subprocess_exec +from asyncio.subprocess import Process +from subprocess import PIPE + +from .sandboxed_plugin import SandboxedPlugin +from ..localplatform.localsocket import LocalSocket +from ..customtypes import UserType + +from typing import Dict, List + +class BinaryPlugin(SandboxedPlugin): + def __init__(self, + socket: LocalSocket, + name: str, + flags: List[str], + file: str, + plugin_directory: str, + plugin_path: str, + version: str | None, + author: str, + env: Dict[str, str]) -> None: + super().__init__(socket, name, flags, file, plugin_directory, plugin_path, version, author, env) + self.process: Process + + def start(self): + create_task(self._start()) + + async def stop(self): + self.process.terminate() + while not self.process.returncode: + await sleep(0) + + async def _start(self): + self.env["DECKY_SOCKET"] = self.socket.socket_addr + user_type = UserType.ROOT.value if "root" in self.flags else UserType.HOST_USER.value + self.process = await create_subprocess_exec(self.file, + env=self.env, + user=user_type, + group=user_type, + stdout=PIPE, + stderr=PIPE) + assert self.process.stderr and self.process.stdout + create_task(self._stream_watcher(self.process.stdout, False)) + create_task(self._stream_watcher(self.process.stderr, True)) + + async def _stream_watcher(self, stream: StreamReader, is_err: bool): + async for line in stream: + line = line.decode("utf-8") + if not line.strip(): + continue + if is_err: + self.log.error(line) + else: + self.log.info(line)
\ No newline at end of file |
