v0.0.4: fix config save silently dropped on real watches - #5
Merged
Conversation
webviewclosed always ran decodeURIComponent on e.response, but the phone app
hands it back already decoded. The moment the payload held a literal % — which
the default strftime_format "%Y-%m-%d" always does — decodeURIComponent threw
"URI malformed", the catch swallowed it, and the whole save was silently
dropped. This is why settings died after the 0.0.2 WYSIWYG change started
sending strftime_format on every save.
Decode like Clay: only decodeURIComponent when the response is still
percent-encoded (an encoded payload starts with %7B, a decoded one with {).
Verified against both delivery modes in the compiled bundle. Also serve the
config page as charset=utf-8 (as Clay does) so accented translations survive.
App version to 0.0.4 (package.json, splash, README, CHANGELOG, PUBLISHING). CONFIG_VERSION unchanged (3.0): the save wire format is the same as 0.0.3.
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
The actual fix for settings not saving on a real watch (0.0.2/0.0.3 never resolved it — wrong diagnosis).
Root cause.
webviewclosedalways randecodeURIComponent(e.response), but the phone app handse.responseback already decoded. As soon as the payload contained a literal%— which the defaultstrftime_format"%Y-%m-%d"always does —decodeURIComponentthrewURIError: URI malformed, the surroundingcatchswallowed it, and the entire save was silently dropped (nothing applied, nothing even written to localStorage). This is exactly why settings worked before and died right after the 0.0.2 WYSIWYG change: WYSIWYG started sendingstrftime_formaton every save, so the%was always present. 0.0.3's payload-size change reduced the close URL but did not touch the real fault.Fix. Decode like Clay (the reference Pebble config framework): only
decodeURIComponentwhen the response is still percent-encoded —raw.match(/^\{/) ? raw : decodeURIComponent(raw). An encoded payload starts with%7B, an already-decoded one with{. Also serve the config page ascharset=utf-8(as Clay does) so accented translation strings survive.The nice custom config page is unchanged — only the decode path is fixed.
Test plan
e.responsedelivered decoded (containing%Y-%m-%d),JSON.parse(decodeURIComponent(...))throwsURIError: URI malformed→ caught → nothing saved. The Clay-style decode parses it correctly.build/pebble-js-app.js, mocked Pebble runtime) for both delivery modes: decoded (real-watch case — previously broken, now 34 keys delivered) and URL-encoded (emulator case — still works).strftime_formatsurvives in both.pebble buildon basalt/diorite/emery/flint; strict-check clean under cloud-Werror.