Bug 470972 - Some Flatpak apps do not follow system theme properly
Summary: Some Flatpak apps do not follow system theme properly
Status: RESOLVED DOWNSTREAM
Alias: None
Product: kde
Classification: I don't know
Component: general (show other bugs)
Version: unspecified
Platform: Flatpak Linux
: NOR normal
Target Milestone: ---
Assignee: Walker White
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-13 11:50 UTC by aylamz
Modified: 2023-08-04 20:42 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aylamz 2023-06-13 11:50:39 UTC
SUMMARY
Some Flatpak apps do not follow system theme properly. Many apps generally give users 3 options: use dark theme, use light theme, or detect automatically from system. The 'detect automatically from system' option does not work in some Flatpak apps and the app defaults to light theme. It generally does work properly with KDE Flatpak apps and Libadwaita Flatpak apps though.

STEPS TO REPRODUCE
1. Set KDE Plasma to use Breeze Dark in System Settings
2. Install Element, Cinny or Pulsar as Flatpak (these are the apps that I tried but likely are not the only ones)
3. In Element or Cinny set the app to follow system theme or 'match system'.

OBSERVED RESULT
The app keeps using light mode even though system is set to use Breeze Dark. In Pulsar, the menubar stays white but in non-Flatpak version of Pulsar it is dark as expected.

EXPECTED RESULT
All apps that support following system theme should use the dark variant of their UI if the system is using a dark theme. This works as expected for all apps that are not Flatpaks that I have tried, but does not work for some Flatpak apps. 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 38 KDE Spin
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.106.0
Qt Version: 5.15.9

