summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorAAGaming <aa@mail.catvibers.me>2022-08-26 01:18:28 -0400
committerAAGaming <aa@mail.catvibers.me>2022-08-26 01:18:28 -0400
commitd4d1c2bbabfcec3c62767e614c9d67f516938af2 (patch)
treec30a7643507ade7200eff36e9c16d0512bb1edce /backend
parenteffc4ab0f56119041ac6efecdbf0a782714ec783 (diff)
downloaddecky-loader-d4d1c2bbabfcec3c62767e614c9d67f516938af2.tar.gz
decky-loader-d4d1c2bbabfcec3c62767e614c9d67f516938af2.zip
basic patch notes viewer, lazy-load settings and store, build frontend as esmodule, add lazy-loaded react-markdown, backend changes to accomodate ESModule frontend
Diffstat (limited to 'backend')
-rw-r--r--backend/helpers.py3
-rw-r--r--backend/loader.py14
-rw-r--r--backend/main.py2
-rw-r--r--backend/settings.py4
-rw-r--r--backend/updater.py5
5 files changed, 18 insertions, 10 deletions
diff --git a/backend/helpers.py b/backend/helpers.py
index b3c8a51e..0991f446 100644
--- a/backend/helpers.py
+++ b/backend/helpers.py
@@ -18,6 +18,7 @@ user = None
group = None
assets_regex = re.compile("^/plugins/.*/assets/.*")
+frontend_regex = re.compile("^/frontend/.*")
def get_ssl_context():
return ssl_ctx
@@ -27,7 +28,7 @@ def get_csrf_token():
@middleware
async def csrf_middleware(request, handler):
- if str(request.method) == "OPTIONS" or request.headers.get('Authentication') == csrf_token or str(request.rel_url) == "/auth/token" or str(request.rel_url).startswith("/plugins/load_main/") or str(request.rel_url).startswith("/static/") or str(request.rel_url).startswith("/legacy/") or str(request.rel_url).startswith("/steam_resource/") or assets_regex.match(str(request.rel_url)):
+ if str(request.method) == "OPTIONS" or request.headers.get('Authentication') == csrf_token or str(request.rel_url) == "/auth/token" or str(request.rel_url).startswith("/plugins/load_main/") or str(request.rel_url).startswith("/static/") or str(request.rel_url).startswith("/legacy/") or str(request.rel_url).startswith("/steam_resource/") or assets_regex.match(str(request.rel_url)) or frontend_regex.match(str(request.rel_url)):
return await handler(request)
return Response(text='Forbidden', status='403')
diff --git a/backend/loader.py b/backend/loader.py
index 4fe104d1..9c2b33f4 100644
--- a/backend/loader.py
+++ b/backend/loader.py
@@ -1,4 +1,4 @@
-from asyncio import Queue
+from asyncio import Queue, sleep
from json.decoder import JSONDecodeError
from logging import getLogger
from os import listdir, path
@@ -75,10 +75,11 @@ class Loader:
self.loop.create_task(self.handle_reloads())
server_instance.add_routes([
+ web.get("/frontend/{path:.*}", self.handle_frontend_assets),
web.get("/plugins", self.get_plugins),
web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle),
web.post("/plugins/{plugin_name}/methods/{method_name}", self.handle_plugin_method_call),
- web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_frontend_assets),
+ web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_plugin_frontend_assets),
# The following is legacy plugin code.
web.get("/plugins/load_main/{name}", self.load_plugin_main_view),
@@ -86,15 +87,20 @@ class Loader:
web.get("/steam_resource/{path:.+}", self.get_steam_resource)
])
+ async def handle_frontend_assets(self, request):
+ file = path.join(path.dirname(__file__), "static", request.match_info["path"])
+
+ return web.FileResponse(file, headers={"Cache-Control": "no-cache"})
+
async def get_plugins(self, request):
plugins = list(self.plugins.values())
return web.json_response([{"name": str(i) if not i.legacy else "$LEGACY_"+str(i), "version": i.version} for i in plugins])
- def handle_frontend_assets(self, request):
+ def handle_plugin_frontend_assets(self, request):
plugin = self.plugins[request.match_info["plugin_name"]]
file = path.join(self.plugin_path, plugin.plugin_directory, "dist/assets", request.match_info["path"])
- return web.FileResponse(file)
+ return web.FileResponse(file, headers={"Cache-Control": "no-cache"})
def handle_frontend_bundle(self, request):
plugin = self.plugins[request.match_info["plugin_name"]]
diff --git a/backend/main.py b/backend/main.py
index 41ecfc77..dfbf1829 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -112,7 +112,7 @@ class PluginManager:
async def inject_javascript(self, request=None):
try:
- await inject_to_tab("SP", "try{window.deckyHasLoaded = true;(async()=>{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};" + open(path.join(path.dirname(__file__), "./static/plugin-loader.iife.js"), "r").read() + "})();}catch(e){console.error(e)}", True)
+ await inject_to_tab("SP", "try{window.deckyHasLoaded = true;(async()=>{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};await import('http://localhost:1337/frontend/index.js')})();}catch(e){console.error(e)}", True)
except:
logger.info("Failed to inject JavaScript into tab")
pass
diff --git a/backend/settings.py b/backend/settings.py
index 03718dab..59849052 100644
--- a/backend/settings.py
+++ b/backend/settings.py
@@ -29,9 +29,7 @@ class SettingsManager:
dump(self.settings, file, indent=4)
def getSetting(self, key, default):
- if key in self.settings:
- return self.settings[key]
- return default
+ return self.settings.get(key, default)
def setSetting(self, key, value):
self.settings[key] = value
diff --git a/backend/updater.py b/backend/updater.py
index b3e73e75..bd61f8a8 100644
--- a/backend/updater.py
+++ b/backend/updater.py
@@ -26,6 +26,7 @@ class Updater:
"check_for_updates": self.check_for_updates
}
self.remoteVer = None
+ self.allRemoteVers = None
try:
with open(path.join(getcwd(), ".loader.version"), 'r') as version_file:
self.localVer = version_file.readline().replace("\n", "")
@@ -59,15 +60,17 @@ class Updater:
return {
"current": self.localVer,
"remote": self.remoteVer,
+ "all": self.allRemoteVers,
"updatable": self.localVer != None
}
else:
- return {"current": "unknown", "remote": self.remoteVer, "updatable": False}
+ return {"current": "unknown", "remote": self.remoteVer, "all": self.allRemoteVers, "updatable": False}
async def check_for_updates(self):
async with ClientSession() as web:
async with web.request("GET", "https://api.github.com/repos/SteamDeckHomebrew/decky-loader/releases", ssl=helpers.get_ssl_context()) as res:
remoteVersions = await res.json()
+ self.allRemoteVers = remoteVersions
self.remoteVer = next(filter(lambda ver: ver["prerelease"] and ver["tag_name"].startswith("v") and ver["tag_name"].find("-pre"), remoteVersions), None)
logger.info("Updated remote version information")
tab = await get_tab("SP")