fix: whether the window starts as fullscreen or not.

This commit is contained in:
huzibaca 2024-09-18 13:23:27 +08:00
parent f64528dd87
commit 7d1b7adda5
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302

View File

@ -3,8 +3,8 @@ use anyhow::{bail, Result};
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use std::{collections::HashMap, sync::Arc};
use tauri::AppHandle;
use tauri_plugin_global_shortcut::{GlobalShortcutExt, ShortcutState};
use tauri::{AppHandle, Manager};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, ShortcutState};
pub struct Hotkey {
current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置
app_handle: Arc<Mutex<Option<AppHandle>>>,
@ -24,6 +24,16 @@ 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(',');
@ -69,9 +79,17 @@ impl Hotkey {
_ => 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 {
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();
}
}
});