ADDITIONAL INFORMATION
This issue has appeared earlier but went await after a while. When I re-installed Fedora it came back.
Comment 1 Walker White 2023-06-13 16:40:14 UTC
Hello Aaron! Unfortunately, due to the nature of Flatpaks, they cannot directly adhere to your system theme. Unlike most programs that run on your computer, Flatpaks are sandboxed, and their ability to access other files is very limited. Consequently, while a regular app might be able to read the neccessary files to adhere to your theme, a Flatpak will not. This explains the difference in behavior between the different versions of Pulsar. This article from the Flatpak documentation provides some helpful additional information!
https://docs.flatpak.org/en/latest/desktop-integration.html#theming
Comment 2 aylamz 2023-06-13 17:13:03 UTC
(In reply to Walker White from comment #1)
> Hello Aaron! Unfortunately, due to the nature of Flatpaks, they cannot
> directly adhere to your system theme. Unlike most programs that run on your
> computer, Flatpaks are sandboxed, and their ability to access other files is
> very limited. Consequently, while a regular app might be able to read the
> neccessary files to adhere to your theme, a Flatpak will not. This explains
> the difference in behavior between the different versions of Pulsar. This
> article from the Flatpak documentation provides some helpful additional
> information!
> https://docs.flatpak.org/en/latest/desktop-integration.html#theming

Apologies if I was being unclear. I'm not expecting these apps to use Breeze Dark. I'm expecting the applications to use their own dark theme when I have the system theme set to some dark theme such as Breeze Dark and when the theme preference in application is set to "Match system". This already works with KDE Flatpak applications and GNOME/libadwaita flatpak applications, and possibly some others but not with every application. Seems like the applications that do not work as expected are mostly electron apps, so maybe Electron is the problem here but I'm not sure.
Comment 3 Joshua Goins 2023-06-13 17:31:47 UTC
(In reply to Aaron Loit from comment #2)
> (In reply to Walker White from comment #1)
> > Hello Aaron! Unfortunately, due to the nature of Flatpaks, they cannot
> > directly adhere to your system theme. Unlike most programs that run on your
> > computer, Flatpaks are sandboxed, and their ability to access other files is
> > very limited. Consequently, while a regular app might be able to read the
> > neccessary files to adhere to your theme, a Flatpak will not. This explains
> > the difference in behavior between the different versions of Pulsar. This
> > article from the Flatpak documentation provides some helpful additional
> > information!
> > https://docs.flatpak.org/en/latest/desktop-integration.html#theming
> Apologies if I was being unclear. I'm not expecting these apps to use Breeze
> Dark. I'm expecting the applications to use their own dark theme when I have
> the system theme set to some dark theme such as Breeze Dark and when the
> theme preference in application is set to "Match system". This already works
> with KDE Flatpak applications and GNOME/libadwaita flatpak applications, and
> possibly some others but not with every application. Seems like the
> applications that do not work as expected are mostly electron apps, so maybe
> Electron is the problem here but I'm not sure.

This is an Electron problem, and nothing we can really do on our end. XDG has already exposed a key for applications to use, so now it's up to the application developers to take advantage of it (https://github.com/Exalm/xdg-desktop-portal/commit/408ce403a80a8a588c8e9d66528ef0df3ca1e134)
Comment 4 aylamz 2023-06-13 17:54:08 UTC
(In reply to Joshua Goins from comment #3)
> (In reply to Aaron Loit from comment #2)
> > (In reply to Walker White from comment #1)
> > > Hello Aaron! Unfortunately, due to the nature of Flatpaks, they cannot
> > > directly adhere to your system theme. Unlike most programs that run on your
> > > computer, Flatpaks are sandboxed, and their ability to access other files is
> > > very limited. Consequently, while a regular app might be able to read the
> > > neccessary files to adhere to your theme, a Flatpak will not. This explains
> > > the difference in behavior between the different versions of Pulsar. This
> > > article from the Flatpak documentation provides some helpful additional
> > > information!
> > > https://docs.flatpak.org/en/latest/desktop-integration.html#theming
> > Apologies if I was being unclear. I'm not expecting these apps to use Breeze
> > Dark. I'm expecting the applications to use their own dark theme when I have
> > the system theme set to some dark theme such as Breeze Dark and when the
> > theme preference in application is set to "Match system". This already works
> > with KDE Flatpak applications and GNOME/libadwaita flatpak applications, and
> > possibly some others but not with every application. Seems like the
> > applications that do not work as expected are mostly electron apps, so maybe
> > Electron is the problem here but I'm not sure.
> 
> This is an Electron problem, and nothing we can really do on our end. XDG
> has already exposed a key for applications to use, so now it's up to the
> application developers to take advantage of it
> (https://github.com/Exalm/xdg-desktop-portal/commit/
> 408ce403a80a8a588c8e9d66528ef0df3ca1e134)

That is very strange as I recall it working as expected before I re-installed the OS (same distro: Fedora KDE spin). I don't remember what I did to get it to work though because it was completely accidental, I simply at one point noticed that this issue was gone.
Comment 5 aylamz 2023-06-14 07:00:09 UTC
So I did some more tinkering and this issue affects more than just Electron apps: for example Tenacity is affected as well. Also would out that Tenacity and Electron apps seem to all decide whether to use dark or light style based on the system GTK theme. So if I go to System Settings > Appearance > Global Theme > Application Style > Configure GNOME/GTK application style and set the GTK theme to some dark theme such as 'adw-gtk3-dark' then the Electron Flatpak apps and Tenacity properly use the dark theme when set to match system theme. If GTK theme is set to Breeze though, the issue described in this bug report appears. Interesting that there is only Breeze theme, I wonder if this issue could be fixed by having separate Breeze Dark and Breeze Light GTK themes?
Comment 6 Nate Graham 2023-08-04 20:42:10 UTC
Joshua is right: this is an app bug... or a series of app bugs. Apps no longer have to guess whether the system is light or dark using this or that random heuristic; they can query the standard color-scheme key as specified in the portal spec linked. Any apps still trying (and evidently failing) to guess this by introspecting the GTK theme or doing some other weird thing need to be ported to use the new standard, which always works, and we support it in Plasma by setting it based on the luminance of your active color scheme.