From 34d1a34b10f4386865f3c241c5ae4026d2bfd8bd Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Sat, 5 Aug 2023 01:11:43 -0400
Subject: Migrate most of frontend callServerMethod usage over to websocket

---
 frontend/src/plugin-loader.tsx | 36 ++++++++++++------------------------
 1 file changed, 12 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 86592016..3c9ba818 100644
--- a/frontend/src/plugin-loader.tsx
+++ b/frontend/src/plugin-loader.tsx
@@ -34,7 +34,6 @@ import Toaster from './toaster';
 import { VerInfo, callUpdaterMethod } from './updater';
 import { getSetting, setSetting } from './utils/settings';
 import TranslationHelper, { TranslationClass } from './utils/TranslationHelper';
-import { WSRouter } from './wsrouter';
 
 const StorePage = lazy(() => import('./components/store/Store'));
 const SettingsPage = lazy(() => import('./components/settings'));
@@ -49,8 +48,6 @@ class PluginLoader extends Logger {
   public toaster: Toaster = new Toaster();
   private deckyState: DeckyState = new DeckyState();
 
-  public ws: WSRouter = new WSRouter();
-
   public hiddenPluginsService = new HiddenPluginsService(this.deckyState);
   public notificationService = new NotificationService(this.deckyState);
 
@@ -105,15 +102,13 @@ class PluginLoader extends Logger {
 
     initFilepickerPatches();
 
-    this.ws.connect().then(() => {
-      this.getUserInfo();
+    this.getUserInfo();
 
-      this.updateVersion();
-    });
+    this.updateVersion();
   }
 
   public async getUserInfo() {
-    const userInfo = (await this.callServerMethod('get_user_info')).result as UserInfo;
+    const userInfo = await window.DeckyBackend.call<[], UserInfo>('utilities/get_user_info');
     setSetting('user_info.user_name', userInfo.username);
     setSetting('user_info.user_home', userInfo.path);
   }
@@ -183,8 +178,8 @@ class PluginLoader extends Logger {
         version={version}
         hash={hash}
         installType={install_type}
-        onOK={() => this.callServerMethod('confirm_plugin_install', { request_id })}
-        onCancel={() => this.callServerMethod('cancel_plugin_install', { request_id })}
+        onOK={() => window.DeckyBackend.call<[string]>('utilities/confirm_plugin_install', request_id)}
+        onCancel={() => window.DeckyBackend.call<[string]>('utilities/cancel_plugin_install', request_id)}
       />,
     );
   }
@@ -196,8 +191,8 @@ class PluginLoader extends Logger {
     showModal(
       <MultiplePluginsInstallModal
         requests={requests}
-        onOK={() => this.callServerMethod('confirm_plugin_install', { request_id })}
-        onCancel={() => this.callServerMethod('cancel_plugin_install', { request_id })}
+        onOK={() => window.DeckyBackend.call<[string]>('utilities/confirm_plugin_install', request_id)}
+        onCancel={() => window.DeckyBackend.call<[string]>('utilities/cancel_plugin_install', request_id)}
       />,
     );
   }
@@ -360,6 +355,7 @@ class PluginLoader extends Logger {
     selectFiles?: boolean,
     regex?: RegExp,
   ): Promise<{ path: string; realpath: string }> {
+    console.warn('openFilePicker is deprecated and will be removed. Please migrate to openFilePickerV2');
     if (selectFiles) {
       return this.openFilePickerV2(FileSelectionType.FILE, startPath, true, true, regex);
     } else {
@@ -443,18 +439,10 @@ class PluginLoader extends Logger {
           code,
         });
       },
-      injectCssIntoTab(tab: string, style: string) {
-        return this.callServerMethod('inject_css_into_tab', {
-          tab,
-          style,
-        });
-      },
-      removeCssFromTab(tab: string, cssId: any) {
-        return this.callServerMethod('remove_css_from_tab', {
-          tab,
-          css_id: cssId,
-        });
-      },
+      injectCssIntoTab: window.DeckyBackend.callable<[tab: string, style: string], string>(
+        'utilities/inject_css_into_tab',
+      ),
+      removeCssFromTab: window.DeckyBackend.callable<[tab: string, cssId: string]>('utilities/remove_css_from_tab'),
     };
   }
 }
-- 
cgit v1.2.3

