🐛 Resolve the issue of closing full screen on Mac.

This commit is contained in:
Tw93
2024-09-11 20:36:42 +08:00
parent 45211922b9
commit 0151686a18
3 changed files with 30 additions and 3 deletions

15
src-tauri/Cargo.lock generated
View File

@@ -73,6 +73,7 @@ dependencies = [
"tauri-build",
"tauri-plugin-oauth",
"tauri-plugin-window-state",
"tokio",
]
[[package]]
@@ -4145,11 +4146,25 @@ dependencies = [
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.65",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"

View File

@@ -20,6 +20,7 @@ serde = { version = "1.0.202", features = ["derive"] }
tauri = { version = "1.6.6", features = ["api-all", "system-tray"] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "main" }
tokio = { version = "1", features = ["full"] }
[dev-dependencies]
cargo-bloat = "0.11.1"

View File

@@ -9,6 +9,7 @@ mod util;
use app::{invoke, menu, window};
use invoke::{download_file, download_file_by_binary};
use menu::{get_system_tray, system_tray_handle};
use std::time::Duration;
use tauri::{GlobalShortcutManager, Manager};
use util::{get_data_dir, get_pake_config};
use window::build_window;
@@ -61,14 +62,24 @@ pub fn run_app() {
})
.on_window_event(|event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
let window = event.window();
#[cfg(target_os = "macos")]
{
event.window().minimize().unwrap();
event.window().hide().unwrap();
let window_handle = window.clone();
tauri::async_runtime::spawn(async move {
if window_handle.is_fullscreen().unwrap_or(false) {
window_handle.set_fullscreen(false).unwrap();
// Give a small delay to ensure the full-screen exit operation is completed.
tokio::time::sleep(Duration::from_millis(900)).await;
}
window_handle.minimize().unwrap();
window_handle.hide().unwrap();
});
}
#[cfg(not(target_os = "macos"))]
event.window().close().unwrap();
window.close().unwrap();
api.prevent_close();
}