Repository navigation
Refuse a persistAs key another toggle already remembers [patch] - #60
Merged
Merged
Conversation
Two toggles given the same persistAs key shared one remembered value: each click overwrote it, and the next launch restored both toggles to it, running both real setters with the wrong state. Toggle now throws ArgumentException (param persistAs) for a key another toggle already uses, compared ordinally to match the store, and for an empty or white-space key. This is the preference-key counterpart of the alias-clash checks from #18. Fixes #37 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3e2AZDcKPKkvjAga2
|
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.



Fixes #37
What was wrong
TrayAppBuilder.Toggle(..., persistAs:)never checked the key against the toggles already added. Preferences live in one flat dictionary, so two toggles sharing a key overwrote each other on every click. On the next launch,LoadPreferencesrestored both toggles to whichever value was stored, and each restore runs the toggle's real setter.Change
TogglethrowsArgumentException(ParamName == "persistAs") when another toggle already uses the key. The comparison is ordinal, to match the store.Tests
The new tests sit next to the #18 alias-clash tests in
TrayAppBuilderTests:Toggle_WithAPersistAsKeyAnotherToggleTook_Throws: checks the message, the param name, and that the builder still holds one toggle.Toggle_WithABlankPersistAsKey_Throwscovers""and" ".Toggle_WithPersistAsKeysThatDifferOnlyInCase_KeepsBoth:awake/Awakeand two unremembered toggles are all accepted.The first two fail on
main(3 cases) and pass with the fix. Full suite: 164 passed, 1 skipped, 0 failed.Generated by Claude Code