fix(v3): guard nil AllowDarkModeForWindow to avoid startup panic#5793
fix(v3): guard nil AllowDarkModeForWindow to avoid startup panic#5793roachadam wants to merge 1 commit into
Conversation
…indows 1809 pkg/w32/theme.go loads the undocumented dark-mode uxtheme exports (including AllowDarkModeForWindow) only on Windows build >= 18334, so on older builds such as Windows 10 1809 / Windows Server 2019 (build 17763) the package-level AllowDarkModeForWindow is nil. The Dark and system-dark branches of (*windowsWebviewWindow).run called it unguarded, so a window with Windows.Theme == Dark (or SystemDefault while the OS is in dark mode) panicked on startup with a nil pointer dereference before the window was shown. w32.SetMenuTheme already guards the identical call. Extract the call into an applyDarkMode method, which nil-guards it, and use it from both branches so the window degrades gracefully instead of crashing. Fixes wailsapp#5792
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughWindows dark-theme initialization now uses a nil-safe helper before invoking the optional dark-mode API. Both dark system-default and explicit dark themes avoid startup panics on builds without that API, and the fix is documented in the unreleased changelog. ChangesWindows dark-mode startup fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" 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. Comment |
Description
Fixes a nil-pointer panic on startup when a window uses a Dark (or system-dark) native title bar on Windows builds that do not load the dark-mode
uxthemeAPIs — e.g. Windows 10 1809 / Windows Server 2019 (build 17763).pkg/w32/theme.goloadsAllowDarkModeForWindow(and siblings) only on build>= 18334, so on 1809 the package-levelw32.AllowDarkModeForWindowisnil.(*windowsWebviewWindow).runcalled it unguarded in theDarkand darkSystemDefaultbranches (webview_window_windows.go), whilew32.SetMenuTheme` already guards the identical call.The fix extracts the call into a small applyDarkMode helper that nil-guards it (mirroring the guard w32.SetMenuTheme already uses) and calls it from both branches, so the window degrades gracefully (default title bar) instead of panicking. No behavior change on builds that load the procs; no new dependencies.
Fixes #5792
Type of change
How Has This Been Tested?
Built a minimal v3 app with
Windows: application.WindowsWindow{Theme: application.Dark}and ran it on Windows Server 2019 (build 17763): before, it panicked on startup; after, the window opens normally.Reproduction repo: https://github.com/roachadam/wails-1809-dark-title-bar-poc.
Test Configuration
Wails is not installed on this VM, so there is no wails3 doctor output. Reproduced with a minimal app instead: my existing app (built on v3.0.0-alpha.68) failed to start on Windows Server 2019 Standard Evaluation (build 17763). I reproduced the panic in isolation using the POC above built against the tagged v3.0.0-alpha2.117 release, then rebuilt the POC against this fix and confirmed the window opens normally.
Checklist:
website/src/pages/changelog.mdxwith details of this PR (v3 changelog entries are added automatically)Summary by CodeRabbit