Skip to content

Commit

Permalink
🐛 Resolve the issue of closing full screen on Mac.
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Sep 11, 2024
1 parent 4521192 commit 0151686
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 14 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0151686

Please sign in to comment.