detached 86ddc8f

fix(webkit): prevent panic on non-GNOME systems in dark mode detection

commit
86ddc8fcb01115b7c142dbc612f4edb7aa38ff3c
author
bnema · · 2025-10-23 21:11 UTC
committer
bnema · · 2025-10-23 21:14 UTC
parent
47d05a1
signature
GPG Unverified2B82207D370127A0 The key is unknown
1 file · +17 -7
M pkg/webkit/helpers.go +17 -7
@@ -241,16 +241,26 @@ func WidgetAllocation(w gtk.Widgetter) (x, y, width, height int) {
241241 // PrefersDarkTheme checks if the system prefers dark theme
242242 func PrefersDarkTheme() bool {
243243 // First try to read GNOME's color-scheme setting (GTK4+)
244- if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {
245- colorScheme := gnomeSettings.String("color-scheme")
246- if colorScheme == "prefer-dark" {
247- return true
248- }
249- if colorScheme == "prefer-light" {
250- return false
244+ // Check if the schema exists before attempting to create GSettings object
245+ // to avoid panics on non-GNOME systems (e.g., Sway, Hyprland, etc.)
246+ var colorScheme string
247+ schemaSource := gio.SettingsSchemaSourceGetDefault()
248+ if schemaSource != nil {
249+ schema := schemaSource.Lookup("org.gnome.desktop.interface", true)
250+ if schema != nil {
251+ if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {
252+ colorScheme = gnomeSettings.String("color-scheme")
253+ }
251254 }
252255 }
253256
257+ switch colorScheme {
258+ case "prefer-dark":
259+ return true
260+ case "prefer-light":
261+ return false
262+ }
263+
254264 // Fallback to GTK's application-level preference
255265 settings := gtk.SettingsGetDefault()
256266 if settings != nil {
@@ -241,16 +241,26 @@ func WidgetAllocation(w gtk.Widgetter) (x, y, width, height int) {
241 // PrefersDarkTheme checks if the system prefers dark theme241 // PrefersDarkTheme checks if the system prefers dark theme
242 func PrefersDarkTheme() bool {242 func PrefersDarkTheme() bool {
243 // First try to read GNOME's color-scheme setting (GTK4+)243 // First try to read GNOME's color-scheme setting (GTK4+)
244- if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {244+ // Check if the schema exists before attempting to create GSettings object
245- colorScheme := gnomeSettings.String("color-scheme")245+ // to avoid panics on non-GNOME systems (e.g., Sway, Hyprland, etc.)
246- if colorScheme == "prefer-dark" {246+ var colorScheme string
247- return true247+ schemaSource := gio.SettingsSchemaSourceGetDefault()
248- }248+ if schemaSource != nil {
249- if colorScheme == "prefer-light" {249+ schema := schemaSource.Lookup("org.gnome.desktop.interface", true)
250- return false250+ if schema != nil {
251+ if gnomeSettings := gio.NewSettings("org.gnome.desktop.interface"); gnomeSettings != nil {
252+ colorScheme = gnomeSettings.String("color-scheme")
253+ }
251 }254 }
252 }255 }
253 256
257+ switch colorScheme {
258+ case "prefer-dark":
259+ return true
260+ case "prefer-light":
261+ return false
262+ }
263+
254 // Fallback to GTK's application-level preference264 // Fallback to GTK's application-level preference
255 settings := gtk.SettingsGetDefault()265 settings := gtk.SettingsGetDefault()
256 if settings != nil {266 if settings != 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