Skip to content

Honor defaults-write customizations for JSONDefault keys - #1811

Open
YuriNachos wants to merge 1 commit into
rxhanson:mainfrom
YuriNachos:YuriNachos/w4-rectangle-defaults
Open

Honor defaults-write customizations for JSONDefault keys#1811
YuriNachos wants to merge 1 commit into
rxhanson:mainfrom
YuriNachos:YuriNachos/w4-rectangle-defaults

Conversation

@YuriNachos

Copy link
Copy Markdown

Summary

defaults write customizations to systemWideMouseDownApps and doubleClickToolBarIgnoredApps — the only two settings with no in-app UI — are now honored. Today they are silently ignored.

Root cause

JSONDefault.init(key:defaultValue:) (Defaults.swift) set typedValue = defaultValue before super.init(key:) and never called loadFromJSON(), unlike the already-correct override init(key:). So whatever the user persisted for that key was never decoded back; typedValue stayed at the default forever. The two keys above are the only consumers of this initializer, so the bug was invisible everywhere else.

Changes

  • Rectangle/Defaults.swiftinit(key:defaultValue:) now mirrors override init(key:): call super.init(key:) first, then loadFromJSON() (which decodes the stored UserDefaults JSON into typedValue, falling back to the default when the stored value is absent or invalid). override init(key:) is unchanged.
  • RectangleTests/JSONDefaultTests.swift (new) — three pure-logic tests: a stored JSON value is honored over the default (RED before / GREEN after), a missing value falls back to the default, and invalid JSON falls back to the default. Each writes to the same UserDefaults.standard suite JSONDefault reads from and cleans up via defer.

Testing

xcodebuild test -project Rectangle.xcodeproj -scheme Rectangle -destination 'platform=macOS'208 tests, 21 failures (0 unexpected). The 21 failures are the pre-existing red baseline on main (cooperative-resize / corner-calculation suites, tracked in issues #1804#1806); this change adds zero new failures, and the three new JSONDefaultTests pass.

AI assistance

This change was developed with AI assistance (Claude Code). Every changed line was reviewed and understood by the contributor.

JSONDefault.init(key:defaultValue:) set typedValue = defaultValue before
super.init and never called loadFromJSON(), so a value the user persisted
via `defaults write` (the only way to customize systemWideMouseDownApps and
doubleClickToolBarIgnoredApps — there is no in-app UI) was silently ignored
and the default was always used. Mirror override init(key:): call
super.init(key:), then loadFromJSON(), then fall back to the default only
when nothing valid is stored. Adds RectangleTests/JSONDefaultTests.swift.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant