question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Electron: Consider to leverage `nativeTheme.themeSource` to enforce light or dark mode in window

See original GitHub issue

I’m always using Dark+ Theme at VSCode (regardless of macOS light/dark appearance), but when window.titleBarStyle set to native, title bar style is mismatching with VSCode theme (if system-wide appearance is light). looks like this:

image

Electron has require("electron").nativeTheme.themeSource API and BrowserWindow#vibrancy API that can overrides system appearance per app/window, so I injected require("electron").nativeTheme.themeSource = "dark" to Visual Studio Code.app/Contents/Resources/app/out/main.js (yeah, its unsupported, i know) and looks pretty great.

image

However, I think code injection is not supported, possibly corrupting the installed VS Code, and disabling it with every VS Code update.

so I’ll suggest new settings that overrides macOS appearance based on VSCode theme.

Note: I think this new settings may conflicts with window.autoDetectColorScheme and window.autoDetectHighContrast.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
bpaserocommented, Apr 8, 2021

I tested this and it seems to work really well on macOS at least. Still, I wonder if this needs to be a separate setting that the user can control it and wether we should not do this automatically.

@aeschli do you have thoughts on this? I know you have added theming related code and settings that automatically switch the theme in VSCode between dark and light depending on the OS setting. Here we would introduce a setting for the user to “hard-code” the appearance of the application to be either dark or light. I would think this setting can only be application scoped and not per workspace though because we need to resolve this from the main side.

Demo:

recording

0reactions
bpaserocommented, Apr 9, 2021

If window.autoDetectColorScheme is false, observe the current color theme and set nativeTheme.themeSource = ‘dark’ or nativeTheme.themeSource = ‘light’ so the window appearance matches the color theme

I am worried that this is a somewhat breaking change for everyone that just runs with default settings and might be confusing for users. If macOS is running in light mode (default), it is probably weird that VSCode suddenly appears dark, both in the window title as well as context menus.

So I think either a new setting or an update to the existing setting is still needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dark Mode | Electron
If you want to manually switch between light/dark modes, you can do this by setting the desired mode in the themeSource property of...
Read more >
Override prefers-color-scheme in Electron - css - Stack Overflow
There is an API! You can nativeTheme.themeSource to system , light or dark . For example, in my background.ts , add this code:...
Read more >
electron-nightly - UNPKG
* Emitted when the application is quitting. 411, *. 412, * **Note:** On Windows, this event will not ...
Read more >
Make your Electron app Dark Mode compatible - Medium
What's worse than seeing a light theme appear for a few milliseconds then switch to a dark one? Nothing is worse. Electron. To...
Read more >
Accelerator - Electron - W3cubDocs
Then execute Electron.app (or electron on Linux, electron.exe on Windows), ... make it follow the system-wide dark mode setting using the nativeTheme api....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found