From 0f5923a10a55dc4fde7a251c1b0312d496f2343c Mon Sep 17 00:00:00 2001
From: GyDi <segydi@foxmail.com>
Date: Thu, 3 Mar 2022 01:58:05 +0800
Subject: [PATCH] chore: enhance wip

---
 src/main.tsx            |  3 +++
 src/services/enhance.ts | 22 ++++++++++++++++++++++
 src/services/types.ts   | 11 +++++++++++
 3 files changed, 36 insertions(+)
 create mode 100644 src/services/enhance.ts

diff --git a/src/main.tsx b/src/main.tsx
index af6d7de..2c0d0c4 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -6,6 +6,9 @@ import ReactDOM from "react-dom";
 import { RecoilRoot } from "recoil";
 import { BrowserRouter } from "react-router-dom";
 import Layout from "./pages/_layout";
+import setup from "./services/enhance";
+
+setup();
 
 ReactDOM.render(
   <React.StrictMode>
diff --git a/src/services/enhance.ts b/src/services/enhance.ts
new file mode 100644
index 0000000..6d42355
--- /dev/null
+++ b/src/services/enhance.ts
@@ -0,0 +1,22 @@
+import { emit, listen } from "@tauri-apps/api/event";
+import { CmdType } from "./types";
+
+export default function setup() {
+  listen("script-handler", (event) => {
+    const payload = event.payload as CmdType.EnhancedPayload;
+    console.log(payload);
+
+    // setTimeout(() => {
+    //   try {
+    //     const fn = eval(payload.script + "\n\nmixin");
+    //     console.log(fn);
+
+    //     const result = fn(payload.params || {});
+    //     console.log("result", result);
+    //     emit(payload.callback, JSON.stringify(result)).catch(console.error);
+    //   } catch (err) {
+    //     console.error(err);
+    //   }
+    // }, 3000);
+  });
+}
diff --git a/src/services/types.ts b/src/services/types.ts
index b9e06f9..d7d86d7 100644
--- a/src/services/types.ts
+++ b/src/services/types.ts
@@ -121,4 +121,15 @@ export namespace CmdType {
     enable_proxy_guard?: boolean;
     system_proxy_bypass?: string;
   }
+
+  export interface ChainItem {
+    item: ProfileItem;
+    merge?: object;
+    script?: string;
+  }
+
+  export interface EnhancedPayload {
+    chain: ChainItem[];
+    current: object;
+  }
 }
-- 
GitLab