diff options
| author | tza <marios8543@gmail.com> | 2022-04-07 22:38:26 +0300 |
|---|---|---|
| committer | tza <marios8543@gmail.com> | 2022-04-07 22:38:26 +0300 |
| commit | c65427e693daf3ee96cfd707e74efcb8d9d985f2 (patch) | |
| tree | a61d643ea63517dbac2c2035c88802e631843b85 /plugin_loader/injector.py | |
| parent | 0f14f2707bf0c50d6fbbfda3da66394953ae4128 (diff) | |
| download | decky-loader-c65427e693daf3ee96cfd707e74efcb8d9d985f2.tar.gz decky-loader-c65427e693daf3ee96cfd707e74efcb8d9d985f2.zip | |
initial browser/installer commit, injector get_tab and stateful utils
- Integrated plugin downloader/installer. It accepts POST requests at /browser/install_plugin, containing an artifact (basically an author/repo string like you'd find on github), and a release version, then fetches the zip file from the repo releases and unzips it inside the plugin dir, after asking for user confirmation (pop-up message in the plugin menu).
- Injector get_tab method. Basically get_tabs with the usual search for a specific tab. Decided to implement this because it was needed again and again, and we kept pasting the same list search one-liner.
- Utilities now have access to the main PluginManager class
Diffstat (limited to 'plugin_loader/injector.py')
| -rw-r--r-- | plugin_loader/injector.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/plugin_loader/injector.py b/plugin_loader/injector.py index 6ca9e8e9..85da1e6a 100644 --- a/plugin_loader/injector.py +++ b/plugin_loader/injector.py @@ -79,21 +79,25 @@ async def get_tabs(): else: raise Exception("/json did not return 200. {}".format(await res.text())) -async def inject_to_tab(tab_name, js): +async def get_tab(tab_name): tabs = await get_tabs() 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)) + raise ValueError("Tab {} not found".format(tab_name)) + return tab + +async def inject_to_tab(tab_name, js): + tab = await get_tab(tab_name) 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: + try: + tab = await get_tab(tab_name) + except ValueError: 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 False return res["result"]["result"]["value"] |
