From b7c386388296069bc57fe2823f6c82e5d9a48c88 Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Fri, 18 Nov 2022 18:37:17 +0800
Subject: [PATCH] fix: patch clash config

---
 src-tauri/src/feat.rs                             |  2 ++
 src/components/setting/mods/clash-port-viewer.tsx | 12 ++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs
index 7c73631..1648453 100644
--- a/src-tauri/src/feat.rs
+++ b/src-tauri/src/feat.rs
@@ -169,7 +169,9 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
             || patch.get("secret").is_some()
             || patch.get("external-controller").is_some()
         {
+            Config::generate()?;
             CoreManager::global().run_core().await?;
+            handle::Handle::refresh_clash();
         }
 
         // 更新系统代理
diff --git a/src/components/setting/mods/clash-port-viewer.tsx b/src/components/setting/mods/clash-port-viewer.tsx
index 53de768..9c55367 100644
--- a/src/components/setting/mods/clash-port-viewer.tsx
+++ b/src/components/setting/mods/clash-port-viewer.tsx
@@ -61,10 +61,14 @@ const ClashPortViewer = ({ handler }: Props) => {
     setOpen(false);
     if (port === config?.["mixed-port"]) return;
 
-    await patchClashConfig({ "mixed-port": port });
-    setGlobalClashPort(port);
-    Notice.success("Change Clash port successfully!", 1000);
-    mutateClash();
+    try {
+      await patchClashConfig({ "mixed-port": port });
+      setGlobalClashPort(port);
+      Notice.success("Change Clash port successfully!", 1000);
+      mutateClash();
+    } catch (err: any) {
+      Notice.error(err.message || err.toString(), 5000);
+    }
   });
 
   return (
-- 
GitLab