From 4daf028e7acb49932e274ad5c32cd98045c7474a Mon Sep 17 00:00:00 2001
From: botato <63275405+botatooo@users.noreply.github.com>
Date: Fri, 1 Jul 2022 23:43:17 +0000
Subject: Uninstall functionality (#97)
* feat: POC uninstallation feature
* Fixes, placeholder
* bugfix: wrong function call
* add oncancel and change function called
* clean up plugin uninstall code
* bugfix, uninstall in store
* Limit scope of feature branch
* feat: PluginLoader.unloadPlugin
* problematic logs
---
backend/browser.py | 34 +++++++++++++++---
frontend/src/components/settings/index.tsx | 6 ++++
.../src/components/settings/pages/PluginList.tsx | 32 +++++++++++++++++
frontend/src/plugin-loader.tsx | 41 ++++++++++++++++++----
4 files changed, 102 insertions(+), 11 deletions(-)
create mode 100644 frontend/src/components/settings/pages/PluginList.tsx
diff --git a/backend/browser.py b/backend/browser.py
index 37099e19..316d57a8 100644
--- a/backend/browser.py
+++ b/backend/browser.py
@@ -1,6 +1,6 @@
from injector import get_tab
from logging import getLogger
-from os import path, rename
+from os import path, rename, listdir
from shutil import rmtree
from aiohttp import ClientSession, web
from io import BytesIO
@@ -11,6 +11,8 @@ from time import time
from hashlib import sha256
from subprocess import Popen
+import json
+
class PluginInstallContext:
def __init__(self, artifact, name, version, hash) -> None:
self.artifact = artifact
@@ -25,7 +27,8 @@ class PluginBrowser:
self.install_requests = {}
server_instance.add_routes([
- web.post("/browser/install_plugin", self.install_plugin)
+ 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):
@@ -39,8 +42,31 @@ class PluginBrowser:
Popen(["chmod", "-R", "555", self.plugin_path])
return True
+ def find_plugin_folder(self, name):
+ for folder in listdir(self.plugin_path):
+ with open(path.join(self.plugin_path, folder, 'plugin.json'), 'r') as f:
+ plugin = json.load(f)
+
+ if plugin['name'] == name:
+ return path.join(self.plugin_path, folder)
+
+ async def uninstall_plugin(self, name):
+ tab = await get_tab("SP")
+ await tab.open_websocket()
+
+ try:
+ if type(name) != str:
+ data = await name.post()
+ name = data.get("name")
+ await tab.evaluate_js(f"DeckyPluginLoader.unloadPlugin('{name}')")
+ rmtree(self.find_plugin_folder(name))
+ except FileNotFoundError:
+ self.log.warning(f"Plugin {name} not installed, skipping uninstallation")
+
+ return web.Response(text="Requested plugin uninstall")
+
async def _install(self, artifact, name, version, hash):
- rmtree(path.join(self.plugin_path, name), ignore_errors=True)
+ self.uninstall_plugin(name)
self.log.info(f"Installing {name} (Version: {version})")
async with ClientSession() as client:
self.log.debug(f"Fetching {artifact}")
@@ -83,4 +109,4 @@ class PluginBrowser:
await self._install(request.artifact, request.name, request.version, request.hash)
def cancel_plugin_install(self, request_id):
- self.install_requests.pop(request_id)
\ No newline at end of file
+ self.install_requests.pop(request_id)
diff --git a/frontend/src/components/settings/index.tsx b/frontend/src/components/settings/index.tsx
index d4799fa9..f9c84c7b 100644
--- a/frontend/src/components/settings/index.tsx
+++ b/frontend/src/components/settings/index.tsx
@@ -1,6 +1,7 @@
import { SidebarNavigation } from 'decky-frontend-lib';
import GeneralSettings from './pages/GeneralSettings';
+import PluginList from './pages/PluginList';
export default function SettingsPage() {
return (
@@ -13,6 +14,11 @@ export default function SettingsPage() {
content:
No plugins installed
+