From e3a8de2490fea942edad4c0a8971a3958cc01d9b Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 22 Aug 2023 20:59:13 +0300 Subject: [PATCH 1/2] feat: allow reading version from environment Temporary (hopefully) workaround for NixOS. A better fix will require more invasive refactoring. --- backend/helpers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/helpers.py b/backend/helpers.py index a1877fb85..2f80d8f99 100644 --- a/backend/helpers.py +++ b/backend/helpers.py @@ -48,6 +48,11 @@ def mkdir_as_user(path): # Fetches the version of loader def get_loader_version() -> str: + # FIXME: this should really come from package metadata + env_version = os.getenv('DECKY_VERSION') + if env_version: + return env_version + try: with open(os.path.join(os.getcwd(), ".loader.version"), "r", encoding="utf-8") as version_file: return version_file.readline().strip() From 89f37f4f547ff0d78783899df80a046bc864c48e Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 22 Aug 2023 23:15:52 +0300 Subject: [PATCH 2/2] fix: include Decky version in request for index.js This avoids the If-Modified-Since logic in aiohttp and makes sure the script is always reloaded. --- backend/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/main.py b/backend/main.py index b2e3e74a7..ef1dafc4d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -24,8 +24,9 @@ # local modules from browser import PluginBrowser from helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token, - mkdir_as_user, get_system_pythonpaths, get_effective_user_id) - + mkdir_as_user, get_system_pythonpaths, get_effective_user_id, + get_loader_version) + from injector import get_gamepadui_tab, Tab, get_tabs, close_old_tabs from loader import Loader from settings import SettingsManager @@ -162,7 +163,7 @@ async def inject_javascript(self, tab: Tab, first=False, request=None): if first: if await tab.has_global_var("deckyHasLoaded", False): await close_old_tabs() - await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => location.reload(), 100)}else{window.deckyHasLoaded = true;(async()=>{try{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};await import('http://localhost:1337/frontend/index.js')}catch(e){console.error(e)};})();}}catch(e){console.error(e)}", False, False, False) + await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => location.reload(), 100)}else{window.deckyHasLoaded = true;(async()=>{try{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};await import('http://localhost:1337/frontend/index.js?v=%s')}catch(e){console.error(e)};})();}}catch(e){console.error(e)}" % (get_loader_version(), ), False, False, False) except: logger.info("Failed to inject JavaScript into tab\n" + format_exc()) pass