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

Light/Dark mode detection no longer works on Ubuntu with Fyne 2.5 #5029

Closed
2 tasks done
ErikKalkoken opened this issue Jul 25, 2024 · 12 comments
Closed
2 tasks done

Light/Dark mode detection no longer works on Ubuntu with Fyne 2.5 #5029

ErikKalkoken opened this issue Jul 25, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@ErikKalkoken
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Fyne apps normally start in light or dark mode, depending on the current preferences of the OS.

Since Fyne 2.5 this does no longer seam to work on Ubuntu. I tested this with the demo app and it consistently starts in dark mode, even though the OS is set to light mode (see screenshot).

However, if I compile an app with Fyne 2.4.5 it correctly runs in light mode, so this looks to me like a new bug that was introduced with 2.5.

I also tested this on Windows 10, and there the theme detection still works with Fyne 2.5 as expected.

How to reproduce

  1. Chose "Light" style under Settings/Appearance
  2. Start the Fyne demo app
  3. The app runs in dark mode

Screenshots

Screenshot from 2024-07-25 14-35-04

Example code

N/A

Fyne version

2.5.0

Go compiler version

1.22.4

Operating system and version

Ubuntu 22.04.4 LTS

Additional Information

No response

@ErikKalkoken ErikKalkoken added the unverified A bug that has been reported but not verified label Jul 25, 2024
@dweymouth
Copy link
Contributor

Hmm I had this reported in my app too but I hadn't found the time to look into it.

@dweymouth dweymouth added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Jul 25, 2024
@dweymouth dweymouth added this to the E fixes (v2.5.x) milestone Jul 25, 2024
@dweymouth
Copy link
Contributor

It may have been a bug introduced in moving to the rymdport/portal package - see difference between

https://github.com/fyne-io/fyne/blob/release/v2.4.x/app/app_xdg.go#L37

and

https://github.com/fyne-io/fyne/blob/release/v2.5.x/app/app_xdg.go#L39

@Jacalz any ideas?

@dweymouth
Copy link
Contributor

The watchTheme code changed between v2.4 and v2.5 too:

https://github.com/fyne-io/fyne/blob/release/v2.4.x/app/app_xdg.go#L174

https://github.com/fyne-io/fyne/blob/release/v2.5.x/app/app_xdg.go#L118

@ErikKalkoken if you're able to test that switching back to the v2.4.x implementations restores the correct behavior on startup and detecting the theme switch while the app is running, we could probably get a PR merged to fix this in the meantime while waiting on issues with rymdport/portal to be resolved

@ErikKalkoken
Copy link
Contributor Author

yes, can confirm it works correctly both on startup and while the app is running for 2.4.5 on Ubuntu.

The live theme switching is shown in the below video with shows the same simple Fyne app, once compiled with 2.4.5 and once with 2.5:
Screencast from 25.07.2024 18:03:28.webm

Here is the app:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Fyne 2.5.0")

	w.SetContent(widget.NewLabel("Hello World!"))
	w.Resize(fyne.Size{Width: 800, Height: 600})
	w.ShowAndRun()
}

@dweymouth
Copy link
Contributor

Oh, I was asking if you would be able to test swapping out the implementations of those 2 functions with the 2.4.5 versions in the release/v2.5.x branch, and if that worked, if you'd consider opening a PR :)

@ErikKalkoken
Copy link
Contributor Author

Sorry, but I know too little about that part of the Fyne code to be able fix this myself.

@dweymouth
Copy link
Contributor

OK, I can probably get around to it in a day or few next time I am on my Ubuntu machine

@Jacalz
Copy link
Member

Jacalz commented Aug 7, 2024

Like mentioned in #5030 (comment), I can not replicate this on Fedora 40. Likely not a bug within the rymdport/portal package as far as I can see.

Jacalz added a commit to Jacalz/fyne that referenced this issue Aug 7, 2024
Should hopefully fix theme lookup on Ubuntu 22.04 and other Linux
distros using too old Gnome versions.

Fixes fyne-io#5029
Replaces fyne-io#5030
@Jacalz

This comment was marked as outdated.

@Jacalz
Copy link
Member

Jacalz commented Aug 9, 2024

I have an idea for what could be causing this. I switched from using the old deprecated .Read interface for the dBUS call to instead use the new .ReadOne call. I wonder if old Linux LTS releases like Ubuntu 22.04 perhaps don't support the new interface and thus always fails when trying to read the value?

Jacalz added a commit to Jacalz/fyne that referenced this issue Aug 9, 2024
The theme value was looked up before being set for the first time. I also updated to a new version of the portal package that lets us not only use the value when the theme changes (instead of manually loading it again) but also falls back to use the old Read function to look up settings if ReadOne fails.

Should hopefully fix fyne-io#5029
@Jacalz
Copy link
Member

Jacalz commented Aug 9, 2024

I have opened #5061 now. I'm fairly certain that it should fix things once and for all. The main problem that I found on the Fyne side was that changes to how we handle dark/light mode internally had a race condition where the dark theme preference was looked up after the theme was set up. I also made sure to fall back to the .Read function that we used for settings in v2.4.x (hopefully fixing Ubuntu 22.04). On top of that, I improved the time ti takes to switch theme when the theme changes.

@andydotxyz
Copy link
Member

Fixed ready for v2.5.1

andydotxyz pushed a commit that referenced this issue Aug 17, 2024
The theme value was looked up before being set for the first time. I also updated to a new version of the portal package that lets us not only use the value when the theme changes (instead of manually loading it again) but also falls back to use the old Read function to look up settings if ReadOne fails.

Should hopefully fix #5029
dweymouth added a commit to dweymouth/fyne that referenced this issue Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants