Honor defaults-write customizations for JSONDefault keys - #1811
Open
YuriNachos wants to merge 1 commit into
Open
Honor defaults-write customizations for JSONDefault keys#1811YuriNachos wants to merge 1 commit into
YuriNachos wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
defaults writecustomizations tosystemWideMouseDownAppsanddoubleClickToolBarIgnoredApps— 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) settypedValue = defaultValuebeforesuper.init(key:)and never calledloadFromJSON(), unlike the already-correctoverride init(key:). So whatever the user persisted for that key was never decoded back;typedValuestayed 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.swift—init(key:defaultValue:)now mirrorsoverride init(key:): callsuper.init(key:)first, thenloadFromJSON()(which decodes the stored UserDefaults JSON intotypedValue, 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 sameUserDefaults.standardsuiteJSONDefaultreads from and cleans up viadefer.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 onmain(cooperative-resize / corner-calculation suites, tracked in issues #1804–#1806); this change adds zero new failures, and the three newJSONDefaultTestspass.AI assistance
This change was developed with AI assistance (Claude Code). Every changed line was reviewed and understood by the contributor.