From f320d515d5e7cf4915eef744d0ef3b5351db3f12 Mon Sep 17 00:00:00 2001
From: GyDi <segydi@foxmail.com>
Date: Mon, 6 Dec 2021 10:31:17 +0800
Subject: [PATCH] chore: compatible with macos

---
 .editorconfig                |  7 +++++++
 package.json                 | 12 ++++++------
 src-tauri/Cargo.toml         |  6 +++---
 src-tauri/src/main.rs        | 17 ++++++++++++-----
 src-tauri/src/sysopt.rs      |  3 +++
 src-tauri/tauri.conf.json    |  2 +-
 index.html => src/index.html |  4 ++--
 src/vite-env.d.ts            |  1 -
 vite.config.ts               |  7 -------
 9 files changed, 34 insertions(+), 25 deletions(-)
 create mode 100644 .editorconfig
 rename index.html => src/index.html (80%)
 delete mode 100644 src/vite-env.d.ts
 delete mode 100644 vite.config.ts

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..33fc5f0
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+indent_size = 2
+insert_final_newline = true
diff --git a/package.json b/package.json
index 2a28add..e8e89d4 100644
--- a/package.json
+++ b/package.json
@@ -4,9 +4,9 @@
   "scripts": {
     "dev": "tauri dev",
     "build": "tauri build",
-    "web:dev": "vite",
-    "web:build": "tsc && vite build",
-    "web:serve": "vite preview"
+    "web:dev": "parcel src/index.html -p 3000",
+    "web:build": "parcel build",
+    "tauri": "tauri"
   },
   "dependencies": {
     "@emotion/react": "^11.7.0",
@@ -19,12 +19,12 @@
     "react-router-dom": "^6.0.2"
   },
   "devDependencies": {
+    "@parcel/transformer-sass": "^2.0.1",
     "@tauri-apps/cli": "^1.0.0-beta.10",
     "@types/react": "^17.0.0",
     "@types/react-dom": "^17.0.0",
-    "@vitejs/plugin-react": "^1.0.0",
+    "parcel": "^2.0.1",
     "sass": "^1.44.0",
-    "typescript": "^4.5.2",
-    "vite": "^2.6.14"
+    "typescript": "^4.5.2"
   }
 }
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 22fded5..e6a188b 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -9,8 +9,6 @@ default-run = "app"
 edition = "2021"
 build = "src/build.rs"
 
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
 [build-dependencies]
 tauri-build = { version = "1.0.0-beta.4" }
 
@@ -20,10 +18,12 @@ serde_json = "1.0"
 serde_yaml = "0.8"
 serde = { version = "1.0", features = ["derive"] }
 tauri = { version = "1.0.0-beta.8", features = ["api-all", "system-tray"] }
-winreg = { version = "0.10", features = ["transactions"] }
 reqwest = { version = "0.11", features = ["json"] }
 tokio = { version = "1", features = ["full"] }
 
+[target.'cfg(windows)'.dependencies]
+winreg = { version = "0.10", features = ["transactions"] }
+
 [features]
 default = [ "custom-protocol" ]
 custom-protocol = [ "tauri/custom-protocol" ]
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 8672947..b65f833 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -19,13 +19,15 @@ async fn get_config_data(url: String) -> Result<String, String> {
 }
 
 fn main() -> std::io::Result<()> {
-  let config = sysopt::get_proxy_config()?;
-  println!("{:?}", config);
+  clash::run_clash_bin(&clash::get_config_dir().to_str().unwrap());
 
   let app = tauri::Builder::default()
     .system_tray(
-      SystemTray::new()
-        .with_menu(SystemTrayMenu::new().add_item(CustomMenuItem::new("tray_event_quit", "Quit"))),
+      SystemTray::new().with_menu(
+        SystemTrayMenu::new()
+          .add_item(CustomMenuItem::new("event_show", "Show"))
+          .add_item(CustomMenuItem::new("event_quit", "Quit")),
+      ),
     )
     .on_system_tray_event(move |app, event| match event {
       SystemTrayEvent::LeftClick { .. } => {
@@ -35,7 +37,12 @@ fn main() -> std::io::Result<()> {
       }
 
       SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
-        "tray_event_quit" => {
+        "event_show" => {
+          let window = app.get_window("main").unwrap();
+          window.show().unwrap();
+          window.set_focus().unwrap();
+        }
+        "event_quit" => {
           app.exit(0);
         }
         _ => {}
diff --git a/src-tauri/src/sysopt.rs b/src-tauri/src/sysopt.rs
index 7673a4f..b21e769 100644
--- a/src-tauri/src/sysopt.rs
+++ b/src-tauri/src/sysopt.rs
@@ -1,6 +1,9 @@
 use serde::{Deserialize, Serialize};
 use std::io;
+
+#[cfg(target_os = "windows")]
 use winreg::enums::*;
+#[cfg(target_os = "windows")]
 use winreg::RegKey;
 
 #[derive(Debug, Deserialize, Serialize)]
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 2507988..4f74bb1 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -26,7 +26,7 @@
         "icons/icon.ico"
       ],
       "resources": [],
-      "externalBin": ["bin/clash"],
+      "externalBin": ["sidebar/clash"],
       "copyright": "",
       "category": "DeveloperTool",
       "shortDescription": "",
diff --git a/index.html b/src/index.html
similarity index 80%
rename from index.html
rename to src/index.html
index 1e59864..d03124c 100644
--- a/index.html
+++ b/src/index.html
@@ -7,10 +7,10 @@
       rel="stylesheet"
       href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
     />
-    <title>Vite App</title>
+    <title>Clash Verge</title>
   </head>
   <body>
     <div id="root"></div>
-    <script type="module" src="/src/main.tsx"></script>
+    <script type="module" src="./main.tsx"></script>
   </body>
 </html>
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
deleted file mode 100644
index 11f02fe..0000000
--- a/src/vite-env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-/// <reference types="vite/client" />
diff --git a/vite.config.ts b/vite.config.ts
deleted file mode 100644
index 9cc50ea..0000000
--- a/vite.config.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { defineConfig } from "vite";
-import react from "@vitejs/plugin-react";
-
-// https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [react()],
-});
-- 
GitLab