fix: whether the window starts as fullscreen or not.

This commit is contained in:
huzibaca 2024-09-18 13:23:27 +08:00
parent 2f61dc9bc6
commit 2c612e371f

View File

@ -3,8 +3,8 @@ use anyhow::{bail, Result};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use tauri::AppHandle; use tauri::{AppHandle, Manager};
use tauri_plugin_global_shortcut::{GlobalShortcutExt, ShortcutState}; use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, ShortcutState};
pub struct Hotkey { pub struct Hotkey {
current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置 current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置
app_handle: Arc<Mutex<Option<AppHandle>>>, app_handle: Arc<Mutex<Option<AppHandle>>>,
@ -24,6 +24,16 @@ impl Hotkey {
*self.app_handle.lock() = Some(app_handle.clone()); *self.app_handle.lock() = Some(app_handle.clone());
let verge = Config::verge(); 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() { if let Some(hotkeys) = verge.latest().hotkeys.as_ref() {
for hotkey in hotkeys.iter() { for hotkey in hotkeys.iter() {
let mut iter = hotkey.split(','); let mut iter = hotkey.split(',');
@ -69,9 +79,17 @@ impl Hotkey {
_ => bail!("invalid function \"{func}\""), _ => bail!("invalid function \"{func}\""),
}; };
let _ = manager.on_shortcut(hotkey, move |_app_handle, _hotkey, event| { let _ = manager.on_shortcut(hotkey, move |app_handle, hotkey, event| {
if event.state == ShortcutState::Pressed { if event.state == ShortcutState::Pressed {
f() if hotkey.key == Code::KeyQ {
if let Some(window) = app_handle.get_webview_window("main") {
if window.is_focused().unwrap_or(false) {
f();
}
}
} else {
f();
}
} }
}); });