Detached window doesn't change color scheme automatically

Steps to reproduce

  1. In Option > Appearance, select Adapt to system in Base color scheme;
  2. Open any note in the main window and move it to a new window;
  3. Move the focus to the detached window;
  4. Change the system color scheme between light and dark.

Expected result

The color scheme of Obsidian changes with the system.

Actual result

The color scheme doesn’t change until the main window regains the focus.

Environment

SYSTEM INFO:
	Obsidian version: v0.16.0
	Installer version: v0.14.6
	Operating system: Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 21.6.0
	Login status: logged in
	Catalyst license: insider
	Insider build toggle: on
	Live preview: off
	Legacy editor: off
	Base theme: adapt to system
	Community theme: Minimal
	Snippets enabled: 3
	Restricted mode: off
	Plugins installed: 32
	Plugins enabled: 28
		1: Find orphaned files and broken links v1.6.1
		2: Improved VimCursor v0.0.1
		3: Add Codemirror matchbrackets.js v1.0.0
		4: Advanced URI v1.24.0
		5: Custom window title v0.3.5
		6: Hide Sidebars on Window Resize v1.0.4
		7: Find & Replace in Selection v1.1.0
		8: Garble Text v1.2.0
		9: File Explorer Note Count v1.2.0
		10: Relative Line Numbers v2.0.1
		11: Advanced Cursors v0.5.1
		12: Style Settings v0.4.10
		13: Calendar v1.5.10
		14: Get Info v1.1.0
		15: Obsidian Git v1.31.0
		16: Regex Find/Replace v1.2.0
		17: Readwise Official v2.0.1
		18: Minimal Theme Settings v6.0.0
		19: Regex Pipeline v1.2.0
		20: Tasks v1.12.0
		21: Notion-Like Tables v4.2.5
		22: Smort v1.0.1
		23: Extract Highlights v0.0.18
		24: Advanced Tables v0.17.3
		25: Kanban v1.3.17
		26: Dataview v0.5.43
		27: Weread Plugin v0.4.6
		28: Typewriter Scroll v0.2.2

download and reinstall obsidian.

does this happen in the sandbox vault?

I can’t repro

Thanks for the reply. I tried again and find the issue can be reproduced only if the main window is either hidden, minimized, or located on a different desktop than the detached window.

Please see a screen capture demonstrating the bug: https://share.cleanshot.com/1FTNed/

Here, I minimized the main window and you can observe the detached window didn’t change color scheme with the system until the main window was un-minimized.

did you download and reinstall obsidian?

Yes and the issue persists.

ok, maybe this is an OSX specific issue.

Steps to reproduce

  • open Obsidian sandbox
  • set base color scheme to “Adapt to system”
  • Cmd+P “Open current tab in new window”
  • Move the new window to another desktop space
  • Move focus to the new window in the other space
  • Open system settings and toggle between light and dark mode
  • Problem: Obsidian color scheme doesn’t switch
  • Move to space where the main Obsidian Sandbox window is open
  • The color scheme switches as soon as the main Obsidian window becomes visible

Did you follow the troubleshooting guide?

Y

Expected result

I expect the color scheme of Obsidian to switch as soon as the system setting changes, no matter what desktop space I am on.

Actual result

The color scheme only changes as soon as I go to the space where the main vault window is open.

Environment

SYSTEM INFO:
	Obsidian version: v1.4.16
	Installer version: v1.4.16
	Operating system: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 23.2.0
	Login status: logged in
	Catalyst license: none
	Insider build toggle: off
	Live preview: on
	Legacy editor: off
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none

Additional information

This always reproduces, on multiple machines.

I encounter this problem every day, as I frequently work with a second window that’s in a different space than the main window. Then I need to switch to the space with the main window and back in order for the color scheme to become consistent with the rest of the system.

Thank you in advance for looking into this!

@WhiteNoise *bump*

Just want to confirm this issue occurs on Windows 10 as well, w/1.5.8 (asar+installer). Ever since I switched to “adapt to system”, I arrive at my desk in the morning with detached windows having the wrong color scheme until I switch focus to the main window, then everything changes color.

It appears the cause of the issue is that the window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", o) setup is only done in the main window, not in other windows. So if the main window is hidden, it doesn’t receive the event and the light/dark mode switch doesn’t happen.

Based on the way this is coded, I would expect it to have the same problem on all platforms. It isn’t even necessary for the main window to be on a different virtual desktop (on Windows), just that it not be visible, as Electron/Chromium delays certain events for hidden windows/documents. So the main window simply being hidden behind other windows suffices to repro it on Windows for me at least.

I’ve released a workaround for this in Pane Relief 0.5.3, for anyone still having this issue.

That the specific workaround code I used works to fix the issue (at least for me on Win 10), seems to confirm the cause is indeed the lack of change listeners in windows other than the main one.

I would suggest wrapping app.adaptTotheme with a debounce so that if multiple windows receive the event it doesn’t set the theme multiple times, once for each visible window. (Or alternately, have app.setTheme() check whether a change is actually needed, so it doesn’t repeat the change.)

will be fixed v1.5.13