vscode: Dark mode doesn't switch on and off when the OS automatically switches

Type: Bug

  1. Set macOS to automatically switch between light mode and dark mode.
  2. Set VS Code to use different themes for light and dark mode.
  3. Before sunset, ensure you are in light mode. Lock your screen and leave your computer.
  4. Have a nice dinner, go for a bike ride, reconnect with friends and family, enjoy a beautiful sunset, and walk your dog.
  5. Later that night, return to your computer. Note the computer has automatically set dark mode, but VS Code is still on light mode.

You’ll have to manually switch macOS back to light mode and back again to dark mode for Code to pick up teh dark mode.

VS Code version: Code 1.70.1 (Universal) (6d9b74a70ca9c7733b29f0456fd8195364076dda, 2022-08-10T06:09:06.916Z) OS version: Darwin arm64 21.6.0 Modes:

System Info
Item Value
CPUs Apple M1 Ultra (20 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 6, 6, 5
Memory (System) 128.00GB (2.24GB free)
Process Argv –crash-reporter-id 04103f14-c8dc-42a8-b7b2-1ffef3657f3f
Screen Reader no
VM 0%
Extensions (30)
Extension Author (truncated) Version
vscode-zonefile Com 0.0.4
systemd-unit-file coo 1.0.6
doxdocgen csc 1.4.0
copilot Git 1.40.6471
vscode-pull-request-github Git 0.48.1
vscode-graphql Gra 0.7.3
vscode-graphql-syntax Gra 1.0.4
better-cpp-syntax jef 1.15.19
cmake-language-support-vscode jos 0.0.4
ldif jta 0.2.0
bash-ide-vscode mad 1.14.0
vscode-docker ms- 1.22.1
vscode-dotnet-runtime ms- 1.5.0
python ms- 2022.12.0
vscode-pylance ms- 2022.8.20
jupyter ms- 2022.7.1102252217
remote-containers ms- 0.245.0
remote-ssh ms- 0.84.0
remote-ssh-edit ms- 0.80.0
remote-wsl ms- 0.66.3
cmake-tools ms- 1.11.26
cpptools ms- 1.12.1
cpptools-extension-pack ms- 1.2.0
vsliveshare ms- 1.0.5683
vsliveshare-audio ms- 0.1.91
sqltools mtx 0.23.0
sqltools-driver-pg mtx 0.2.0
vetur oct 0.36.0
cmake twx 0.0.17
vscode-arduino vsc 0.4.12

(3 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411cf:30542925
vsaa593cf:30376535
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vscscmwlcmt:30465135
cppdebug:30492333
pylanb8912cf:30529770
vsclangdf:30486550
c4g48928:30535728
hb751961:30541207
dsvsc012cf:30540253

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 24 (7 by maintainers)

Most upvoted comments

What helped for me was to open up the settings.json manually and changing some lines. It was like this:

{
    "window.systemColorTheme": "auto",
    "window.autoDetectColorScheme": true,
}

I removed the systemColorTheme line, saved the file (Cmd+S) and then it did immediataly change colors correctly. It also changed the settings.json to this, though obviously that could also be Dark something if you run it in the evening.

{
    "window.autoDetectColorScheme": true,
    "workbench.colorTheme": "Default Light Modern",
}

This is vey likely an Electron issue. VS Code listens to the OS color theme changes that come from Electron, and I suspect one is missing while the screen is locked.

I you have a chance (and have node and git installed on your machine), can you validate my theory by running this:

  • git clone https://github.com/aeschli/electron-theme-test.git
  • cd electron-theme-test, npm i && npm start
  • a simple electron window opens
  • enjoy your evening
  • when you come back, check the output of the command and paste it here There should be some messages showing that the event has been sent

Marking as fixed. I made the following changes:

  • When window.autoDetectColorScheme is not enabled, we use workbench.colorTheme (as before)
  • When window.autoDetectColorScheme is enabled, we use workbench.preferredDarkColorTheme and workbench.preferredLightColorTheme. workbench.colorTheme is ignored, and also not changed
  • Caveat: window.autoDetectColorScheme is ignored it the system color is hardcoded by window.systemColorTheme

Did you set "window.autoDetectColorScheme": true ?

Is there a reason that window.autoDetectColorScheme is not set to true out-of-the-box? Pretty much every other application on my Mac has this default, and toggles based on system preference (including Teams, Outlook and other MSFT apps).

Seems like VSCode should remove the window.systemColorTheme setting when auto detect is turned on or at least warn a user about it. As it stands now if you set a color scheme and try to use auto, nothing will work unless you figure this bit out.