summaryrefslogtreecommitdiff
path: root/backend/browser.py
diff options
context:
space:
mode:
authorbotato <63275405+botatooo@users.noreply.github.com>2022-08-27 00:01:23 -0400
committerGitHub <noreply@github.com>2022-08-26 21:01:23 -0700
commitb7d7ca04e12690b5e65259c8806e5e895cdc16aa (patch)
tree4cca1b72b69622e536dbb1ba13656d39a9420685 /backend/browser.py
parentd4d1c2bbabfcec3c62767e614c9d67f516938af2 (diff)
downloaddecky-loader-b7d7ca04e12690b5e65259c8806e5e895cdc16aa.tar.gz
decky-loader-b7d7ca04e12690b5e65259c8806e5e895cdc16aa.zip
Refractor plugin backend (#111)v2.0.5-pre18
* refractor uninstall plugin backend * refractor plugin installation method * Change formatting in browser.py * Manually format main.py * Manually format utilities.py * remove inconsistency * remove unnecessary linebreaks * lol what * last minute pythoning * Fix async missing * lint * more refractor * await forgotten * fix: menu not disappearing after first click * lint * bug: fix double click on uninstall * depricate request installs * basic patch notes viewer, lazy-load settings and store, build frontend as esmodule, add lazy-loaded react-markdown, backend changes to accomodate ESModule frontend * refractor uninstall plugin backend * Change formatting in browser.py * Manually format main.py * Manually format utilities.py * remove unnecessary linebreaks * lol what * last minute pythoning * Fix async missing * rebase onto main * fix error, fix React crash if patch notes are opened before remote version info is loaded Co-authored-by: TrainDoctor <traindoctor@protonmail.com> Co-authored-by: AAGaming <aa@mail.catvibers.me>
Diffstat (limited to 'backend/browser.py')
-rw-r--r--backend/browser.py39
1 files changed, 11 insertions, 28 deletions
diff --git a/backend/browser.py b/backend/browser.py
index 1261c057..c5b4f474 100644
--- a/backend/browser.py
+++ b/backend/browser.py
@@ -28,16 +28,11 @@ class PluginInstallContext:
self.hash = hash
class PluginBrowser:
- def __init__(self, plugin_path, server_instance, plugins) -> None:
+ def __init__(self, plugin_path, plugins) -> None:
self.plugin_path = plugin_path
self.plugins = plugins
self.install_requests = {}
- server_instance.add_routes([
- web.post("/browser/install_plugin", self.install_plugin),
- web.post("/browser/uninstall_plugin", self.uninstall_plugin)
- ])
-
def _unzip_to_plugin_dir(self, zip, name, hash):
zip_hash = sha256(zip.getbuffer()).hexdigest()
if hash and (zip_hash != hash):
@@ -64,25 +59,19 @@ class PluginBrowser:
async def uninstall_plugin(self, name):
tab = await get_tab("SP")
-
try:
- if type(name) != str:
- data = await name.post()
- name = data.get("name", "undefined")
logger.info("uninstalling " + name)
logger.info(" at dir " + self.find_plugin_folder(name))
await tab.evaluate_js(f"DeckyPluginLoader.unloadPlugin('{name}')")
if self.plugins[name]:
self.plugins[name].stop()
- self.plugins.pop(name, None)
+ self.plugins.remove(name)
rmtree(self.find_plugin_folder(name))
except FileNotFoundError:
logger.warning(f"Plugin {name} not installed, skipping uninstallation")
- return web.Response(text="Requested plugin uninstall")
-
async def _install(self, artifact, name, version, hash):
- try:
+ try:
await self.uninstall_plugin(name)
except:
logger.error(f"Plugin {name} not installed, skipping uninstallation")
@@ -95,29 +84,23 @@ class PluginBrowser:
data = await res.read()
logger.debug(f"Read {len(data)} bytes")
res_zip = BytesIO(data)
- with ProcessPoolExecutor() as executor:
- logger.debug("Unzipping...")
- ret = self._unzip_to_plugin_dir(res_zip, name, hash)
- if ret:
- logger.info(f"Installed {name} (Version: {version})")
- await inject_to_tab("SP", "window.syncDeckyPlugins()")
- else:
- logger.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})")
+ logger.debug("Unzipping...")
+ ret = self._unzip_to_plugin_dir(res_zip, name, hash)
+ if ret:
+ logger.info(f"Installed {name} (Version: {version})")
+ await inject_to_tab("SP", "window.syncDeckyPlugins()")
+ else:
+ self.log.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})")
else:
logger.fatal(f"Could not fetch from URL. {await res.text()}")
- async def install_plugin(self, request):
- data = await request.post()
- get_event_loop().create_task(self.request_plugin_install(data.get("artifact", ""), data.get("name", "No name"), data.get("version", "dev"), data.get("hash", False)))
- return web.Response(text="Requested plugin install")
-
async def request_plugin_install(self, artifact, name, version, hash):
request_id = str(time())
self.install_requests[request_id] = PluginInstallContext(artifact, name, version, hash)
tab = await get_tab("SP")
await tab.open_websocket()
await tab.evaluate_js(f"DeckyPluginLoader.addPluginInstallPrompt('{name}', '{version}', '{request_id}', '{hash}')")
-
+
async def confirm_plugin_install(self, request_id):
request = self.install_requests.pop(request_id)
await self._install(request.artifact, request.name, request.version, request.hash)