You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Always matches prefers-color-scheme: light media-query (no dark mode) #21427
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
Electron Version:
7.1.3 & 8.0.0-beta.4
Operating System:
Linux Manjaro 18.1.3
Expected Behavior
Electron should behave like Chromium with prefers-color-scheme media-queries.
Actual Behavior
Electron always matches prefers-color-scheme: light so OS dark-mode isn't selected in media-query.
To Reproduce
I made an electron-fiddle here. You can reproduce issue by switching to dark theme in your OS. See <link> tags in <head>.
Screenshots
This is a comparison of same web-page in electron 7.1.3 (right) and chromium 78.0.3904.97 (left) on Arch/Manjaro. I am switching between "Adwaita-dark" and "Adwaita" themes on gnome.
Reacted by Marek Hrabe, Gergely Gombos, Caesar Schinas, Lorenz Hoffmann, Selwyn, Melvin. L. Abraham, su-ex, Martin Carton, Théo LUDWIG, Zháinán Gāofùshuài and 1 more
changed the title [-]Always matches `prefers-color-scheme: light`[/-][+]Always matches `prefers-color-scheme: light` media-query (no dark mode)[/+]on Dec 7, 2019
For me window.matchMedia((prefers-color-scheme: light)).matches === true also returns always true in Chromium regardless of theme. Works in FF properly though.
@Prinzhorn
I tried an Electron fiddle with 9.0.0-beta.13, but still doesn't seem to work in GNOME 3.34. 😞
I reckon it's because of this unsolved Chromium bug . prefers-color-scheme doesn't at all seem to be working properly in Linux.
@gombosg oh I understand, these are two separate things. What was fixed in 9.0.0-beta.13 was a regression where explicitly setting nativeTheme.themeSource would not work anymore. This is about having nativeTheme.themeSource = 'system' work automatically with the system theme on Linux.
#23678 does appear to make things better (and I also like the way it decides whether a theme is dark or light) but unless I'm missing something it doesn't appear to be a full fix for this bug.
When switching themes (e.g. between yaru-dark and yaru-light, or between adwaita and adwaita-dark as described by @konsumer), the gist above does not change its appearance, and when I look in the inspector, window's prefers-color-scheme value doesn't change. (Tested on master @ 3fa4299)
I've confirmed that #23678 does ensure set_use_dark_colors() is called so that's a step in the right direction, but that doesn't appear to be the whole fix.
I am running Pop!OS 20.04 (very similar to Ubuntu 20.04) and chrome 83.0.4103.97 doesn't seem to work right, anymore.
I made this codepen to demonstrate:
You can see, weirdly, it seems to understand to change the window decorations to light/dark, but the content doesn't change.
Here I am testing with same HTML, in that electron-fiddle, with same issue:
Activity
[-]Always matches `prefers-color-scheme: light`[/-][+]Always matches `prefers-color-scheme: light` media-query (no dark mode)[/+]gombosg commentedon Feb 21, 2020
Yep, same for me.
See also VSCode, Joplin.
For me
window.matchMedia((prefers-color-scheme: light)).matches === truealso returns always true in Chromium regardless of theme. Works in FF properly though.EDIT: could be due to this Chromium bug.
EDIT2: at the same time, the top menu in an Electron app turns dark when switching to a dark theme.
Prinzhorn commentedon Apr 3, 2020
@konsumer for me this is fixed in 9.0.0-beta.13 (see #22900). Can you confirm?
gombosg commentedon Apr 3, 2020
@Prinzhorn
I tried an Electron fiddle with 9.0.0-beta.13, but still doesn't seem to work in GNOME 3.34. 😞
I reckon it's because of this unsolved Chromium bug .
prefers-color-schemedoesn't at all seem to be working properly in Linux.Prinzhorn commentedon Apr 3, 2020
@gombosg oh I understand, these are two separate things. What was fixed in 9.0.0-beta.13 was a regression where explicitly setting
nativeTheme.themeSourcewould not work anymore. This is about havingnativeTheme.themeSource = 'system'work automatically with the system theme on Linux.ckerr commentedon Jun 4, 2020
#23678 does appear to make things better (and I also like the way it decides whether a theme is dark or light) but unless I'm missing something it doesn't appear to be a full fix for this bug.
When switching themes (e.g. between yaru-dark and yaru-light, or between adwaita and adwaita-dark as described by @konsumer), the gist above does not change its appearance, and when I look in the inspector, window's
prefers-color-schemevalue doesn't change. (Tested on master @ 3fa4299)I've confirmed that #23678 does ensure
set_use_dark_colors()is called so that's a step in the right direction, but that doesn't appear to be the whole fix.konsumer commentedon Jun 4, 2020
I am running Pop!OS 20.04 (very similar to Ubuntu 20.04) and chrome 83.0.4103.97 doesn't seem to work right, anymore.
I made this codepen to demonstrate:
You can see, weirdly, it seems to understand to change the window decorations to light/dark, but the content doesn't change.
Here I am testing with same HTML, in that electron-fiddle, with same issue:
So I guess the upstream chrome issue is to blame.
konsumer commentedon Jun 4, 2020
I tested on windows 10, and it seems to work right:
latest chrome:
latest electron-fiddle:

konsumer commentedon Jun 5, 2020
I also tried same source in neutralino, a sort of competing project, which uses webkitgtk and it works as expected:
zcbenz commentedon Jun 5, 2020
It seems that GTK theme observer is not working, and could not update dark mode setting when it is changed:
zcbenz commentedon Jun 5, 2020
I would not be able to look into this for a while, feel free to dig more if anyone is interested.
electron-triage commentedon Mar 9, 2021
The Electron version reported on this issue is no longer supported. See our supported versions documentation.
If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.
Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.