From e8b340b67b6ba08867ebbbd1aaaefb7b2040666d Mon Sep 17 00:00:00 2001 From: Jacalz Date: Wed, 7 Aug 2024 14:39:48 +0200 Subject: [PATCH] Fall back to old Gnome prefer-dark if first try fails --- settings/appearance/appearance.go | 5 ++++- settings/appearance/color.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/settings/appearance/appearance.go b/settings/appearance/appearance.go index ed67db4..5b3f703 100644 --- a/settings/appearance/appearance.go +++ b/settings/appearance/appearance.go @@ -1,4 +1,7 @@ // Package appearance is a helper package for reading appearance settings. package appearance -const appearanceNamespace = "org.freedesktop.appearance" +const ( + appearanceNamespace = "org.freedesktop.appearance" + gnomeInterfaceNamespace = "org.gnome.desktop.interface" +) diff --git a/settings/appearance/color.go b/settings/appearance/color.go index b00d494..5b40ac2 100644 --- a/settings/appearance/color.go +++ b/settings/appearance/color.go @@ -23,7 +23,7 @@ const ( func GetColorScheme() (ColorScheme, error) { value, err := settings.ReadOne(appearanceNamespace, "color-scheme") if err != nil { - return NoPreference, err + return getGnomeInterfacePreference() // Fallback if new interface does not exist. } result := value.(uint32) @@ -74,3 +74,17 @@ func GetAccentColor() (*color.RGBA, error) { A: uint8(alpha), }, nil } + +func getGnomeInterfacePreference() (ColorScheme, error) { + value, err := settings.ReadOne(gnomeInterfaceNamespace, "color-scheme") + if err != nil { + return NoPreference, err + } + + result := value.(string) + if result == "prefer-dark" { + return Dark, nil + } + + return NoPreference, nil +}