Skip to content

fix: prevent silent launch window flash#151

Merged
zouyonghe merged 5 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/silent-launch-no-flash
Jul 6, 2026
Merged

fix: prevent silent launch window flash#151
zouyonghe merged 5 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/silent-launch-no-flash

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Start the main Tauri window hidden so silent launch never briefly flashes the app window.
  • Explicitly show the main window during normal startup after desktop settings are loaded.
  • Keep tray labels in sync when silent launch keeps the window hidden.
  • Add regression coverage for the Tauri window visibility config and startup window action.

Why

When launch-at-login and silent launch are both enabled, the main window was created visible first and then hidden in setup, causing a brief app frame flash at login. Starting hidden and showing only for non-silent startup removes that flash.

Verification

  • node --test scripts/prepare-resources/tauri-config.test.mjs
  • cargo test startup_window_action_keeps_window_hidden_for_silent_launch
  • cargo test app_runtime
  • cargo test app_runtime_events
  • cargo fmt -- --check
  • cargo test
  • cargo clippy --all-targets -- -D warnings

Summary by Sourcery

Prevent the main Tauri window from briefly flashing on silent launch by starting it hidden and explicitly controlling its visibility based on startup settings.

Bug Fixes:

  • Ensure the main window remains hidden during silent launch to avoid a brief frame flash at login.

Enhancements:

  • Introduce a shared startup window visibility helper to keep window and tray state consistent across launch modes.
  • Refactor the Linux WebKit workaround into a dedicated, testable module with explicit logging.

Tests:

  • Add a test to verify the main Tauri window is configured to start hidden in tauri.conf.json.
  • Maintain and relocate tests for the Linux WebKit workaround behavior to the new module.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/app_runtime.rs" line_range="12" />
<code_context>
     DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV,
 };

