Skip to content

[V3] Fix Window Affinity weirdness - #4600

Merged
leaanthony merged 4 commits into
v3-alphafrom
v3-alpha-bugfix/windows-affinity
Sep 27, 2025
Merged

leaanthony merged 4 commits into
v3-alphafrom
v3-alpha-bugfix/windows-affinity

Conversation

@leaanthony

@leaanthony leaanthony commented Sep 25, 2025 •

Copy link
Copy Markdown
Member

Description

Fixes multiple issues introduced from the Content protection PR.

Fixes #4574 & #4498

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Windows: Reduced window flicker on startup.
    • Windows: Fixed hidden windows appearing unexpectedly.
    • Windows: Improved reliability of content protection when showing windows.
  • Documentation

@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Sep 25, 2025
@coderabbitai

coderabbitai Bot commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Replaces a Wayland changelog entry with a Windows fix entry and implements stateful Windows content-protection handling: tracks whether protection is applied, defers applying SetWindowDisplayAffinity until the window is visible, exposes applyDisplayAffinity wrapper with logging, and updates protection on show() and WM_SHOWWINDOW.

Changes

Cohort / File(s) Summary
Changelog
v3/UNRELEASED_CHANGELOG.md
Replaces a Wayland fixed entry with a new “Fixed” entry referencing PR #4600 about Windows window flicker at startup and hidden windows being shown incorrectly.
Windows content protection flow
v3/pkg/application/webview_window_windows.go
Adds contentProtectionApplied field; introduces updateContentProtection() and applyDisplayAffinity(); setContentProtection() now records desired state and delegates to updateContentProtection(); show() and WndProc (WM_SHOWWINDOW) call updateContentProtection(); defers applying affinity until window is visible; logs affinity failures and returns success bool.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor App
    participant WW as WindowsWebviewWindow
    participant Wnd as WndProc
    participant CP as updateContentProtection()
    participant SDA as applyDisplayAffinity()
    participant OS as Windows API

    App->>WW: show()
    WW->>WW: mark shown/requested
    WW->>CP: updateContentProtection()
    CP->>CP: ensure hwnd!=0 && visible?
    alt Visible
        CP->>SDA: applyDisplayAffinity(ON/OFF)
        SDA->>OS: SetWindowDisplayAffinity(affinity)
        OS-->>SDA: success/failure
        SDA-->>CP: success bool
        CP->>WW: set contentProtectionApplied
    else Not visible
        CP-->>WW: defer (do not change affinity)
    end

    Note over Wnd,CP: runtime show event
    OS-->>Wnd: WM_SHOWWINDOW (shown)
    Wnd->>CP: updateContentProtection()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I’m a rabbit in the code, I hop and pry,
No more flicker in the corner of your eye.
Affinity waits until the stage is bright,
Hidden stays hidden until the show’s just right.
I nibble bugs and leave a smoother start—🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description identifies the linked issues and classifies the change as a bug fix, but it omits key template requirements such as detailed motivation and context, reproduction steps and environment details including wails doctor output, and lacks confirmation of changelog, documentation, tests, and code review checklist items. Please complete the description template by adding motivation and context, reproduction instructions with environment specifics and wails doctor output, and update the checklist to reflect changelog updates, documentation changes, self-review notes, and any new tests added.
Linked Issues Check ❓ Inconclusive The code changes address the flicker behavior in issue #4574 by deferring display affinity until the window is visible, but the objectives and validation criteria for issue #4498 are not provided, preventing confirmation that it has been resolved. Provide the details or acceptance criteria for issue #4498 and clarify how the implemented changes satisfy those requirements so the compliance check can be completed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[V3] Fix Window Affinity weirdness” succinctly and accurately characterizes the primary change in this pull request, which refines the display affinity logic on Windows to eliminate flicker and hidden window visibility issues, making it clear to reviewers what the main fix entails.
Out of Scope Changes Check ✅ Passed All modifications are confined to the Windows webview window content protection logic and the changelog entry, which directly relate to the linked issues and introduce no unrelated or extraneous changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v3-alpha-bugfix/windows-affinity

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be842ca and 77a1cae.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Analyze (go)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
v3/UNRELEASED_CHANGELOG.md (1)

