From fc5c959a55d80e24725d799bf7dff214e8a36a9e Mon Sep 17 00:00:00 2001 From: huzibaca Date: Wed, 25 Sep 2024 15:45:12 +0800 Subject: [PATCH] chore: unified hotkey registration --- src-tauri/src/lib.rs | 2 ++ src/pages/_layout.tsx | 8 +------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 85d39d9..a04561f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -158,6 +158,7 @@ pub fn run() { #[cfg(not(target_os = "macos"))] { log_err!(hotkey::Hotkey::global().register("Control+Q", "quit")); + log_err!(hotkey::Hotkey::global().register("Escape", "quit")); }; } tauri::WindowEvent::Focused(false) => { @@ -169,6 +170,7 @@ pub fn run() { #[cfg(not(target_os = "macos"))] { log_err!(hotkey::Hotkey::global().unregister("Control+Q")); + log_err!(hotkey::Hotkey::global().unregister("Escape")); }; } _ => {} diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index df86330..9a7b662 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -27,6 +27,7 @@ import "dayjs/locale/zh-cn"; import { getPortableFlag } from "@/services/cmds"; import React from "react"; import { TransitionGroup, CSSTransition } from "react-transition-group"; + const appWindow = getCurrentWebviewWindow(); export let portableFlag = false; @@ -48,13 +49,6 @@ const Layout = () => { if (!routersEles) return null; useEffect(() => { - window.addEventListener("keydown", (e) => { - // macOS有cmd+w - if (e.key === "Escape" && OS !== "macos") { - appWindow.close(); - } - }); - listen("verge://refresh-clash-config", async () => { // the clash info may be updated await getAxios(true);