+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum StartupWindowAction {
+    KeepHidden,
</code_context>
<issue_to_address>
**issue (complexity):** Consider inlining the `silent_launch` branching logic or extracting a direct behavior function instead of routing through `StartupWindowAction` and `startup_window_action` to avoid unnecessary indirection.

You can keep the new behavior while removing the extra indirection from `StartupWindowAction` and `startup_window_action`, which currently just re-encode a boolean and add a test for that mapping.

Inline the decision on `silent_launch` and call the appropriate functions directly:

```rust
fn configure_setup(builder: Builder<tauri::Wry>) -> Builder<tauri::Wry> {
    builder.setup(|app| {
        let app_handle = app.handle().clone();
        if let Err(error) = tray::setup::setup_tray(&app_handle) {
            append_startup_log(&format!("failed to initialize tray: {error}"));
        }
        crate::windows_shutdown::install(&app_handle);

        let desktop_settings = app_handle.state::<DesktopSettingsCache>().get();
        if desktop_settings.silent_launch {
            append_startup_log("silent launch enabled, keeping main window hidden");
            tray::labels::update_tray_menu_labels_with_visibility(
                &app_handle,
                DEFAULT_SHELL_LOCALE,
                Some(false),
                append_desktop_log,
            );
        } else {
            window::actions::show_main_window(
                &app_handle,
                DEFAULT_SHELL_LOCALE,
                append_desktop_log,
            );
        }

        startup_task::spawn_startup_task(app_handle.clone(), append_startup_log);
        Ok(())
    })
}
```

With this, you can remove:

```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum StartupWindowAction {
    KeepHidden,
    Show,
}

fn startup_window_action(silent_launch: bool) -> StartupWindowAction {
    if silent_launch {
        StartupWindowAction::KeepHidden
    } else {
        StartupWindowAction::Show
    }
}

#[test]
fn startup_window_action_keeps_window_hidden_for_silent_launch() {
    assert_eq!(startup_window_action(true), StartupWindowAction::KeepHidden);
    assert_eq!(startup_window_action(false), StartupWindowAction::Show);
}
```

If you want to keep the “startup behavior” idea explicit for future extension, you can still avoid the boolean-to-enum adapter and encode it where the behavior is executed:

```rust
fn apply_startup_window_behavior(
    app_handle: &tauri::AppHandle,
    silent_launch: bool,
) {
    if silent_launch {
        append_startup_log("silent launch enabled, keeping main window hidden");
        tray::labels::update_tray_menu_labels_with_visibility(
            app_handle,
            DEFAULT_SHELL_LOCALE,
            Some(false),
            append_desktop_log,
        );
    } else {
        window::actions::show_main_window(
            app_handle,
            DEFAULT_SHELL_LOCALE,
            append_desktop_log,
        );
    }
}

// in configure_setup:
let desktop_settings = app_handle.state::<DesktopSettingsCache>().get();
apply_startup_window_behavior(&app_handle, desktop_settings.silent_launch);
```

This keeps the new behavior, reduces conceptual overhead, and removes the need for a dedicated test that only verifies a boolean-to-enum mapping.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/app_runtime.rs Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request configures the main Tauri window to start hidden by default to prevent a visual flash during silent launches. In app_runtime.rs, a new StartupWindowAction enum is introduced to handle window visibility during startup based on the silent launch setting. If silent launch is enabled, the window remains hidden and tray menu labels are updated; otherwise, the window is shown. Relevant unit and integration tests have been added to verify this behavior. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/app_runtime.rs" line_range="17-18" />
<code_context>
+#[cfg(target_os = "linux")]
 const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY";

+#[cfg(any(target_os = "linux", test))]
 fn should_set_webkit_dmabuf_renderer_env(
     existing_value: Option<&std::ffi::OsStr>,
     wayland_display: Option<&std::ffi::OsStr>,
</code_context>
<issue_to_address>
**issue (bug_risk):** The `test` cfg on this function can cause non-Linux test builds to fail because the Linux-only env constants are not available there.

The function is compiled with `#[cfg(any(target_os = "linux", test))]`, but `WAYLAND_DISPLAY_ENV` (and `WEBKIT_DISABLE_DMABUF_RENDERER_ENV`) are only compiled on `target_os = "linux"`. On non-Linux test builds this function will still compile but reference constants that don’t exist, causing a compile error.

To fix, either:
- Restrict the function to Linux: `#[cfg(target_os = "linux")] fn should_set_webkit_dmabuf_renderer_env(...)` and keep its tests Linux-only, or
- Broaden the constants: `#[cfg(any(target_os = "linux", test))]` on both constants.

The key is to align the `cfg` on the function and its constants to avoid cross-platform test build failures.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/app_runtime.rs Outdated
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In configure_setup, consider centralizing window visibility handling (show/hide plus tray label update) in a single helper so the silent and non-silent branches don’t drift in behavior over time.
  • The #[cfg(target_os = "linux")] annotations for the WebKit-related constants and helper are now scattered; you might simplify maintenance by grouping this Linux-specific logic into a dedicated, cfg-gated module or section.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `configure_setup`, consider centralizing window visibility handling (show/hide plus tray label update) in a single helper so the silent and non-silent branches don’t drift in behavior over time.
- The `#[cfg(target_os = "linux")]` annotations for the WebKit-related constants and helper are now scattered; you might simplify maintenance by grouping this Linux-specific logic into a dedicated, cfg-gated module or section.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/app_runtime.rs" line_range="67-69" />
<code_context>
     })
 }

+fn apply_startup_window_visibility(app_handle: &tauri::AppHandle, silent_launch: bool) {
+    if silent_launch {
+        append_startup_log("silent launch enabled, keeping main window hidden");
+        window::actions::hide_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log);
+    } else {
+        window::actions::show_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log);
+    }
+}
</code_context>
<issue_to_address>
**suggestion:** Consider logging the non-silent startup path as well for more consistent startup diagnostics.

Now that startup window visibility is centralized, it would be useful to add a log entry in the non-silent path as well (e.g., "silent launch disabled, showing main window") to make startup behavior and configuration-related issues easier to diagnose from logs.

```suggestion
fn configure_plugins(builder: Builder<tauri::Wry>) -> Builder<tauri::Wry> {
    builder
        .plugin(tauri_plugin_autostart::init(
    })
 }

 fn apply_startup_window_visibility(app_handle: &tauri::AppHandle, silent_launch: bool) {
     if silent_launch {
         append_startup_log("silent launch enabled, keeping main window hidden");
         window::actions::hide_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log);
     } else {
         append_startup_log("silent launch disabled, showing main window");
         window::actions::show_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log);
     }
 }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/app_runtime.rs
@zouyonghe zouyonghe merged commit 12efb3c into AstrBotDevs:main Jul 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant