Pebble.openURL with previously-saved configuration


#1

I am adding configuration to a watchface, and have got the saving of configuration working in the Pebble.js “webviewclosed” handler. When I re-launch the configuration URL using Pebble.openURL, I append the encoded JSON as a hash value, like this:

Pebble.addEventListener(‘showConfiguration’, function(e) {
// Show config page, URLs are indicative
if (jsonConfig) {
Pebble.openURL(‘http://deployed-site.com/pebble/watchface-config#’ + encodeURIComponent(jsonConfig));
} else {
Pebble.openURL(‘http://deployed-site.com/pebble/watchface-config’);
}
});
In the emulator, I notice that the opened URL is actually
http://deployed-site.com/pebble/watchface-config#{“isDateShown”%3Atrue%2C"isAnimated"%3Atrue}?return_to=https%3A//cloudpebble.net/ide/emulator/config%3F#{“isDateShown”%3Atrue%2C"isAnimated"%3Atrue}
instead of
http://deployed-site.com/pebble/watchface-config#{“isDateShown”%3Atrue%2C"isAnimated"%3Atrue}?return_to=https%3A//cloudpebble.net/ide/emulator/config%3F
I couldn’t find any documentation of Pebble.openURL beyond the example provided in http://developer.getpebble.com/guides/js-apps/pebblekit-js/app-configuration. Does this accept any optional extra parameter for additional query string arguments or hash components? Why is the extra copy of the hash component appended to the end of the URL?
If I remove the appended JSON fragment (as in the ‘else’ branch, in case openURL adds this JSON by magic), the default URL is launched without any configuration:
http://deployed-site.com/pebble/watchface-config?return_to=https%3A//cloudpebble.net/ide/emulator/config%3F
How can I get this URL loaded reliably?
Many thanks.










#2

When you are using the emulator in CloudPebble, in order to send results from a config page back to the PebbleKit JS app, we have to use a special page (as opposed to pebblejs://close#). The details on how to use it are in this blog post: https://developer.getpebble.com/blog/2015/01/22/cloudpebble-pebble-emulator/

We are actively working on documenting this better on the site so people are more aware of it.

There is however a known bug with this return_to parameter (https://github.com/pebble/cloudpebble/issues/124) that you are encountering.


#3

Thanks, my JavaScript on the hosted webpage is already detecting the return_to query string parameter and redirecting back to https://cloudpebble.net/ide/emulator/config? instead of pebblejs://close#. This question was more about launching the hosted webpage from Pebble.js when additional parameters need to be supplied.


#4

I’ve figured out a workaround. Turns out that I need to use query string parameters for passing custom data to my hosted page, not hash URL components. Fortunately, Pebble.openURL() is smart enough to check my URL passed in for any query string and augment the URL correctly.
So now my URL passed in:

Pebble.openURL('http://deployed-site.com/pebble/watchface-config?cfg=' + encodeURIComponent(jsonConfig));
correctly gets rewritten to:
http://deployed-site.com/pebble/watchface-config?cfg={%22isDateShown%22%3Atrue%2C%22isAnimated%22%3Atrue}&return_to=https%3A//cloudpebble.net/ide/emulator/config%3F
instead of a more naive (note the second question mark):
http://deployed-site.com/pebble/watchface-config?cfg={%22isDateShown%22%3Atrue%2C%22isAnimated%22%3Atrue}?return_to=https%3A//cloudpebble.net/ide/emulator/config%3F
That satisfies my needs. Thanks.

#5