Files
Hebert Marchesi 87c1a9cc11 Fix/appearance system reset (#152)
* fix: Dark -> System appearance switch left window content dark

Problem:
Selecting Dark in the appearance picker and then switching back to
System updated only the title bar; the sidebar and detail content stayed
dark while the window was focused. The content only snapped to the
correct scheme once the PureMac window lost focus.

Reproduction (system appearance set to Light):
1. Launch PureMac (Appearance: System)
2. Choose Appearance -> Dark
3. Choose Appearance -> System
   -> title bar turns light, all window content remains dark
4. Click any other window: the content now turns light

Root cause:
The theme was applied with .preferredColorScheme(appearance.colorScheme),
where System maps to nil. On macOS, resetting preferredColorScheme from
an explicit scheme back to nil inside a WindowGroup that hosts a
NavigationSplitView (unified toolbar) resets the NSWindow appearance --
the title bar follows the system again -- but SwiftUI does not
re-evaluate the content's colorScheme environment until the window
resigns key. Confirmed on macOS 26.5 with a minimal instrumented repro:
after the reset, window.appearance=nil / effectiveAppearance=Aqua while
the content still reported colorScheme=dark; the same repro without the
NavigationSplitView does not exhibit the bug, so this is a SwiftUI
framework defect PureMac was triggering, not an app logic error.

Fix:
Drive the override at the AppKit level instead. ThemeManager now sets
NSApp.appearance (nil for System, aqua/darkAqua for explicit modes) when
the selection changes and on startup, and the .preferredColorScheme
modifier is removed. The AppKit route applies immediately while the
window stays focused, and also themes windows outside the main scene
(Settings, menus, popovers). AppearanceMode.colorScheme is replaced by
nsAppearance accordingly.

Adds ThemeManagerTests covering the AppKit application of all three
modes -- including the Dark -> System regression (override must be
cleared) -- and selection persistence.

* test: restore global appearance state after theme tests

---------

Co-authored-by: momenbasel <momenbasel@users.noreply.github.com>
2026-08-21 12:55:15 +03:00
..
2026-08-21 12:55:15 +03:00