From 86e23686aacccfe22a24e1d63c57f037b7ce2a4d Mon Sep 17 00:00:00 2001
From: AAGaming <aa@bigdumb.gq>
Date: Wed, 1 Jun 2022 17:50:10 -0400
Subject: React Plugin install dialog (closes #75)

---
 frontend/src/plugin-loader.tsx | 57 ++++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

(limited to 'frontend/src/plugin-loader.tsx')

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 };
-- 
cgit v1.2.3

