Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix: leave full screen at the configured size on macOS
Tw93be35fa3327fd
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex 92517028..1b5050c0 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -319,9 +319,38 @@ pub fn reveal_built_window(window: &WebviewWindow) {}let _ = window.show();reapply_window_icon(window);+ #[cfg(target_os = "macos")]+ enter_configured_fullscreen(window);let _ = window.set_focus();}+/// Puts a window into full screen the first time it is shown when the app is set to+/// start in full screen. Once per window, so a window the user took out of full+/// screen stays out when it is hidden and shown again.+#[cfg(target_os = "macos")]+pub fn enter_configured_fullscreen(window: &WebviewWindow) {+ static ENTERED: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());+ let configured = window+ .app_handle()+ .try_state::<MultiWindowState>()+ .is_some_and(|state| state.pake_config.windows[0].fullscreen);+ let Ok(mut entered) = ENTERED.lock() else {+ return;+ };+ let label = window.label().to_string();+ let first_show = !entered.contains(&label);+ if crate::util::enters_fullscreen_on_show(+ configured,+ first_show,+ window.is_fullscreen().unwrap_or(false),+ ) {+ let _ = window.set_fullscreen(true);+ }+ if configured && first_show {+ entered.push(label);+ }+}+/// True when any Pake webview window is currently on screen.////// A minimized window does not count. Windows keeps `IsWindowVisible` true while@@ -353,6 +382,8 @@ pub fn show_all_app_windows(app: &AppHandle, init_fullscreen: bool) {if init_fullscreen && !window.is_fullscreen().unwrap_or(false) {let _ = window.set_fullscreen(true);}+ #[cfg(target_os = "macos")]+ enter_configured_fullscreen(window);}#[cfg(not(target_os = "linux"))]let _ = init_fullscreen;@@ -580,7 +611,10 @@ fn build_window(.always_on_top(window_config.always_on_top).incognito(window_config.incognito);- #[cfg(any(target_os = "windows", target_os = "macos"))]+ // macOS enters full screen once the window is shown (`enter_configured_fullscreen`):+ // tao gives a window built full screen the screen's frame as its own size, so+ // leaving full screen kept the screen's size instead of the configured one.+ #[cfg(target_os = "windows")]{window_builder = window_builder.fullscreen(window_config.fullscreen);}@@ -913,6 +947,13 @@ fn build_window(let window = window_builder.build()?;+ // A popup is built visible, so it can enter full screen now; a hidden window+ // enters when it is first shown.+ #[cfg(target_os = "macos")]+ if visible {+ enter_configured_fullscreen(&window);+ }+#[cfg(target_os = "windows")]{let password_autosave = window_config.password_autosave_enabled();diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex a656ca51..242e2f77 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -27,6 +27,8 @@ const WEBKIT_DMABUF_RENDERER_FORCE_SHM: &str = "WEBKIT_DMABUF_RENDERER_FORCE_SHM#[cfg(target_os = "linux")]const GDK_BACKEND: &str = "GDK_BACKEND";+#[cfg(target_os = "macos")]+use app::window::enter_configured_fullscreen;use app::{invoke::{clear_dock_badge, close_notification, download_file, increment_dock_badge, quit_app,@@ -85,6 +87,9 @@ fn reveal_startup_window(window: WebviewWindow, init_fullscreen: bool, revealed:}}+ #[cfg(target_os = "macos")]+ enter_configured_fullscreen(&window);+#[cfg(not(target_os = "linux"))]let _ = init_fullscreen;});@@ -359,6 +364,8 @@ pub fn run_app() {let _ = window.unminimize();let _ = window.show();reapply_window_icon(&window);+ #[cfg(target_os = "macos")]+ enter_configured_fullscreen(&window);let _ = window.set_focus();}},@@ -552,6 +559,8 @@ pub fn run_app() {cancel_startup_reveal(&reopen_revealed);let _ = window.show();reapply_window_icon(&window);+ #[cfg(target_os = "macos")]+ enter_configured_fullscreen(&window);let _ = window.set_focus();}}diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rsindex 1514b4f0..8c361653 100644--- a/src-tauri/src/util.rs+++ b/src-tauri/src/util.rs@@ -542,6 +542,13 @@ pub fn check_file_or_append(file_path: &str) -> String {new_path.to_string_lossy().into_owned()}+/// Whether a window enters full screen as it is shown: only when the app is set to+/// start in full screen, only on the window's first show, and not when it already is.+#[cfg(any(target_os = "macos", test))]+pub fn enters_fullscreen_on_show(configured: bool, first_show: bool, fullscreen_now: bool) -> bool {+ configured && first_show && !fullscreen_now+}+#[cfg(test)]mod tests {use super::*;@@ -582,6 +589,16 @@ mod tests {fs::remove_dir_all(path.parent().unwrap().parent().unwrap()).unwrap();}+ #[test]+ fn a_window_enters_configured_full_screen_only_on_its_first_show() {+ assert!(enters_fullscreen_on_show(true, true, false));+ // Hidden and shown again after the user left full screen: stays out.+ assert!(!enters_fullscreen_on_show(true, false, false));+ // Restored full screen by the window state plugin: nothing to do.+ assert!(!enters_fullscreen_on_show(true, true, true));+ assert!(!enters_fullscreen_on_show(false, true, false));+ }+#[test]fn a_window_taller_than_the_work_area_fits_inside_it() {// The tablet preset on a 1440x900 MacBook Air with the Dock shown.