Add missing settings to an existing config file - #14
Merged
Conversation
The template every new install gets lists every setting, which is how `tap_to_toggle` is meant to be discovered — but ensureFileExists returns early when the file is there, so anyone upgrading kept a config with no line for it. Clicking "Edit config…" opened a file that hid half the settings, and the README was the only way to learn they existed. The daemon now backfills the missing defaults at startup, and again right before "Edit config…" opens the file. Values already set are untouched, keys yap has never heard of are left alone, and insertion is textual so the file keeps its own formatting; missing keys land where the template lists them rather than wherever the alphabet puts them. It declines rather than forcing it. A section written on one line has nowhere to put a line, so a compact hand-written config keeps its formatting and its missing keys. And every rewrite is verified before it lands: the new text has to parse, and it has to differ from what was there by exactly the defaults being added, or the file is left alone. Verified against six fixtures under a faux HOME: a stale real-shape config gains the key with formatting intact; a config with no dictation object gets the whole section, indented like the template; a compact one-liner is left byte-identical; unknown keys survive; malformed JSON is untouched; and a complete config is never written at all — same mtime.
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.
The template a new install gets lists every setting — that is how a config-only feature like
tap_to_toggleis meant to be discovered. ButensureFileExistsreturns early when the file is already there, so anyone who upgrades keeps a config with no line for anything added since. "Edit config…" opens a file that hides half the settings, and the README becomes the only way to learn they exist.The daemon now backfills missing defaults at startup, and again immediately before "Edit config…" opens the file.
What it will and will not do
Verification
Six fixtures, each run through the real daemon under a faux
HOME(CFFIXED_USER_HOME), so nothing touched a real config:tap_to_togglemissingdictationobject at all{ "dictation": { "hotkey": "right_option" }, … }my_own_note,dictation.future_key)Also two cosmetic fixes to Foundation's pretty printer so a generated section reads like the template next to it:
"key" : value→"key": value, and slashes are no longer escaped (~\/Recordings→~/Recordings). Neither can corrupt anything, because the result is parsed and compared before it is written.No measured path changes: one file read and parse at daemon start, and a write only when a key is actually missing.