Skip to content

[Bug]: nativeTheme API not working on Fedora Workstation 36 / Gnome 42 #33635

Closed as not planned

Description

@aeschli

Preflight Checklist

Electron Version

17.1.2

What operating system are you using?

Other Linux

Operating System Version

Fedora Linux 36 (Workstation Edition Prerelease)

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

nativeTheme should reflect the light/dark scheme configured in the OS

Actual Behavior

nativeTheme.shouldUseDarkColors is always false.

Testcase Gist URL

No response

Additional Information

From microsoft/vscode#146804

  • git clone https://github.com/aeschli/electron-theme-test.git
  • cd electron-theme-test, npm i && npm start
  • a simple electron window opens
  • switch between light and dark in the OS
  • the window should change the menu bar colors and the terminal should print shouldUseDarkColors matching the OS scheme.

image

Terminal output

> [email protected] start
> electron-forge start

✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies
✔ Launching Application
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[4553:0406/110408.146875:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[4553:0406/110412.166946:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times!
[4553:0406/110449.772046:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 2 times!
[4553:0406/110449.783890:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 3 times!

Activity

  1. changed the title [-]nativeTheme API not working on Fedora Workstation [/-] [+]nativeTheme API not working on Fedora Workstation 36 / Gnome 42[/+] on Apr 7, 2022
  2. added
    has-repro-repo
    on Apr 19, 2022
  3. moved this to Unsorted Issues in 19-x-yon Apr 19, 2022
  4. moved this from Unsorted Issues to Doesn't Block Stable in 19-x-yon Apr 21, 2022
  5. ckerr commented on Apr 26, 2022

    @ckerr
    Member

    I'm not able to reproduce this when running the test repo (Electron 17.1.2) on Ubuntu 22.04, which like Fedora 36 is also running GNOME 42. Wayland graphics. When I load System settings, go to Appearance, and click "Light" or "Dark", Electron's theme updates correctly along with the rest of the desktop.

    I'll try installing Fedora 36 to see if that changes things.

    As an aside, I do see that the console log is triggered twice each time I toggle between light and dark:

    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    

    I'm mentioning it here since It's possible that this is relevant to the bug and that second event is needed to make Electron's theme change. It's also possible that, this is a red herring, that the testcase registered for the event twice, or that Electron is generating unnecessary duplicate events 👀 :

    I'll try installing Fedora 36 to see if that helps in reproducing this issue.

  6. Jeter-work commented on Jun 3, 2022

    @Jeter-work

    New install of Fedora 36 and I see this issue as well. Specifically with VS Code 1.67.2. Came here from: microsoft/vscode#146804

  7. senekor commented on Jun 5, 2022

    @senekor

    The work around posted here worked for me:

    Gnome Tweaks -> Appearance -> Themes, Legacy Application -> Select Dark theme (Adwaita-dark)

    I have also figured out for myself a way to script this:

    gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"
    gsettings set org.gnome.desktop.interface gtk-theme "Adwaita-dark"
    

    The first line is how Fedora 36 seems to "generally" handle dark mode, while the second covers those edge cases like vscode / electron.

  8. proninyaroslav commented on Jun 5, 2022

    @proninyaroslav

    @remlse
    But this will not follow the system theme change. Although it's possible to write a script that would listen to the DBus theme change event and change it globally.

  9. proninyaroslav commented on Jun 5, 2022

    @proninyaroslav

    I also use a ready-made extension for GNOME 42 which allows to force a theme switch for legacy applications (this is disabled by default in the extension settings) https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension
    I definitely recommend it to those who want to have real theme switching in GNOME 42 like in macOS.

  10. 12 remaining items

  11. escape0707 commented on Apr 4, 2023

    @escape0707

    Combining with #33635

    This issue is #33635. Was this one closed by accident?

    Problem solved in Chinese Communist Party ways.

  12. Ige-fi commented on Apr 10, 2023

    @Ige-fi

    The upstream issue in Chromium has been fixed today, at long last. They have implemented a new DarkModeManagerLinux view that monitors the FreeDesktop settings portal, and falls back to GTK/QT theme monitoring for systems where the portal is not supported. As far as I can see, this means that the current workaround for GTK themes in the nativeTheme API of Electron is no longer needed.

  13. q234rty commented on Jun 29, 2023

    @q234rty

    I believe this was not fixed by just updating chromium to 114, the workaround mentioned above probably needs to be removed.

  14. Ige-fi commented on Jul 7, 2023

    @Ige-fi

    @q234rty is correct. Chromium 114 did fix the prefers-color-scheme query for newer distros that implement the XDG Settings portal. You can test it yourself by using a suitable desktop environment (e.g. Fedora 38 / GNOME 44), downloading the latest Chrome/Chromium, opening this site, and toggling the dark mode setting in the desktop environment’s settings. The style of the page should change immediately.


    However, since Electron 25 still uses the aforementioned workaround, which is designed for older Linux distributions and older Chromium, the nativeTheme API cannot possibly work as expected for newer systems that rely solely on the Settings portal, since Electron overrides Chromium’s (now correct) current behaviour.

    Reproduction steps

    I have updated the reproduction repository example by @aeschli.

    Prerequisities: use Fedora 38 / GNOME 44

    1. Clone the repository, install and start the app
    git clone https://github.com/Igetin/electron-25-prefers-color-scheme-test
    cd electron-25-prefers-color-scheme-test
    npm install
    npm start
    1. An Electron window should open
    2. Switch between the light/dark preference in the OS
      • you can do this in the quick settings panel of the top bar by toggling the “Dark Style” setting

    What should happen

    • When the light preference is active:
      • The window will have black text on a white background
      • shouldUseDarkColors: false will be printed in the terminal
    • When the dark preference is active:
      • The window will have white text on a black background
      • shouldUseDarkColors: true will be printed in the terminal

    What actually happens

    The window has black text on a white background at all times, and does not respond to the system’s preference. Only shouldUseDarkColors: false is printed to the terminal.

    Here’s also an example screenshot of the erroneous behaviour. As can be seen, the dark preference is enabled in the Fedora 38 system, but the Electron window does not reflect this.

    electron-25-prefers-color-scheme-dark-bug

    Fix

    To fix this, Electron must remove the previously mentioned workaround. Chromium now handles the prefers-color-scheme media query in a backwards-compatible manner, which means that it should work for both older distros/apps (that rely on the selected GTK/Qt theme) and newer distros/apps (that rely on the XDG Settings portal preference). Electron no longer needs to provide special handling for Linux distros in the nativeTheme API.

    In this context, “old distros” are basically any distros that still rely on GTK themes for light/dark preference. This includes GNOME 41 or older (example: Ubuntu 18.04) and all currently supported Plasma releases (example: Kubuntu 22.04).

    GNOME implemented the XDG Settings portal in GNOME 42 . Distros that have 42 or a newer version are “new distros” in this context (examples: Fedora 36+, Ubuntu 22.04).

    (Note: KDE technically implemented the XDG Settings portal in Plasma 5.24. However, if you toggle between light and dark appearance in the system settings, it currently still changes the GTK theme under the hood.)


    @codebytere Can you please reopen the issue, as this is still unresolved and reproducible on the latest Electron? This was inadvertently closed as a duplicate a few months ago. You marked 36040 as a duplicate of this issue (33635), so this issue should have stayed open as it is the earliest report of the problem.

  15. Danik1601 commented on Jul 30, 2023

    @Danik1601

    Combining with #33635

    This issue is #33635. Was this one closed by accident?

    @codebytere I believe you closed this issue by accident. Please reopen it

  16. aeschli commented on Aug 24, 2023

    @aeschli
    Author

    @codebytere Can this issue be reopened?

    I tested on Fedora Linux 38 (Workstation Edition), Gnome 44.3, Wayland
    Electron 26.1.0, Node.js 18.16.1, Chromium 116.0.5845.97

    • git clone https://github.com/aeschli/electron-theme-test.git
    • cd electron-theme-test, npm i && npm start
    • a simple electron window opens

    Expected:

    • the console prints shouldUseDarkColors: false when the OS uses a light color scheme, or shouldUseDarkColors: true if the OS color scheme is dark

    Actual:

    • Always shouldUseDarkColors: false, is printed, even when the OS color scheme is dark.

    • In the OS settings, switch between light and dark while the window is still open

    Expected:

    • the console prints a message matching the need OS color scheme

    Actual:

    • nothing printed

    Test running under Wayland:

    • cd electron-theme-test, npm i && npm start-wayland

    Same problem.

  17. itsyigid commented on Nov 6, 2023

    @itsyigid

    @codebytere Can this issue be reopened?

    I tested on Fedora Linux 38 (Workstation Edition), Gnome 44.3, Wayland Electron 26.1.0, Node.js 18.16.1, Chromium 116.0.5845.97

    • git clone https://github.com/aeschli/electron-theme-test.git
    • cd electron-theme-test, npm i && npm start
    • a simple electron window opens

    Expected:

    • the console prints shouldUseDarkColors: false when the OS uses a light color scheme, or shouldUseDarkColors: true if the OS color scheme is dark

    Actual:

    • Always shouldUseDarkColors: false, is printed, even when the OS color scheme is dark.
    • In the OS settings, switch between light and dark while the window is still open

    Expected:

    • the console prints a message matching the need OS color scheme

    Actual:

    • nothing printed

    Test running under Wayland:

    • cd electron-theme-test, npm i && npm start-wayland

    Same problem.

    Tested just like @aeschli has done on Arch Linux, Hyprland (Wayland) without no success.

    I attached a video demonstrating the issue; you can clearly see Chromium switching themes as the GTK theme and colour scheme change, and also the logged CLI messages noticing the change; however, the Electron app doesn't react in any way.

    test.mp4
  18. real-or-random commented on Nov 6, 2023

    @real-or-random

    I attached a video demonstrating the issue;

    Note: the video doesn't work (here in my Firefox). "Video can't be played because the file is corrupt."

  19. itsyigid commented on Nov 6, 2023

    @itsyigid

    I attached a video demonstrating the issue;

    Note: the video doesn't work (here in my Firefox). "Video can't be played because the file is corrupt."

    I triple checked the attachment, and it seems to work on Chromium. I'll record again with a different codec once I've the time.

  20. strophy commented on Nov 7, 2023

    @strophy

    Plays for me by downloading it and using VLC

  21. johnny-brav0 commented on Jan 5, 2024

    @johnny-brav0

    This issue is still there on Fedora 39 (Workstation Edition) running GNOME 45.2

    Terminal output:

    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020111.827043:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times!
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020130.378229:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 2 times!
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020134.019750:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 3 times!
    

    shouldUseDarkColors seems to change but only the title bar changes to dark/light.

    EDIT:
    The Open and Save As dialog boxes are white, other ones which appear like "Are you sure you want to ... something" go dark when using "custom" dialog style.

  22. itsyigid commented on Jan 6, 2024

    @itsyigid

    This issue is still there on Fedora 39 (Workstation Edition) running GNOME 45.2

    Terminal output:

    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020111.827043:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times!
    shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020130.378229:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 2 times!
    shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
    [6046:0106/020134.019750:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 3 times!
    

    shouldUseDarkColors seems to change but only the title bar changes to dark/light.

    EDIT: The Open and Save As dialog boxes are white, other ones which appear like "Are you sure you want to ... something" go dark when using "custom" dialog style.

    It's apparent that we won't be getting a real fix...

  23. real-or-random commented on Jan 7, 2024

    @real-or-random

    @codebytere I believe you closed this issue by accident. Please reopen it

    @codebytere Giving this another try. Can you please re-open this issue? It was closed by accident.

  24. spease commented on Nov 13, 2024

    @spease

    This still seems to be indirectly causing an issue with Signal, are there any plans to get this fixed?

  25. real-or-random commented on Nov 13, 2024

    @real-or-random

    AFAIU the discussion and in particular @Igetin's very detailed analysis (#33635 (comment)), the solution should be simply reverting fdf40ce. Perhaps this should be submitted as a PR? This would at least raise renewed attention to the issue.

    (I don't have the time right now, so for the moment, I just hope that someone else can step up here.)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions