@@ -6,13 +6,15 @@ use std::sync::{
66 atomic:: { AtomicBool , Ordering } ,
77 Arc ,
88} ;
9- use tauri:: { webview:: PageLoadEvent , Manager , WebviewWindow } ;
9+ use tauri:: { webview:: PageLoadEvent , Manager , Url , WebviewWindow } ;
1010use tauri_plugin_window_state:: Builder as WindowStatePlugin ;
1111use tauri_plugin_window_state:: StateFlags ;
1212
1313#[ cfg( target_os = "macos" ) ]
1414use std:: time:: Duration ;
1515
16+ // Fallback when PageLoadEvent::Finished never arrives (offline / stalled).
17+ // Deliberately longer than a paint tick so the normal path can win first.
1618const STARTUP_WINDOW_FALLBACK_DELAY : u64 = 3_000 ;
1719#[ cfg( target_os = "linux" ) ]
1820const PAKE_LINUX_WEBKIT_SAFE_MODE : & str = "PAKE_LINUX_WEBKIT_SAFE_MODE" ;
@@ -33,6 +35,13 @@ use app::{
3335} ;
3436use util:: get_pake_config;
3537
38+ /// Placeholder documents used before the real target URL navigates (e.g. macOS
39+ /// cert-bypass starts on about:blank). Revealing on these would reintroduce the
40+ /// blank-window flash the page-load gate is meant to prevent.
41+ fn is_placeholder_startup_url ( url : & Url ) -> bool {
42+ url. scheme ( ) . eq_ignore_ascii_case ( "about" )
43+ }
44+
3645fn reveal_startup_window ( window : WebviewWindow , init_fullscreen : bool , revealed : & Arc < AtomicBool > ) {
3746 if revealed. swap ( true , Ordering :: AcqRel ) {
3847 return ;
@@ -221,13 +230,26 @@ pub fn run_app() {
221230 ) ) ;
222231 }
223232
233+ // Reveal the main window after the first real document finishes loading so
234+ // slow WKWebView cold starts do not expose an empty but interactive shell.
235+ // start_to_tray keeps the window hidden for the whole session until the user
236+ // opens it from the tray / shortcut.
224237 if !start_to_tray {
225238 let page_load_revealed = startup_window_revealed. clone ( ) ;
226239 app_builder = app_builder. on_page_load ( move |webview, payload| {
227- if webview. label ( ) == "pake" && matches ! ( payload. event( ) , PageLoadEvent :: Finished ) {
228- if let Some ( window) = webview. app_handle ( ) . get_webview_window ( "pake" ) {
229- reveal_startup_window ( window, init_fullscreen, & page_load_revealed) ;
230- }
240+ if webview. label ( ) != "pake" {
241+ return ;
242+ }
243+ if !matches ! ( payload. event( ) , PageLoadEvent :: Finished ) {
244+ return ;
245+ }
246+ // Skip about:blank (and other about: placeholders) used by the macOS
247+ // cert-bypass path before the real target URL navigates.
248+ if is_placeholder_startup_url ( payload. url ( ) ) {
249+ return ;
250+ }
251+ if let Some ( window) = webview. app_handle ( ) . get_webview_window ( "pake" ) {
252+ reveal_startup_window ( window, init_fullscreen, & page_load_revealed) ;
231253 }
232254 } ) ;
233255 }
@@ -352,6 +374,19 @@ pub fn run() {
352374mod tests {
353375 use super :: * ;
354376
377+ #[ test]
378+ fn placeholder_startup_urls_cover_about_blank ( ) {
379+ let blank: Url = "about:blank" . parse ( ) . unwrap ( ) ;
380+ let srcdoc: Url = "about:srcdoc" . parse ( ) . unwrap ( ) ;
381+ let https: Url = "https://github.com/" . parse ( ) . unwrap ( ) ;
382+ let tauri: Url = "tauri://localhost/" . parse ( ) . unwrap ( ) ;
383+
384+ assert ! ( is_placeholder_startup_url( & blank) ) ;
385+ assert ! ( is_placeholder_startup_url( & srcdoc) ) ;
386+ assert ! ( !is_placeholder_startup_url( & https) ) ;
387+ assert ! ( !is_placeholder_startup_url( & tauri) ) ;
388+ }
389+
355390 #[ test]
356391 fn linux_webkit_safe_mode_stays_on_by_default ( ) {
357392 assert ! ( should_enable_linux_webkit_safe_mode_from_values(
0 commit comments