Skip to content

Commit

Permalink
Merge pull request #4800 from andydotxyz/fix/portalwait
Browse files Browse the repository at this point in the history
Fix timeout if the portal DBus is not present
  • Loading branch information
andydotxyz authored May 6, 2024
2 parents 7336b07 + 23c12a3 commit d247b0e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/app_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"fyne.io/fyne/v2/theme"
)

var currentVariant atomic.Uint64

func defaultVariant() fyne.ThemeVariant {
return findFreedestktopColorScheme()
return fyne.ThemeVariant(currentVariant.Load())
}

func (a *fyneApp) OpenURL(url *url.URL) error {
Expand All @@ -39,7 +41,7 @@ func (a *fyneApp) OpenURL(url *url.URL) error {
}

// fetch color variant from dbus portal desktop settings.
func findFreedestktopColorScheme() fyne.ThemeVariant {
func findFreedesktopColorScheme() fyne.ThemeVariant {
colourScheme, err := appearance.GetColorScheme()
if err != nil {
return theme.VariantDark
Expand Down Expand Up @@ -119,9 +121,15 @@ func rootConfigDir() string {
}

func watchTheme() {
go portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
fyne.CurrentApp().Settings().(*settings).setupTheme()
}
})
go func() {
// with portal this may not be immediate, so we update a cache instead
currentVariant.Store(uint64(findFreedesktopColorScheme()))

portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
currentVariant.Store(uint64(findFreedesktopColorScheme()))
fyne.CurrentApp().Settings().(*settings).setupTheme()
}
})
}()
}

0 comments on commit d247b0e

Please sign in to comment.