diff options
| author | WerWolv <werwolv98@gmail.com> | 2022-04-07 09:58:26 +0200 |
|---|---|---|
| committer | WerWolv <werwolv98@gmail.com> | 2022-04-07 09:58:26 +0200 |
| commit | 3dec82672a76eec0c4630afa7c2125780be57d0a (patch) | |
| tree | eef712e2414eddced88a6311acfb44b3818885c0 /plugin_loader/injector.py | |
| parent | a3619d1d3aa3644a30c56056fd27890d06cc48de (diff) | |
| download | decky-loader-3dec82672a76eec0c4630afa7c2125780be57d0a.tar.gz decky-loader-3dec82672a76eec0c4630afa7c2125780be57d0a.zip | |
Reinject loader if steam got restarted
Diffstat (limited to 'plugin_loader/injector.py')
| -rw-r--r-- | plugin_loader/injector.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/plugin_loader/injector.py b/plugin_loader/injector.py index e130d830..6ca9e8e9 100644 --- a/plugin_loader/injector.py +++ b/plugin_loader/injector.py @@ -1,11 +1,13 @@ #Injector code from https://github.com/SteamDeckHomebrew/steamdeck-ui-inject. More info on how it works there. from aiohttp import ClientSession -from logging import debug +from logging import debug, getLogger from asyncio import sleep BASE_ADDRESS = "http://localhost:8080" +logger = getLogger("Injector") + class Tab: def __init__(self, res) -> None: self.title = res["title"] @@ -68,7 +70,7 @@ async def get_tabs(): res = await web.get("{}/json".format(BASE_ADDRESS)) break except: - print("Steam isn't available yet. Wait for a moment...") + logger.info("Steam isn't available yet. Wait for a moment...") await sleep(5) if res.status == 200: @@ -82,4 +84,16 @@ async def inject_to_tab(tab_name, js): tab = next((i for i in tabs if i.title == tab_name), None) if not tab: raise ValueError("Tab {} not found in running tabs".format(tab_name)) - debug(await tab.evaluate_js(js)) + logger.debug(f"Injected JavaScript Result: {await tab.evaluate_js(js)}") + +async def tab_has_element(tab_name, element_name): + tabs = await get_tabs() + tab = next((i for i in tabs if i.title == tab_name), None) + if not tab: + return False + res = await tab.evaluate_js(f"document.getElementById('{element_name}') != null") + + if not "result" in res or not "result" in res["result"] or not "value" in res["result"]["result"]: + return False; + + return res["result"]["result"]["value"] |
