mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 04:46:57 -04:00
expose meta containing watch and account info in ClayConfig
This commit is contained in:
@@ -607,7 +607,11 @@ This is the main way of talking to your generated config page.
|
||||
|----------|------|-------------|
|
||||
| `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page. |
|
||||
| `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page. |
|
||||
| `.config` | Array | Reference to the config passed to the constructer and used for generating the page. |
|
||||
| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. |
|
||||
| `.meta` | Object | Contains information about the current user and watch |
|
||||
| `.meta.activeWatchInfo` | watchinfo|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
|
||||
|
||||
|
||||
#### Methods
|
||||
|
||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
@@ -11,6 +11,7 @@ var settings = _.extend({}, window.claySettings || {});
|
||||
var returnTo = window.returnTo || 'pebblejs://close#';
|
||||
var customFn = window.customFn || function() {};
|
||||
var clayComponents = window.clayComponents || {};
|
||||
var clayMeta = window.clayMeta || {};
|
||||
|
||||
var platform = window.navigator.userAgent.match(/android/i) ? 'android' : 'ios';
|
||||
document.documentElement.classList.add('platform-' + platform);
|
||||
@@ -21,7 +22,7 @@ _.eachObj(clayComponents, function(key, component) {
|
||||
});
|
||||
|
||||
var $mainForm = $('#main-form');
|
||||
var clayConfig = new ClayConfig(settings, config, $mainForm);
|
||||
var clayConfig = new ClayConfig(settings, config, $mainForm, clayMeta);
|
||||
|
||||
// add listeners here
|
||||
$mainForm.on('submit', function() {
|
||||
|
||||
@@ -26,9 +26,10 @@ var manipulators = require('./manipulators');
|
||||
* @param {Object} settings - setting that were set from a previous session
|
||||
* @param {Array|Object} config
|
||||
* @param {M} $rootContainer
|
||||
* @param {Object} meta
|
||||
* @constructor
|
||||
*/
|
||||
function ClayConfig(settings, config, $rootContainer) {
|
||||
function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
var self = this;
|
||||
|
||||
var _settings = _.copyObj(settings);
|
||||
@@ -95,6 +96,8 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self.meta = meta;
|
||||
|
||||
self.EVENTS = {
|
||||
/**
|
||||
* Called before framework has initialized. This is when you would attach your
|
||||
@@ -183,7 +186,6 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
|
||||
// expose the config to allow developers to update it before the build is run
|
||||
self.config = config;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+25
-1
@@ -10,6 +10,29 @@ var components = require('../src/scripts/components');
|
||||
var componentRegistry = require('../src/scripts/lib/component-registry');
|
||||
var idCounter = 0;
|
||||
|
||||
/**
|
||||
* @returns {{accountToken: string, watchToken: string, activeWatchInfo: {platform:
|
||||
* string, model: string, language: string, firmware: {major: number, minor:
|
||||
* number, patch: number, suffix: string}}}}
|
||||
*/
|
||||
module.exports.meta = function() {
|
||||
return {
|
||||
accountToken: '0123456789abcdef0123456789abcdef',
|
||||
watchToken: '0123456789abcdef0123456789abcdef',
|
||||
activeWatchInfo: {
|
||||
platform: 'chalk',
|
||||
model: 'qemu_platform_chalk',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 3,
|
||||
patch: 2,
|
||||
suffix: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string|Object} config
|
||||
* @param {boolean} [autoRegister=true]
|
||||
@@ -70,7 +93,8 @@ module.exports.clayConfig = function(types, build, autoRegister, settings) {
|
||||
var clayConfig = new ClayConfig(
|
||||
settings || {},
|
||||
module.exports.config(types, autoRegister),
|
||||
$(HTML('<div>'))
|
||||
$(HTML('<div>')),
|
||||
module.exports.meta()
|
||||
);
|
||||
return build === false ? clayConfig : clayConfig.build();
|
||||
};
|
||||
|
||||
@@ -20,12 +20,20 @@ describe('ClayConfig', function() {
|
||||
'build',
|
||||
'on',
|
||||
'off',
|
||||
'trigger'
|
||||
'trigger',
|
||||
'meta'
|
||||
];
|
||||
var clayConfig = fixtures.clayConfig(['input']);
|
||||
checkReadOnly(clayConfig, properties);
|
||||
});
|
||||
|
||||
describe('.meta', function() {
|
||||
it('populates meta', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input']);
|
||||
assert.deepEqual(clayConfig.meta, fixtures.meta());
|
||||
});
|
||||
});
|
||||
|
||||
describe('throws when trying to run methods before being built', function() {
|
||||
[
|
||||
'getItemByAppKey',
|
||||
|
||||
Reference in New Issue
Block a user