diff options
| author | botato <63275405+botatooo@users.noreply.github.com> | 2022-07-01 23:43:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-01 16:43:17 -0700 |
| commit | 4daf028e7acb49932e274ad5c32cd98045c7474a (patch) | |
| tree | fa75d035d90d30d3cb7e2ecd17cb3f8e8f67b168 /frontend | |
| parent | 934a50f683f579695292f88437d91d4fce2f4edc (diff) | |
| download | decky-loader-4daf028e7acb49932e274ad5c32cd98045c7474a.tar.gz decky-loader-4daf028e7acb49932e274ad5c32cd98045c7474a.zip | |
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
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/src/components/settings/index.tsx | 6 | ||||
| -rw-r--r-- | frontend/src/components/settings/pages/PluginList.tsx | 32 | ||||
| -rw-r--r-- | frontend/src/plugin-loader.tsx | 41 |
3 files changed, 72 insertions, 7 deletions
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: <GeneralSettings />, route: '/decky/settings/general', }, + { + title: 'Plugins', + content: <PluginList />, + route: '/decky/settings/plugins', + }, ]} /> ); diff --git a/frontend/src/components/settings/pages/PluginList.tsx b/frontend/src/components/settings/pages/PluginList.tsx new file mode 100644 index 00000000..4fd2c063 --- /dev/null +++ b/frontend/src/components/settings/pages/PluginList.tsx @@ -0,0 +1,32 @@ +import { DialogButton, staticClasses } from 'decky-frontend-lib'; +import { FaTrash } from 'react-icons/fa'; + +export default function PluginList() { + const plugins = window.DeckyPluginLoader?.getPlugins(); + + if (plugins.length === 0) { + return ( + <div> + <p>No plugins installed</p> + </div> + ); + } + + return ( + <ul style={{ listStyleType: 'none' }}> + {window.DeckyPluginLoader?.getPlugins().map(({ name }) => ( + <li style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}> + <span>{name}</span> + <div className={staticClasses.Title} style={{ marginLeft: 'auto', boxShadow: 'none' }}> + <DialogButton + style={{ height: '40px', width: '40px', padding: '10px 12px' }} + onClick={() => window.DeckyPluginLoader.uninstall_plugin(name)} + > + <FaTrash /> + </DialogButton> + </div> + </li> + ))} + </ul> + ); +} diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index b3df0f28..fc48fdd9 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -47,6 +47,10 @@ class PluginLoader extends Logger { this.routerHook.addRoute('/decky/settings', () => <SettingsPage />); } + public getPlugins() { + return this.plugins; + } + public addPluginInstallPrompt(artifact: string, version: string, request_id: string, hash: string) { showModal( <ModalRoot @@ -66,6 +70,28 @@ class PluginLoader extends Logger { ); } + public uninstall_plugin(name: string) { + showModal( + <ModalRoot + onOK={async () => { + const formData = new FormData(); + formData.append('name', name); + await fetch('http://localhost:1337/browser/uninstall_plugin', { + method: 'POST', + body: formData, + }); + }} + onCancel={() => { + // do nothing + }} + > + <div className={staticClasses.Title} style={{ flexDirection: 'column' }}> + Uninstall {name}? + </div> + </ModalRoot>, + ); + } + public dismountAll() { for (const plugin of this.plugins) { this.log(`Dismounting ${plugin.name}`); @@ -78,6 +104,13 @@ class PluginLoader extends Logger { this.routerHook.removeRoute('/decky/settings'); } + public unloadPlugin(name: string) { + const plugin = this.plugins.find((plugin) => plugin.name === name || plugin.name === name.replace('$LEGACY_', '')); + plugin?.onDismount?.(); + this.plugins = this.plugins.filter((p) => p !== plugin); + this.deckyState.setPlugins(this.plugins); + } + public async importPlugin(name: string) { if (this.reloadLock) { this.log('Reload currently in progress, adding to queue', name); @@ -89,13 +122,7 @@ class PluginLoader extends Logger { this.reloadLock = true; this.log(`Trying to load ${name}`); - const oldPlugin = this.plugins.find( - (plugin) => plugin.name === name || plugin.name === name.replace('$LEGACY_', ''), - ); - if (oldPlugin) { - oldPlugin.onDismount?.(); - this.plugins = this.plugins.filter((plugin) => plugin !== oldPlugin); - } + this.unloadPlugin(name); if (name.startsWith('$LEGACY_')) { await this.importLegacyPlugin(name.replace('$LEGACY_', '')); |
