Forráskód Böngészése

feat: Support Open/Close Dashboard Hotkey

#439
MystiPanda 1 éve
szülő
commit
2835e79973

+ 1 - 1
src-tauri/src/core/hotkey.rs

@@ -65,7 +65,7 @@ impl Hotkey {
         }
 
         let f = match func.trim() {
-            "open_dashboard" => feat::open_dashboard,
+            "open_or_close_dashboard" => feat::open_or_close_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()),

+ 8 - 2
src-tauri/src/feat.rs

@@ -10,13 +10,19 @@ use crate::log_err;
 use crate::utils::resolve;
 use anyhow::{bail, Result};
 use serde_yaml::{Mapping, Value};
-use tauri::{AppHandle, ClipboardManager};
+use tauri::{AppHandle, ClipboardManager, Manager};
 
 // 打开面板
-pub fn open_dashboard() {
+pub fn open_or_close_dashboard() {
     let handle = handle::Handle::global();
     let app_handle = handle.app_handle.lock();
     if let Some(app_handle) = app_handle.as_ref() {
+        if let Some(window) = app_handle.get_window("main") {
+            if let Ok(true) = window.is_focused() {
+                let _ = window.close();
+                return;
+            }
+        }
         resolve::create_window(app_handle);
     }
 }

+ 1 - 1
src/components/setting/mods/hotkey-viewer.tsx

@@ -14,7 +14,7 @@ const ItemWrapper = styled("div")`
 `;
 
 const HOTKEY_FUNC = [
-  "open_dashboard",
+  "open_or_close_dashboard",
   "clash_mode_rule",
   "clash_mode_global",
   "clash_mode_direct",

+ 1 - 1
src/locales/en.json

@@ -138,7 +138,7 @@
   "Download Speed": "Download Speed",
   "Upload Speed": "Upload Speed",
 
-  "open_dashboard": "Open Dashboard",
+  "open_or_close_dashboard": "Open/Close Dashboard",
   "clash_mode_rule": "Rule Mode",
   "clash_mode_global": "Global Mode",
   "clash_mode_direct": "Direct Mode",

+ 1 - 1
src/locales/ru.json

@@ -118,7 +118,7 @@
   "Cancel": "Отмена",
   "Exit": "Выход",
 
-  "open_dashboard": "Open Dashboard",
+  "open_or_close_dashboard": "Open/Close Dashboard",
   "clash_mode_rule": "Режим правил",
   "clash_mode_global": "Глобальный режим",
   "clash_mode_direct": "Прямой режим",

+ 1 - 1
src/locales/zh.json

@@ -138,7 +138,7 @@
   "Download Speed": "下载速度",
   "Upload Speed": "上传速度",
 
-  "open_dashboard": "打开面板",
+  "open_or_close_dashboard": "打开/关闭面板",
   "clash_mode_rule": "规则模式",
   "clash_mode_global": "全局模式",
   "clash_mode_direct": "直连模式",