fix: exit hotkey conflict

This commit is contained in:
huzibaca 2024-09-18 15:16:43 +08:00
parent 7d1b7adda5
commit c21ce578f5
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
2 changed files with 25 additions and 12 deletions

View File

@ -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");

View File

@ -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"));
};
}
_ => {}
}
}