diff options
| author | Jonas Dellinger <jonas@dellinger.dev> | 2022-05-26 13:30:14 +0200 |
|---|---|---|
| committer | Jonas Dellinger <jonas@dellinger.dev> | 2022-05-26 13:30:14 +0200 |
| commit | 71dd0ea449469ed38e784b9c73b673eece680446 (patch) | |
| tree | 15914a2b7979296b8c04cac0e75191eb9f955919 /backend/utilities.py | |
| parent | a06efc08bc01a4a014d916ff1e219a0f17d0c480 (diff) | |
| parent | 4b923c1dc70eaa4a3ca58d9e9f3218785b2fe919 (diff) | |
| download | decky-loader-71dd0ea449469ed38e784b9c73b673eece680446.tar.gz decky-loader-71dd0ea449469ed38e784b9c73b673eece680446.zip | |
Cleanup after merge
Diffstat (limited to 'backend/utilities.py')
| -rw-r--r-- | backend/utilities.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/backend/utilities.py b/backend/utilities.py index 39f9ca55..983bb790 100644 --- a/backend/utilities.py +++ b/backend/utilities.py @@ -1,5 +1,6 @@ -from aiohttp import ClientSession +from aiohttp import ClientSession, web from injector import inject_to_tab +from json.decoder import JSONDecodeError import uuid class Utilities: @@ -11,9 +12,32 @@ class Utilities: "confirm_plugin_install": self.confirm_plugin_install, "execute_in_tab": self.execute_in_tab, "inject_css_into_tab": self.inject_css_into_tab, - "remove_css_from_tab": self.remove_css_from_tab + "remove_css_from_tab": self.remove_css_from_tab, + "open_plugin_store": self.open_plugin_store } + if context: + context.web_app.add_routes([ + web.post("/methods/{method_name}", self._handle_server_method_call) + ]) + + async def _handle_server_method_call(self, request): + method_name = request.match_info["method_name"] + try: + method_info = await request.json() + args = method_info["args"] + except JSONDecodeError: + args = {} + res = {} + try: + r = await self.util_methods[method_name](**args) + res["result"] = r + res["success"] = True + except Exception as e: + res["result"] = str(e) + res["success"] = False + return web.json_response(res) + async def confirm_plugin_install(self, request_id): return await self.context.plugin_browser.confirm_plugin_install(request_id) @@ -104,3 +128,16 @@ class Utilities: "success": False, "result": e } + + async def open_plugin_store(self): + await inject_to_tab("SP", """ + (function() { + wpRequire = webpackJsonp.push([[], { get_require: (mod, _exports, wpRequire) => mod.exports = wpRequire }, [["get_require"]]]); + const all = () => Object.keys(wpRequire.c).map((x) => wpRequire.c[x].exports).filter((x) => x); + router = all().map(m => { + if (typeof m !== "object") return undefined; + for (let prop in m) { if (m[prop]?.Navigate) return m[prop]} + }).find(x => x) + router.NavigateToExternalWeb("http://127.0.0.1:1337/browser/redirect") + })(); + """)
\ No newline at end of file |
