Skip to content

Commit

Permalink
backport webhelper restart logic from websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
AAGaming00 committed May 30, 2024
1 parent 5bfc532 commit 5053a52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/src/localplatformlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ async def service_start(service_name : str) -> bool:
res = run(cmd, stdout=PIPE, stderr=STDOUT)
return res.returncode == 0

async def restart_webhelper() -> bool:
logger.info("Restarting steamwebhelper")
# TODO move to pkill
res = run(["killall", "-s", "SIGTERM", "steamwebhelper"], stdout=DEVNULL, stderr=DEVNULL)
return res.returncode == 0

def get_privileged_path() -> str:
path = os.getenv("PRIVILEGED_PATH")

Expand Down
10 changes: 5 additions & 5 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys
from typing import Dict
from .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_privileged_path)
get_privileged_path, restart_webhelper)
if hasattr(sys, '_MEIPASS'):
chmod(sys._MEIPASS, 755) # type: ignore
# Full imports
Expand Down Expand Up @@ -158,9 +158,9 @@ async def loader_reinjector(self):
async def inject_javascript(self, tab: Tab, first: bool=False, request: Request|None=None):
logger.info("Loading Decky frontend!")
try:
if first:
if await tab.has_global_var("deckyHasLoaded", False):
await close_old_tabs()
# if first:
if ON_LINUX and await tab.has_global_var("deckyHasLoaded", False):
await restart_webhelper()
await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => SteamClient.Browser.RestartJSContext(), 100)}else{window.deckyHasLoaded = true;(async()=>{try{while(!window.webpackChunksteamui){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)
except:
logger.info("Failed to inject JavaScript into tab\n" + format_exc())
Expand Down

0 comments on commit 5053a52

Please sign in to comment.