2023-02-19 22:43:09 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# The decky plugin module is located at decky-loader/plugin
|
2024-06-13 23:11:44 +01:00
|
|
|
# For easy intellisense checkout the decky-loader code repo
|
|
|
|
# and add the `decky-loader/plugin/imports` path to `python.analysis.extraPaths` in `.vscode/settings.json`
|
2024-10-24 03:33:31 +01:00
|
|
|
import pathlib
|
|
|
|
import subprocess
|
2024-06-13 23:11:44 +01:00
|
|
|
import asyncio
|
2024-10-24 03:33:31 +01:00
|
|
|
import os
|
2022-08-25 02:06:26 +01:00
|
|
|
|
2024-10-24 03:33:31 +01:00
|
|
|
HOME_DIR = str(pathlib.Path(os.getcwd()).parent.parent.resolve())
|
|
|
|
PARENT_DIR = str(pathlib.Path(__file__).parent.resolve())
|
|
|
|
|
|
|
|
LOG_LOCATION = "/tmp/usdpl-template.py.log"
|
2022-04-22 23:42:11 +01:00
|
|
|
|
2024-10-24 03:33:31 +01:00
|
|
|
# set up logging for Python back-end spawning
|
|
|
|
import logging
|
2024-06-13 23:11:44 +01:00
|
|
|
|
2024-10-24 03:33:31 +01:00
|
|
|
logging.basicConfig(
|
|
|
|
filename = LOG_LOCATION,
|
|
|
|
format = '%(asctime)s %(levelname)s %(message)s',
|
|
|
|
filemode = 'w',
|
|
|
|
force = True)
|
|
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
logging.info(f"usdpl-decky-template main.py https://git.ngni.us/NG-SD-Plugins/usdpl-decky-plugin-template")
|
|
|
|
|
|
|
|
class Plugin:
|
|
|
|
backend_proc = None
|
2022-04-22 23:42:11 +01:00
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
|
|
|
async def _main(self):
|
2024-10-24 03:33:31 +01:00
|
|
|
# startup back-end
|
|
|
|
self.backend_proc = subprocess.Popen(
|
|
|
|
[PARENT_DIR + "/bin/backend"],
|
|
|
|
env = dict(os.environ))
|
|
|
|
while True: # keep running in case Decky checks; very likely unnecessary
|
|
|
|
await asyncio.sleep(1)
|
2023-02-19 22:43:09 +00:00
|
|
|
|
2022-10-23 02:48:59 +01:00
|
|
|
async def _unload(self):
|
2024-10-24 03:33:31 +01:00
|
|
|
# gracefully stop the back-end, but kill if it doesn't exit quickly enough
|
|
|
|
if self.backend_proc is not None:
|
|
|
|
self.backend_proc.terminate()
|
|
|
|
try:
|
|
|
|
self.backend_proc.wait(timeout=5) # 5 seconds timeout
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
self.backend_proc.kill()
|
|
|
|
self.backend_proc = None
|