mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 07:43:44 +08:00
fix: exit hotkey conflict
This commit is contained in:
parent
7d1b7adda5
commit
c21ce578f5
@ -24,16 +24,6 @@ impl Hotkey {
|
||||
*self.app_handle.lock() = Some(app_handle.clone());
|
||||
let verge = Config::verge();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(self.register("CMD+Q", "quit"));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(self.register("Control+Q", "quit"));
|
||||
}
|
||||
|
||||
if let Some(hotkeys) = verge.latest().hotkeys.as_ref() {
|
||||
for hotkey in hotkeys.iter() {
|
||||
let mut iter = hotkey.split(',');
|
||||
@ -57,7 +47,7 @@ impl Hotkey {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn register(&self, hotkey: &str, func: &str) -> Result<()> {
|
||||
pub fn register(&self, hotkey: &str, func: &str) -> Result<()> {
|
||||
let app_handle = self.app_handle.lock();
|
||||
if app_handle.is_none() {
|
||||
bail!("failed to get the hotkey manager");
|
||||
@ -97,7 +87,7 @@ impl Hotkey {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unregister(&self, hotkey: &str) -> Result<()> {
|
||||
pub fn unregister(&self, hotkey: &str) -> Result<()> {
|
||||
let app_handle = self.app_handle.lock();
|
||||
if app_handle.is_none() {
|
||||
bail!("failed to get the hotkey manager");
|
||||
|
@ -5,6 +5,7 @@ mod enhance;
|
||||
mod feat;
|
||||
mod utils;
|
||||
|
||||
use crate::core::hotkey;
|
||||
use crate::utils::{resolve, resolve::resolve_scheme, server};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::Listener;
|
||||
@ -149,6 +150,28 @@ pub fn run() {
|
||||
tauri::WindowEvent::Moved(_) | tauri::WindowEvent::Resized(_) => {
|
||||
let _ = resolve::save_window_size_position(app_handle, false);
|
||||
}
|
||||
tauri::WindowEvent::Focused(true) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().register("CMD+Q", "quit"));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().register()("Control+Q", "quit"));
|
||||
};
|
||||
}
|
||||
tauri::WindowEvent::Focused(false) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister("CMD+Q"));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister()("Control+Q"));
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user