Skip to content

Fix white flash on restore-from-minimize by toggling WebView2 visibility #1014

Description

@ashish01-dev

Problem

The main UI window (windhawk-ui.exe, the Tauri/WebView2 window) briefly
flashes white when it's restored from the taskbar after having been
minimized. It doesn't happen on first launch (that path already builds
the window hidden, themed, and sized before showing it), only on the
minimize → restore cycle, and independent of which tab/page was open.

Root cause

WebView2 discards its compositor surface while the host window is
minimized (to save memory), and on some machines the first frame it
repaints after being restored is blank/white until something else (a
resize, a click) forces a second paint. This is a known WebView2
behavior, and Microsoft's own guidance is that the host app must
manually toggle ICoreWebView2Controller.IsVisible to false right as
the window minimizes and back to true right as it's restored
(handling SIZE_MINIMIZED/SIZE_RESTORED via WM_SIZE in a plain
Win32 host).

lib.rs's on_window_event handler was tracking Resized only for
window-geometry persistence. On Windows, a minimize is reported as
Resized(0, 0) and the restore as a second Resized with the real
size back (there's no dedicated Minimized/Restored variant in
Tauri's WindowEvent), but nothing reacted to that transition to give
WebView2 the visibility toggle it needs.

Fix

  • shell.rs: add set_webview_visible(), a small helper that reaches
    the WebView2 controller (the same way the existing shortcut/context-menu/
    theme helpers in this file already do) and calls SetIsVisible.

  • lib.rs: in the existing Resized branch of on_window_event, detect
    the (0, 0) minimize signal and the following real-size restore
    signal, and call set_webview_visible(false) / set_webview_visible(true)
    at exactly those transitions.

No behavior changes on first launch, resizing, or maximizing - only the
minimize/restore transition is affected.

Testing

  • Manual: launch Windhawk, minimize from the taskbar, restore - no more
    white flash before the UI repaints, across several repeated cycles.
  • Sanity-checked normal resize/maximize/move still persist window state
    correctly (unaffected by this change, since it only adds to the
    existing Resized branch).

References

CHECK THE UPDATED FILES HERE https://gofile.io/d/dWuN8O

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginfo-neededFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions