Skip to content

prefers-color-scheme media query not updated when changing nativeTheme.themeSource #22846

Closed

Description

@tinselspoon

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:
    • v8.2.0
  • Operating System:
    • Windows 10 (17763)
  • Last Known Working Electron version:
    • n/a

Expected Behavior

When setting nativeTheme.themeSource, the prefers-color-scheme media query updates accordingly and all elements using the query on the page are restyled.

Actual Behavior

Setting nativeTheme.themeSource does not appear to update the media query until a system-level change to the light/dark theme is made.

e.g. if we do nativeTheme.themeSource = "dark", then running matchMedia("(prefers-color-scheme: dark)").matches returns false.

The documentation appears to suggest the media query should update: https://www.electronjs.org/docs/api/native-theme#nativethemethemesource

To Reproduce

Fiddle Gist: https://gist.github.com/6e571fb4e8aa3d319a3109d61dda79c3

  1. Set your windows theme to light in system settings.
  2. Open the fiddle. The menu bar and page are in the light theme.
  3. From the Theme menu, click Dark. This sets nativeTheme.
  4. Notice that the menu changes colour but the page does not (as per screenshot).
  5. Set your windows theme to dark in system settings.
  6. Notice that the page is now dark.
  7. Set your windows theme to light in system settings.
  8. The page remains dark as expected.
  9. From the Theme menu, click Light.
  10. The menu changes colour but the page does not. It only updates when changing the system settings.

Screenshots

image

Additional Information

  • Using the remote module to set nativeTheme.

Activity

  1. tinselspoon commented on Mar 30, 2020

    @tinselspoon
    Author

    Thanks for the quick fix!

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions