From 3efd575dd206c32b15c4187ee53916fddfeda6ba Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Sun, 10 Sep 2023 14:46:03 +0800
Subject: [PATCH] feat: add Open Dashboard to the hotkey, close #723

---
 src-tauri/src/core/hotkey.rs                  |  1 +
 src-tauri/src/feat.rs                         | 10 ++++++++++
 src/components/setting/mods/hotkey-viewer.tsx |  1 +
 src/locales/en.json                           |  1 +
 src/locales/ru.json                           |  1 +
 src/locales/zh.json                           |  1 +
 6 files changed, 15 insertions(+)

diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs
index b55babb..cd4c149 100644
--- a/src-tauri/src/core/hotkey.rs
+++ b/src-tauri/src/core/hotkey.rs
@@ -76,6 +76,7 @@ impl Hotkey {
         }
 
         let f = match func.trim() {
+            "open_dashboard" => || feat::open_dashboard(),
             "clash_mode_rule" => || feat::change_clash_mode("rule".into()),
             "clash_mode_global" => || feat::change_clash_mode("global".into()),
             "clash_mode_direct" => || feat::change_clash_mode("direct".into()),
diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs
index a3a0768..a446c27 100644
--- a/src-tauri/src/feat.rs
+++ b/src-tauri/src/feat.rs
@@ -7,10 +7,20 @@
 use crate::config::*;
 use crate::core::*;
 use crate::log_err;
+use crate::utils::resolve;
 use anyhow::{bail, Result};
 use serde_yaml::{Mapping, Value};
 use wry::application::clipboard::Clipboard;
 
+// 打开面板
+pub fn open_dashboard() {
+    let handle = handle::Handle::global();
+    let app_handle = handle.app_handle.lock();
+    if let Some(app_handle) = app_handle.as_ref() {
+        resolve::create_window(app_handle);
+    }
+}
+
 // 重启clash
 pub fn restart_clash_core() {
     tauri::async_runtime::spawn(async {
diff --git a/src/components/setting/mods/hotkey-viewer.tsx b/src/components/setting/mods/hotkey-viewer.tsx
index 41879f1..a47d30e 100644
--- a/src/components/setting/mods/hotkey-viewer.tsx
+++ b/src/components/setting/mods/hotkey-viewer.tsx
@@ -14,6 +14,7 @@ const ItemWrapper = styled("div")`
 `;
 
 const HOTKEY_FUNC = [
+  "open_dashboard",
   "clash_mode_rule",
   "clash_mode_global",
   "clash_mode_direct",
diff --git a/src/locales/en.json b/src/locales/en.json
index 1ac4a0e..eedfcfd 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -108,6 +108,7 @@
   "Download Speed": "Download Speed",
   "Upload Speed": "Upload Speed",
 
+  "open_dashboard": "Open Dashboard",
   "clash_mode_rule": "Rule Mode",
   "clash_mode_global": "Global Mode",
   "clash_mode_direct": "Direct Mode",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index 58eac6d..f8ea10b 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -97,6 +97,7 @@
   "Save": "Сохранить",
   "Cancel": "Отмена",
 
+  "open_dashboard": "Open Dashboard",
   "clash_mode_rule": "Режим правил",
   "clash_mode_global": "Глобальный режим",
   "clash_mode_direct": "Прямой режим",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 26964be..b70f738 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -108,6 +108,7 @@
   "Download Speed": "下载速度",
   "Upload Speed": "上传速度",
 
+  "open_dashboard": "打开面板",
   "clash_mode_rule": "规则模式",
   "clash_mode_global": "全局模式",
   "clash_mode_direct": "直连模式",
-- 
GitLab