Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: reveal startup window after initial page load

Nora5d6841711d7c
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 76435c7b..96f1f1f7 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -2,14 +2,18 @@
mod app;
mod util;
-use tauri::Manager;
+use std::sync::{
+ atomic::{AtomicBool, Ordering},
+ Arc,
+};
+use tauri::{webview::PageLoadEvent, Manager, WebviewWindow};
use tauri_plugin_window_state::Builder as WindowStatePlugin;
use tauri_plugin_window_state::StateFlags;
#[cfg(target_os = "macos")]
use std::time::Duration;
-const WINDOW_SHOW_DELAY: u64 = 50;
+const STARTUP_WINDOW_FALLBACK_DELAY: u64 = 3_000;
#[cfg(target_os = "linux")]
const PAKE_LINUX_WEBKIT_SAFE_MODE: &str = "PAKE_LINUX_WEBKIT_SAFE_MODE";
#[cfg(target_os = "linux")]
@@ -29,6 +33,36 @@ use app::{
};
use util::get_pake_config;
+fn reveal_startup_window(window: WebviewWindow, init_fullscreen: bool, revealed: &Arc<AtomicBool>) {
+ if revealed.swap(true, Ordering::AcqRel) {
+ return;
+ }
+
+ tauri::async_runtime::spawn(async move {
+ let _ = window.show();
+ reapply_window_icon(&window);
+
+ // Fixed: Linux fullscreen issue with virtual keyboard
+ #[cfg(target_os = "linux")]
+ {
+ if init_fullscreen {
+ let _ = window.set_fullscreen(true);
+ // Ensure webview maintains focus for input after fullscreen
+ let _ = window.set_focus();
+ } else {
+ // Fix: Ubuntu 24.04/GNOME window buttons non-functional until resize (#1122)
+ // The window manager needs time to process the MapWindow event before
+ // accepting focus requests. Without this, decorations remain non-interactive.
+ tokio::time::sleep(tokio::time::Duration::from_millis(30)).await;
+ let _ = window.set_focus();
+ }
+ }
+
+ #[cfg(not(target_os = "linux"))]
+ let _ = init_fullscreen;
+ });
+}
+
#[cfg(any(target_os = "linux", test))]
fn is_disabled_env_value(value: &str) -> bool {
matches!(
@@ -149,6 +183,7 @@ pub fn run_app() {
let multi_instance = pake_config.multi_instance;
let multi_window = pake_config.multi_window;
let _enable_find = pake_config.windows[0].enable_find;
+ let startup_window_revealed = Arc::new(AtomicBool::new(false));
let window_state_plugin = WindowStatePlugin::default()
.with_state_flags(if init_fullscreen {
@@ -186,6 +221,17 @@ pub fn run_app() {
));
}
+ if !start_to_tray {
+ let page_load_revealed = startup_window_revealed.clone();
+ app_builder = app_builder.on_page_load(move |webview, payload| {
+ if webview.label() == "pake" && matches!(payload.event(), PageLoadEvent::Finished) {
+ if let Some(window) = webview.app_handle().get_webview_window("pake") {
+ reveal_startup_window(window, init_fullscreen, &page_load_revealed);
+ }
+ }
+ });
+ }
+
app_builder
.invoke_handler(tauri::generate_handler![
download_file,
@@ -226,29 +272,17 @@ pub fn run_app() {
set_global_shortcut(app.app_handle(), activation_shortcut, init_fullscreen)?;
// Show window after state restoration to prevent position flashing
- // Unless start_to_tray is enabled, then keep it hidden
+ // once its first page finishes. A fallback keeps offline or stalled
+ // pages reachable without exposing a blank webview during normal startup.
if !start_to_tray {
let window_clone = window.clone();
+ let fallback_revealed = startup_window_revealed.clone();
tauri::async_runtime::spawn(async move {
- tokio::time::sleep(tokio::time::Duration::from_millis(WINDOW_SHOW_DELAY)).await;
- let _ = window_clone.show();
- reapply_window_icon(&window_clone);
-
- // Fixed: Linux fullscreen issue with virtual keyboard
- #[cfg(target_os = "linux")]
- {
- if init_fullscreen {
- let _ = window_clone.set_fullscreen(true);
- // Ensure webview maintains focus for input after fullscreen
- let _ = window_clone.set_focus();
- } else {
- // Fix: Ubuntu 24.04/GNOME window buttons non-functional until resize (#1122)
- // The window manager needs time to process the MapWindow event before
- // accepting focus requests. Without this, decorations remain non-interactive.
- tokio::time::sleep(tokio::time::Duration::from_millis(30)).await;
- let _ = window_clone.set_focus();
- }
- }
+ tokio::time::sleep(tokio::time::Duration::from_millis(
+ STARTUP_WINDOW_FALLBACK_DELAY,
+ ))
+ .await;
+ reveal_startup_window(window_clone, init_fullscreen, &fallback_revealed);
});
}
diff --git a/tests/unit/startup-window-reveal.test.ts b/tests/unit/startup-window-reveal.test.ts
new file mode 100644
index 00000000..80a1e336
--- /dev/null
+++ b/tests/unit/startup-window-reveal.test.ts
@@ -0,0 +1,21 @@
+import fs from 'node:fs';
+import path from 'node:path';
+import { describe, expect, it } from 'vitest';
+
+const libSource = fs.readFileSync(
+ path.join(process.cwd(), 'src-tauri', 'src', 'lib.rs'),
+ 'utf8',
+);
+
+describe('startup window reveal', () => {
+ it('waits for the initial page to finish instead of exposing a blank webview', () => {
+ expect(libSource).toContain('.on_page_load(');
+ expect(libSource).toContain('PageLoadEvent::Finished');
+ expect(libSource).toContain('revealed.swap(true');
+ expect(libSource).toContain('STARTUP_WINDOW_FALLBACK_DELAY');
+ expect(libSource).toMatch(
+ /if !start_to_tray \{[\s\S]*?app_builder = app_builder\.on_page_load/,
+ );
+ expect(libSource).not.toContain('WINDOW_SHOW_DELAY');
+ });
+});