mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 04:46:57 -04:00
extract watchinfo etc from Pebble object
This commit is contained in:
@@ -29,11 +29,13 @@ function Clay(config, customFn, options) {
|
||||
self.config = config;
|
||||
self.customFn = customFn || function() {};
|
||||
self.components = {};
|
||||
self.meta = {};
|
||||
|
||||
// Let Clay handle all the magic
|
||||
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function() {
|
||||
_populateMeta();
|
||||
Pebble.openURL(self.generateUrl());
|
||||
});
|
||||
|
||||
@@ -49,6 +51,23 @@ function Clay(config, customFn, options) {
|
||||
console.log(JSON.stringify(error));
|
||||
});
|
||||
});
|
||||
} else if (typeof Pebble !== 'undefined') {
|
||||
Pebble.addEventListener('ready', function() {
|
||||
_populateMeta();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the meta with data from the Pebble object. Make sure to run this inside
|
||||
* either the "showConfiguration" or "ready" event handler
|
||||
* @return {void}
|
||||
*/
|
||||
function _populateMeta() {
|
||||
self.meta = !Pebble ? {} : {
|
||||
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
|
||||
accountToken: Pebble.getAccountToken(),
|
||||
watchToken: Pebble.getWatchToken()
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +126,8 @@ Clay.prototype.generateUrl = function() {
|
||||
.replace('$$CUSTOM_FN$$', toSource(this.customFn))
|
||||
.replace('$$CONFIG$$', toSource(this.config))
|
||||
.replace('$$SETTINGS$$', toSource(settings))
|
||||
.replace('$$COMPONENTS$$', toSource(this.components));
|
||||
.replace('$$COMPONENTS$$', toSource(this.components))
|
||||
.replace('$$META$$', toSource(this.meta));
|
||||
|
||||
// if we are in the emulator then we need to proxy the data via a webpage to
|
||||
// obtain the return_to.
|
||||
|
||||
Reference in New Issue
Block a user