Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout if the portal DBus is not present #4800

Merged
merged 5 commits into from
May 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = theme.VariantDark

func defaultVariant() fyne.ThemeVariant {
return findFreedestktopColorScheme()
return currentVariant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think this might be introducing a race condition given that it is modified in a different goroutine? Might be worth using something like an atomic.Pointer or a lock?

}

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 = findFreedesktopColorScheme()

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