Skip to content

nativeTheme not receiving updated event respecting Linux system preference change #25925

Closed

Description

@davidwinter

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:
    • 10.1.3 11.0.1
  • Operating System:
    • Ubuntu 20.04 x64

Expected Behavior

When switching "Window theme" preference between Light and Dark modes on Ubuntu, the updated event should be triggered for nativeTheme.

Actual Behavior

The updated event is never triggered when alternating between window themes.

To Reproduce

See: https://github.com/davidwinter/electron-native-theme/blob/master/main.js

$ git clone https://github.com/davidwinter/electron-native-theme.git
$ yarn
$ ./node_modules/.bin/electron main.js

Screenshots

image

Activity

  1. ckerr commented on Oct 19, 2020

    @ckerr
    Member

    I think this is fixed as a side-effect of #23479

  2. davidwinter commented on Nov 18, 2020

    @davidwinter
    Author

    This is still broken with 11.0.1 @ckerr

    Example repo updated.

  3. shiftkey commented on Mar 11, 2021

    @shiftkey
    Contributor

    I'm seeing similar behaviour on Ubuntu 20.04 with Electron 11.1.1 while working with GitHub Desktop's Linux fork. I can put together a better repro but the short version:

    • changing from Yaru-light to Yaru-dark does update the default chrome of the app
    • querying from the console for nativeTheme.shouldUseDarkColors shows the correct value
    • but the updated event on nativeTheme doesn't fire, so the app content itself is unable to switch from light to dark as the OS changes

    This limits us being able to emulate the "Automatically switch theme to match system theme" behaviour that macOS and Windows now allow us to do in the app.

  4. julianfairfax commented on Mar 15, 2021

    @julianfairfax

    Hopefully this can be resolved somehow. I use an extension to change my theme automatically depending on time of day, and Electron apps (most of my apps) use the system theme when launching, but as mentioned don't update it after the theme has been changed, and they require a relaunch.

  5. ffflorian commented on Mar 23, 2021

    @ffflorian
    Contributor

    Also doesn't work with 11.4.1 and 12.0.1, but seems to be fixed with 13.0.0-beta.7. 🎉

  6. julianfairfax commented on Mar 23, 2021

    @julianfairfax

    Also doesn't work with 11.4.1 and 12.0.1, but seems to be fixed with 13.0.0-beta.7. 🎉

    Is there any indication of when version 13 will be released? And will the electron apps I use have to each be individually updated by their developer?

  7. ffflorian commented on Mar 23, 2021

    @ffflorian
    Contributor

    @julian-fairfax

    Is there any indication of when version 13 will be released?

    Electron 13 stable release is scheduled for 2021-05-25.

    And will the electron apps I use have to each be individually updated by their developer?

    Yes.

  8. Nantris commented on Mar 24, 2021

    @Nantris
    Contributor

    Any hope for a backport on this fix, to at least 11.x?

    @shiftkey's finding that the value is updated but 'updated' event is never triggered is interesting. That seems not to be the case for me on Mint 20.1 xfce.

    For us the value of nativeTheme.shouldUseDarkColors seems to be defined at the first run of the main process and doesn't change after that. If we create new windows, we will still get the old value if we run something like this in devtools: window.matchMedia('(prefers-color-scheme: dark)')

  9. Nantris commented on Apr 1, 2021

    @Nantris
    Contributor

    Anybody on the team know what PR may have resolved the issue for @ffflorian and whether it might be backport-able?

  10. nornagon commented on Apr 1, 2021

    @nornagon
    Contributor

    Closing this as fixed, but feel free to continue discussing backports.

  11. aykevl commented on Oct 11, 2022

    @aykevl

    Unfortunately, this doesn't appear to be working on KDE (current Arch Linux ARM / Asahi Linux, KDE Plasma 5.25.5). Most other applications do automatically update when the theme changes, including all tested KDE apps, Firefox, and Inkscape (GIMP and Chromium don't). The correct theme is applied on startup, but doesn't get updated when the system theme changes.

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