restart ui by killing webhelper

this cleanly reloads the ui, prevents memory leaks, and won't break the toasts
This commit is contained in:
AAGaming
2024-02-14 17:49:52 -05:00
parent 091428f683
commit ee6122b97d
2 changed files with 19 additions and 17 deletions
@@ -156,6 +156,10 @@ async def service_start(service_name : str) -> bool:
res = run(cmd, stdout=PIPE, stderr=STDOUT) res = run(cmd, stdout=PIPE, stderr=STDOUT)
return res.returncode == 0 return res.returncode == 0
async def restart_webhelper() -> bool:
res = run(["killall", "-s", "SIGTERM", "steamwebhelper"], stdout=DEVNULL, stderr=DEVNULL)
return res.returncode == 0
def get_privileged_path() -> str: def get_privileged_path() -> str:
path = os.getenv("PRIVILEGED_PATH") path = os.getenv("PRIVILEGED_PATH")
+9 -11
View File
@@ -2,9 +2,9 @@
import sys import sys
from typing import Dict from typing import Dict
from .localplatform.localplatform import (chmod, chown, service_stop, service_start, from .localplatform.localplatform import (chmod, chown, service_stop, service_start,
ON_WINDOWS, get_log_level, get_live_reload, ON_WINDOWS, ON_LINUX, get_log_level, get_live_reload,
get_server_port, get_server_host, get_chown_plugin_path, get_server_port, get_server_host, get_chown_plugin_path,
get_privileged_path) get_privileged_path, restart_webhelper)
if hasattr(sys, '_MEIPASS'): if hasattr(sys, '_MEIPASS'):
chmod(sys._MEIPASS, 755) # type: ignore chmod(sys._MEIPASS, 755) # type: ignore
# Full imports # Full imports
@@ -25,7 +25,7 @@ from .browser import PluginBrowser
from .helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token, get_loader_version, from .helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token, get_loader_version,
mkdir_as_user, get_system_pythonpaths, get_effective_user_id) mkdir_as_user, get_system_pythonpaths, get_effective_user_id)
from .injector import get_gamepadui_tab, Tab, close_old_tabs from .injector import get_gamepadui_tab, Tab
from .loader import Loader from .loader import Loader
from .settings import SettingsManager from .settings import SettingsManager
from .updater import Updater from .updater import Updater
@@ -131,13 +131,10 @@ class PluginManager:
await self.inject_javascript(tab, True) await self.inject_javascript(tab, True)
try: try:
async for msg in tab.listen_for_message(): async for msg in tab.listen_for_message():
# this gets spammed a lot
if msg.get("method", None) != "Page.navigatedWithinDocument":
logger.debug("Page event: " + str(msg.get("method", None)))
if msg.get("method", None) == "Page.domContentEventFired": if msg.get("method", None) == "Page.domContentEventFired":
if not await tab.has_global_var("deckyHasLoaded", False): if not await tab.has_global_var("deckyHasLoaded", False):
await self.inject_javascript(tab) await self.inject_javascript(tab)
if msg.get("method", None) == "Inspector.detached": elif msg.get("method", None) == "Inspector.detached":
logger.info("CEF has requested that we detach.") logger.info("CEF has requested that we detach.")
await tab.close_websocket() await tab.close_websocket()
break break
@@ -158,10 +155,11 @@ class PluginManager:
async def inject_javascript(self, tab: Tab, first: bool=False, request: Request|None=None): async def inject_javascript(self, tab: Tab, first: bool=False, request: Request|None=None):
logger.info("Loading Decky frontend!") logger.info("Loading Decky frontend!")
try: try:
if first: # if first:
if await tab.has_global_var("deckyHasLoaded", False): if ON_LINUX and await tab.has_global_var("deckyHasLoaded", False):
await close_old_tabs() await restart_webhelper()
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) return # We'll catch the next tab in the main loop
await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => SteamClient.Browser.RestartJSContext(), 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: except:
logger.info("Failed to inject JavaScript into tab\n" + format_exc()) logger.info("Failed to inject JavaScript into tab\n" + format_exc())
pass pass