detached 0060bbf

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.
44
55 ## [Unreleased]
66
7+### Fixed
8+- Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation
9+
710 ## [0.12.0] - 2025-10-16
811
912 ### 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-1610 ## [0.12.0] - 2025-10-16
8 11
9 ### Added12 ### Added
M pkg/webkit/webview.go +11 -0
@@ -9,6 +9,7 @@ import (
99 "sync/atomic"
1010
1111 webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6"
12+ "github.com/diamondburned/gotk4/pkg/gdk/v4"
1213 "github.com/diamondburned/gotk4/pkg/gtk/v4"
1314 )
1415
@@ -76,6 +77,16 @@ func NewWebView(cfg *Config) (*WebView, error) {
7677 return nil, ErrWebViewNotInitialized
7778 }
7879
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+
7990 // Verify the WebView is using the persistent session
8091 viewSession := wkView.NetworkSession()
8192 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, ErrWebViewNotInitialized77 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 session90 // Verify the WebView is using the persistent session
80 viewSession := wkView.NetworkSession()91 viewSession := wkView.NetworkSession()
81 if viewSession == nil {92 if viewSession == nil {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close