Skip to content

Commit

Permalink
undo temp fix for Linux color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Aug 19, 2024
1 parent 6204543 commit 6c9b9dc
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions app/app_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/rymdport/portal/notification"
"github.com/rymdport/portal/openuri"
portalSettings "github.com/rymdport/portal/settings"
"github.com/rymdport/portal/settings/appearance"

"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
Expand All @@ -36,43 +37,24 @@ func (a *fyneApp) OpenURL(url *url.URL) error {

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
dbusConn, err := dbus.SessionBus()
colorScheme, err := appearance.GetColorScheme()
if err != nil {
fyne.LogError("Unable to connect to session D-Bus", err)
return theme.VariantDark
}

dbusObj := dbusConn.Object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
call := dbusObj.Call(
"org.freedesktop.portal.Settings.Read",
dbus.FlagNoAutoStart,
"org.freedesktop.appearance",
"color-scheme",
)
if call.Err != nil {
// many desktops don't have this exported yet
return theme.VariantDark
}

var value uint8
if err = call.Store(&value); err != nil {
fyne.LogError("failed to read theme variant from D-Bus", err)
return theme.VariantDark
}
return colorSchemeToThemeVariant(colorScheme)
}

// See: https://github.com/flatpak/xdg-desktop-portal/blob/1.16.0/data/org.freedesktop.impl.portal.Settings.xml#L32-L46
// 0: No preference
// 1: Prefer dark appearance
// 2: Prefer light appearance
switch value {
case 2:
func colorSchemeToThemeVariant(colorScheme appearance.ColorScheme) fyne.ThemeVariant {
switch colorScheme {
case appearance.Light:
return theme.VariantLight
case 1:
case appearance.Dark:
return theme.VariantDark
default:
// Default to light theme to support Gnome's default see https://github.com/fyne-io/fyne/pull/3561
return theme.VariantLight
}

// Default to light theme to support Gnome's default see https://github.com/fyne-io/fyne/pull/3561
return theme.VariantLight
}

func (a *fyneApp) SendNotification(n *fyne.Notification) {
Expand Down Expand Up @@ -139,14 +121,14 @@ func rootConfigDir() string {

func watchTheme() {
go func() {
// with portal this may not be immediate, so we update a cache instead
// Theme lookup hangs on some desktops. Update theme variant cache from within goroutine.
internalapp.CurrentVariant.Store(uint64(findFreedesktopColorScheme()))
// ensure initial variant setting is applied at startup
fyne.CurrentApp().Settings().(*settings).setupTheme()

portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
internalapp.CurrentVariant.Store(uint64(findFreedesktopColorScheme()))
themeVariant := colorSchemeToThemeVariant(appearance.ColorScheme(changed.Value.(uint32)))
internalapp.CurrentVariant.Store(uint64(themeVariant))
fyne.CurrentApp().Settings().(*settings).setupTheme()
}
})
Expand Down

0 comments on commit 6c9b9dc

Please sign in to comment.