fix: eliminate theme flash on startup by respecting user preference
- Set WebView background color based on GTK theme preference - Dark theme users get #1c1c1c background - Light theme users get #f5f5f5 background - Prevents white flash on dark theme and black flash on light theme
- commit
- 0060bbf0a0d3b123155be58181478aa0f10dca19
- author
- bnema · · 2025-10-17 04:17 UTC
- parent
- 14227da
- signature
- unsigned
2 files · +14 -0
M CHANGELOG.md +3 -0
| @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. | |||
| 4 | 4 | ||
| 5 | 5 | ## [Unreleased] | |
| 6 | 6 | ||
| 7 | + | ### Fixed | |
| 8 | + | - Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation | |
| 9 | + | ||
| 7 | 10 | ## [0.12.0] - 2025-10-16 | |
| 8 | 11 | ||
| 9 | 12 | ### Added | |
| @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. | |||||
| 4 | 4 | ||||
| 5 | ## [Unreleased] | 5 | ## [Unreleased] | ||
| 6 | 6 | ||||
| 7 | + | ### Fixed | |||
| 8 | + | - Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation | |||
| 9 | + | ||||
| 7 | ## [0.12.0] - 2025-10-16 | 10 | ## [0.12.0] - 2025-10-16 | ||
| 8 | 11 | ||||
| 9 | ### Added | 12 | ### Added | ||
M pkg/webkit/webview.go +11 -0
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | "sync/atomic" | |
| 10 | 10 | ||
| 11 | 11 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 12 | + | "github.com/diamondburned/gotk4/pkg/gdk/v4" | |
| 12 | 13 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| @@ -76,6 +77,16 @@ func NewWebView(cfg *Config) (*WebView, error) { | |||
| 76 | 77 | return nil, ErrWebViewNotInitialized | |
| 77 | 78 | } | |
| 78 | 79 | ||
| 80 | + | // Set background color based on user's theme preference to prevent white/black flash | |
| 81 | + | // This must be done before any content loads | |
| 82 | + | var bg gdk.RGBA | |
| 83 | + | if PrefersDarkTheme() { | |
| 84 | + | bg = gdk.NewRGBA(0.11, 0.11, 0.11, 1.0) // #1c1c1c - dark background | |
| 85 | + | } else { | |
| 86 | + | bg = gdk.NewRGBA(0.96, 0.96, 0.96, 1.0) // #f5f5f5 - light background | |
| 87 | + | } | |
| 88 | + | wkView.SetBackgroundColor(&bg) | |
| 89 | + | ||
| 79 | 90 | // Verify the WebView is using the persistent session | |
| 80 | 91 | viewSession := wkView.NetworkSession() | |
| 81 | 92 | if viewSession == nil { | |
| @@ -9,6 +9,7 @@ import ( | |||||
| 9 | "sync/atomic" | 9 | "sync/atomic" | ||
| 10 | 10 | ||||
| 11 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | 11 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | ||
| 12 | + | "github.com/diamondburned/gotk4/pkg/gdk/v4" | |||
| 12 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | 13 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | ||
| 13 | ) | 14 | ) | ||
| 14 | 15 | ||||
| @@ -76,6 +77,16 @@ func NewWebView(cfg *Config) (*WebView, error) { | |||||
| 76 | return nil, ErrWebViewNotInitialized | 77 | return nil, ErrWebViewNotInitialized | ||
| 77 | } | 78 | } | ||
| 78 | 79 | ||||
| 80 | + | // Set background color based on user's theme preference to prevent white/black flash | |||
| 81 | + | // This must be done before any content loads | |||
| 82 | + | var bg gdk.RGBA | |||
| 83 | + | if PrefersDarkTheme() { | |||
| 84 | + | bg = gdk.NewRGBA(0.11, 0.11, 0.11, 1.0) // #1c1c1c - dark background | |||
| 85 | + | } else { | |||
| 86 | + | bg = gdk.NewRGBA(0.96, 0.96, 0.96, 1.0) // #f5f5f5 - light background | |||
| 87 | + | } | |||
| 88 | + | wkView.SetBackgroundColor(&bg) | |||
| 89 | + | ||||
| 79 | // Verify the WebView is using the persistent session | 90 | // Verify the WebView is using the persistent session | ||
| 80 | viewSession := wkView.NetworkSession() | 91 | viewSession := wkView.NetworkSession() | ||
| 81 | if viewSession == nil { | 92 | if viewSession == nil { | ||