generated from SteamDeckHomebrew/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
css_server.py
33 lines (26 loc) · 1.07 KB
/
css_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio, aiohttp.web, json
from css_utils import Log, create_cef_flag
PLUGIN_CLASS = None
async def handle(request : aiohttp.web.BaseRequest):
data = await request.json()
request_result = {"res": None, "success": True}
# This is very cool decky code
try:
request_result["res"] = await getattr(PLUGIN_CLASS, data["method"])(PLUGIN_CLASS, **data["args"])
except Exception as e:
request_result["res"] = str(e)
request_result["success"] = False
finally:
return aiohttp.web.Response(text=json.dumps(request_result, ensure_ascii=False), content_type='application/json')
def start_server(plugin):
global PLUGIN_CLASS
PLUGIN_CLASS = plugin
loop = asyncio.get_running_loop()
try:
create_cef_flag()
except Exception as e:
Log(f"Failed to create steam cef flag. {str(e)}")
app = aiohttp.web.Application(loop=loop)
app.router.add_route('POST', '/req', handle)
loop.create_task(aiohttp.web._run_app(app, host="127.0.0.1", port=35821))
Log("Started CSS_Loader server on port 35821")