codebytere

#54595: refactor: use upstream's color scheme override for nativeTheme.themeSource

Merged
Created: Sep 30, 2026, 10:52:11 AM
Merged: Oct 5, 2026, 4:58:25 AM
3 comments
Target: main

Description of Change

nativeTheme.themeSource has been implemented since 2019 by a Chromium patch that adds set_theme_source() to ui::NativeTheme. CL 8401888 added ui::NativeTheme::SetPreferredColorSchemeOverride() upstream, which does the same job for every theme instance at once, so this uses it and drops the patch.

Electron now stores the themeSource value itself, and system restores the override the process started with, so --force-dark-mode behaves as before (new spec). On macOS the app appearance is set before the override, because Chromium reads the system value from it.

Behavior differs in three places:

  • With the patch, if the OS switched to the forced theme while themeSource was dark or light, the change was never recorded, and going back to system reported the previous OS theme. That is fixed.
  • While themeSource is dark or light, an OS theme change no longer emits updated. It used to in one direction only, as a side effect of the patched getter. On Windows shouldUseDarkColorsForSystemIntegratedUI is only refreshed on updated, so it keeps its last value until the next one.
  • On Linux the first themeSource = 'light' can emit one extra updated, because the upstream setter recomputes every OS-derived value and the UI theme's were computed before GTK's settings were available.

Compared on Linux against a build with the patch, with and without --force-dark-mode: themeSource, shouldUseDarkColors, prefers-color-scheme, the error for an invalid value and the context menu colors are identical, so there are no screenshots. macOS and Windows have only been through CI.

Only targets 45-x-y: 44-x-y is on Chromium 152, which does not have the upstream API.

Checklist

Release Notes

Notes: Fixed a stale nativeTheme.shouldUseDarkColors after resetting themeSource.

Backports

45-x-y
Merged
PR Number
#54648
Merged At
Oct 5, 2026, 7:55:52 AM
Released In
Not yet
Release Date
Not yet

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron