Skip to content

Always matches prefers-color-scheme: light media-query (no dark mode) #21427

Closed

Description

@konsumer

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • 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.

Peek 2019-12-06 20-06

Activity

  1. changed the title [-]Always matches `prefers-color-scheme: light`[/-] [+]Always matches `prefers-color-scheme: light` media-query (no dark mode)[/+] on Dec 7, 2019
  2. gombosg commented on Feb 21, 2020

    @gombosg

    Yep, same for me.
    See also VSCode, Joplin.

    For me window.matchMedia((prefers-color-scheme: light)).matches === true also 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.

  3. Prinzhorn commented on Apr 3, 2020

    @Prinzhorn
    Contributor

    @konsumer for me this is fixed in 9.0.0-beta.13 (see #22900). Can you confirm?

  4. gombosg commented on Apr 3, 2020

    @gombosg

    @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.

  5. Prinzhorn commented on Apr 3, 2020

    @Prinzhorn
    Contributor

    @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.

  6. self-assigned this
    on May 20, 2020
  7. ckerr commented on Jun 4, 2020

    @ckerr
    Member

    #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.

  8. reopened this on Jun 4, 2020
  9. konsumer commented on Jun 4, 2020

    @konsumer
    Author

    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:

    Peek 2020-06-04 14-57

    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:

    Peek 2020-06-04 15-00

    So I guess the upstream chrome issue is to blame.

  10. konsumer commented on Jun 4, 2020

    @konsumer
    Author

    I tested on windows 10, and it seems to work right:

    latest chrome:

    Peek 2020-06-04 15-09

    latest electron-fiddle:
    Peek 2020-06-04 15-13

  11. konsumer commented on Jun 5, 2020

    @konsumer
    Author

    I also tried same source in neutralino, a sort of competing project, which uses webkitgtk and it works as expected:

    Peek 2020-06-04 17-24

  12. zcbenz commented on Jun 5, 2020

    @zcbenz
    Contributor

    It seems that GTK theme observer is not working, and could not update dark mode setting when it is changed:

    linux_ui->GetNativeTheme(nullptr)->AddObserver(dark_theme_observer_.get());
    
  13. zcbenz commented on Jun 5, 2020

    @zcbenz
    Contributor

    I would not be able to look into this for a while, feel free to dig more if anyone is interested.

  14. removed their assignment
    on Jun 5, 2020
  15. electron-triage commented on Mar 9, 2021

    @electron-triage

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions