diff options
| author | AAGaming <aa@bigdumb.gq> | 2022-06-01 17:50:10 -0400 |
|---|---|---|
| committer | AAGaming <aa@bigdumb.gq> | 2022-06-01 17:50:10 -0400 |
| commit | 86e23686aacccfe22a24e1d63c57f037b7ce2a4d (patch) | |
| tree | a7b899385d8d4523f966497778a31ddc14a270b2 /frontend/src/plugin-loader.tsx | |
| parent | bd1b2e82fdc6ff1725bab61593e1f54d0b975fe0 (diff) | |
| download | decky-loader-86e23686aacccfe22a24e1d63c57f037b7ce2a4d.tar.gz decky-loader-86e23686aacccfe22a24e1d63c57f037b7ce2a4d.zip | |
React Plugin install dialog (closes #75)
Diffstat (limited to 'frontend/src/plugin-loader.tsx')
| -rw-r--r-- | frontend/src/plugin-loader.tsx | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index 200fffdc..0c62ad5d 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -1,3 +1,4 @@ +import { ModalRoot, showModal, staticClasses } from 'decky-frontend-lib'; import { FaPlug } from 'react-icons/fa'; import { DeckyState, DeckyStateContextProvider } from './components/DeckyState'; @@ -40,6 +41,25 @@ class PluginLoader extends Logger { }); } + public addPluginInstallPrompt(artifact: string, version: string, request_id: string) { + showModal( + <ModalRoot + onOK={() => { + console.log('ok'); + this.callServerMethod('confirm_plugin_install', { request_id }); + }} + onCancel={() => { + console.log('nope'); + this.callServerMethod('cancel_plugin_install', { request_id }); + }} + > + <div className={staticClasses.Title}> + Install {artifact} version {version}? + </div> + </ModalRoot>, + ); + } + public dismountAll() { for (const plugin of this.plugins) { this.log(`Dismounting ${plugin.name}`); @@ -82,33 +102,22 @@ class PluginLoader extends Logger { }); } + async callServerMethod(methodName: string, args = {}) { + const response = await fetch(`http://127.0.0.1:1337/methods/${methodName}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(args), + }); + + return response.json(); + } + createPluginAPI(pluginName: string) { return { routerHook: this.routerHook, - async callServerMethod(methodName: string, args = {}) { - const response = await fetch(`http://127.0.0.1:1337/methods/${methodName}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(args), - }); - - return response.json(); - }, - async callPluginMethod(methodName: string, args = {}) { - const response = await fetch(`http://127.0.0.1:1337/plugins/${pluginName}/methods/${methodName}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - args, - }), - }); - - return response.json(); - }, + callServerMethod: this.callServerMethod, fetchNoCors(url: string, request: any = {}) { let args = { method: 'POST', headers: {}, body: '' }; const req = { ...args, ...request, url, data: request.body }; |