26-26: Changelog entry looks good

Thanks for documenting the Windows flicker fix with a direct PR reference.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony
leaanthony changed the base branch from master to v3-alpha September 25, 2025 05:44
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Sep 25, 2025
@dosubot dosubot Bot added Bug Something isn't working v3 labels Sep 25, 2025
@dosubot

dosubot Bot commented Sep 25, 2025

Copy link
Copy Markdown

Related Documentation

Checked 1 published document(s). No updates required.

You have 2 draft document(s). Publish docs to keep them always up-to-date

How did I do? Any feedback?  Join Discord

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 25, 2025
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 25, 2025 •

Copy link
Copy Markdown

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: b6273f2
Status:🚫  Build failed.

View logs

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
v3/pkg/application/webview_window_windows.go (1)

2455-2477: Use contentProtectionApplied to short-circuit redundant affinity updates.

Right now we call SetWindowDisplayAffinity on every show() and every WM_SHOWWINDOW, even if we already have the correct state. That’s unnecessary work and can emit duplicate warnings when the native call fails. Since we’re now tracking the applied state, we can bail out early once the desired and applied states match.

Apply this tweak inside updateContentProtection():

 func (w *windowsWebviewWindow) updateContentProtection() {
 	if w.hwnd == 0 {
 		return
 	}

 	if !w.isVisible() {
 		// Defer updates until the window is visible to avoid affinity glitches.
 		return
 	}

 	desired := w.parent.options.ContentProtectionEnabled
+
+	if desired == w.contentProtectionApplied {
+		return
+	}

 	if desired {
 		if w.applyDisplayAffinity(w32.WDA_EXCLUDEFROMCAPTURE) {
 			w.contentProtectionApplied = true
 		}
 		return
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 386034e and be842ca.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)
  • v3/pkg/application/webview_window_windows.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
v3/pkg/application/webview_window_windows.go (1)
v3/pkg/w32/wda.go (3)
  • WDA_EXCLUDEFROMCAPTURE (8-8)
  • WDA_NONE (6-6)
  • SetWindowDisplayAffinity (11-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
🔇 Additional comments (3)
v3/UNRELEASED_CHANGELOG.md (1)

24-26: Changelog entry LGTM.

Thanks for documenting the Windows startup flicker fix so clearly.

v3/pkg/application/webview_window_windows.go (2)

1093-1096: Good call reapplying after showing.

Triggering the affinity update immediately after ShowWindow ensures the window is already visible before we touch display affinity, which is exactly what the flicker fix needs.


1438-1442: WM_SHOWWINDOW hook makes sense.

Catching the show message guarantees that any external visibility changes re-run the content-protection sync, so the native state can’t drift.

@semgrep-code-wailsapp

Copy link
Copy Markdown

Semgrep found 1 ssc-cee3e6d5-d7c8-4c35-9815-076aa1ebfd49 finding:

  • v3/examples/dev/frontend/package-lock.json

Risk: Affected versions of rollup are vulnerable to Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').

Manual Review Advice: A vulnerability from this advisory is reachable if you use Rollup to bundle JavaScript with import.meta.url and the output format is set to cjs, umd, or iife formats, while allowing users to inject scriptless HTML elements with unsanitized name attributes

Fix: Upgrade this library to at least version 3.29.5 at wails/v3/examples/dev/frontend/package-lock.json:569.

Reference(s): GHSA-gcx4-mw62-g8wm, CVE-2024-47068

@sonarqubecloud

Copy link
Copy Markdown

@leaanthony
leaanthony merged commit 751e4af into v3-alpha Sep 27, 2025
55 of 56 checks passed
@leaanthony
leaanthony deleted the v3-alpha-bugfix/windows-affinity branch September 27, 2025 02:25
Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
* Fix window affinity weirdness

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation size:M This PR changes 30-99 lines, ignoring generated files. v3 Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3] When the program starts, the Wails window initially appears in the top-left corner, flickers briefly, and then moves to the center of the screen.

2 participants