mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-29 13:26:59 -04:00
Compare commits
30
Commits
v1.0.0
...
experimental
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae5cc21abb | ||
|
|
df3965ccac | ||
|
|
8d53645a3a | ||
|
|
e328fa8cfa | ||
|
|
ff4f41e63f | ||
|
|
12e335915b | ||
|
|
d12c9a00db | ||
|
|
27a5b77b8a | ||
|
|
1aff0378f5 | ||
|
|
ffd0ba64ec | ||
|
|
74d6d0d21d | ||
|
|
6e6440c9fb | ||
|
|
62f0337198 | ||
|
|
eb89496733 | ||
|
|
5d6e070e01 | ||
|
|
ae31f9737f | ||
|
|
6e42537aa1 | ||
|
|
2b14076171 | ||
|
|
55ac8681af | ||
|
|
b5d2615307 | ||
|
|
6742ec84cf | ||
|
|
61d735662e | ||
|
|
050b89f82f | ||
|
|
1b179a603a | ||
|
|
4a6382aa7f | ||
|
|
f0c44c5719 | ||
|
|
2c2076bf69 | ||
|
|
5a67fec99e | ||
|
|
7cadd5fba4 | ||
|
|
6b59844084 |
+1
-1
@@ -1,4 +1,4 @@
|
||||
# We ignore everying except for what is actually used by the pebble tool.
|
||||
# We ignore everything except for what is actually used by the pebble tool.
|
||||
/**/*
|
||||
!/dist.zip
|
||||
!/src/**/*
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required (VERSION 3.2)
|
||||
project (test-project)
|
||||
|
||||
set(CMAKE_C_FLAGS "-std=c11 -mthumb -ffunction-sections -g -fno-diagnostics-show-caret -D_REENT_SMALL=1 -Wall -Wextra -Werror -Wpointer-arith -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-parameter -Wno-error=unused-but-set-variable -Wno-packed-bitfield-compat -mcpu=cortex-m3 -Os -Werror=return-type")
|
||||
|
||||
file(GLOB_RECURSE src "src/c/*")
|
||||
file(GLOB_RECURSE include "include/*")
|
||||
file(GLOB_RECURSE build "build/basalt/*.c")
|
||||
|
||||
set(SOURCES
|
||||
${src}
|
||||
${build}
|
||||
${include}
|
||||
)
|
||||
|
||||
set(INCLUDES
|
||||
~/Library/Application\ Support/Pebble\ SDK/SDKs/current/sdk-core/pebble/basalt/include
|
||||
./node_modules/pebble-events/dist/include
|
||||
./node_modules/@smallstoneapps/linked-list/dist/include
|
||||
./node_modules/@keegan-stoneware/simple-dict/dist/include
|
||||
./node_modules/@keegan-stoneware/simple-app-message/dist/include
|
||||
./build/include
|
||||
./build
|
||||
./include
|
||||
)
|
||||
|
||||
add_definitions(-DPEBBLE)
|
||||
add_definitions(-DPBL_COLOR)
|
||||
|
||||
include_directories(${INCLUDES})
|
||||
|
||||
add_executable(app ${SOURCES})
|
||||
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
# Contributing
|
||||
|
||||
Thanks for checking out Clay. We accept pull requests from anybody, however we ask
|
||||
that you follow some conventions when contributing to Clay.
|
||||
|
||||
We have set up a
|
||||
[piece-of-cake](https://github.com/pebble/clay/issues?q=is%3Aopen+is%3Aissue+label%3Apiece-of-cake)
|
||||
label in GitHub issues for bugs/features that are easy to implement. These issues are
|
||||
a great place to start for people that are new to the codebase.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Node](https://nodejs.org) (4.0 and later)
|
||||
- [Google Chrome](www.google.com/chrome) (To run tests)
|
||||
- [Pebble SDK](https://developer.pebble.com/sdk/) (optional)
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
### 1. Fork, then clone the repo:
|
||||
|
||||
`$ git clone git@github.com:your-username/clay.git`
|
||||
|
||||
### 2. Create a new branch with the following naming convention.
|
||||
|
||||
`#<issue-id>/description-of-change`
|
||||
|
||||
example:
|
||||
|
||||
`#90/support-message-keys`
|
||||
|
||||
If there is currently no GitHub issue open for your proposed contribution,
|
||||
then please make one. This allows us to assign milestones and triage priority.
|
||||
|
||||
### 3. Install the project dependencies.
|
||||
|
||||
`$ npm install`
|
||||
|
||||
### 4. Develop your feature
|
||||
|
||||
Commit as often as you like. Your branch will be squashed when the pull request is merged.
|
||||
|
||||
### 5. Run the tests
|
||||
|
||||
`$ npm run test`
|
||||
|
||||
### 6. Run linting
|
||||
|
||||
`$ npm run lint`
|
||||
|
||||
### 7. Submit your pull request
|
||||
|
||||
In the main comment of the pull request, you must state the GitHub issue that your PR
|
||||
resolves. You do this by using the syntax `Resolves #<issue-id>`. An example of this
|
||||
can be found [here](https://github.com/pebble/clay/pull/81)
|
||||
|
||||
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
|
||||
## Important Files
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
|
||||
### index.js
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`.
|
||||
It is responsible for serializing the provided config into a data URI that will be opened
|
||||
using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
|
||||
### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page,
|
||||
and is responsible for passing the injected config and other components to the
|
||||
`ClayConfig` class.
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
Use the following command to build Clay during development.
|
||||
|
||||
`$ npm run dev`
|
||||
|
||||
This command packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory
|
||||
so `dev/dev.html` can include them as script tags. This will also watch for changes
|
||||
in the project.
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to
|
||||
work with the files in the `dev/` directory than on a phone or emulator. Below is
|
||||
an explanation of the files and their purpose.
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependencies into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
|
||||
|
||||
## Testing your change inside of a test project.
|
||||
|
||||
Once your change is ready to be tested in the emulator or on the watch, follow these steps:
|
||||
|
||||
1. From your Clay fork run `$ npm run pebble-build`. This builds Clay to work with the Pebble SDK
|
||||
2. From your test Pebble project, run `$ pebble package install /path/to/your/clay/fork`.
|
||||
This will modify your `package.json` to point directly to your local copy of Clay.
|
||||
3. Run the usual`$ pebble build && pebble install --emulator basalt && pebble emu-app-config` to test your modifications
|
||||
4. If you make modifications to your fork of Clay, you must repeat the above steps.
|
||||
|
||||
|
||||
## Functionality
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js`
|
||||
initializes a new instance of `ClayConfig` and calls the injected custom function
|
||||
(`window.customFn`) with the `ClayConfig` as its context. This allows developers to
|
||||
add extra functionality to the config page, such as setting values of items dynamically
|
||||
or registering small custom components.
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over
|
||||
the config and injects each item into the page. Each item is an instance of `ClayItem`.
|
||||
It also indexes the items to later be retrieved with `.getAllItems()`,
|
||||
`.getItemByMessageKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
Clay enforces 100% test coverage. Chances are, that if you are submitting a pull request,
|
||||
there should be tests for the proposed code changes. Have a look at the other tests in
|
||||
the repository to see some examples of how you should be writing your tests.
|
||||
|
||||
There are two commands to use while writing your tests.
|
||||
|
||||
- `$ npm run test` - Runs all tests once.
|
||||
- `$ npm run test-debug` - Watches for file changes and re-runs all tests when it
|
||||
detects a change. This also leaves an in instance of Google Chrome running.
|
||||
If you click the "Debug" button in the top right of the page, a new tab will open.
|
||||
You can then use the Google Chrome developer tools to debug your tests as they run.
|
||||
Refreshing the page will re-run the tests.
|
||||
|
||||
## Style Guide
|
||||
|
||||
Our style guide is very similar to the
|
||||
[Airbnb style guide.](https://github.com/airbnb/javascript/tree/master/es5) with the
|
||||
following exceptions:
|
||||
|
||||
- When saving a reference to `this` use `self`.
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
var _this = this;
|
||||
return function() {
|
||||
console.log(_this);
|
||||
};
|
||||
}
|
||||
|
||||
// bad
|
||||
function() {
|
||||
var that = this;
|
||||
return function() {
|
||||
console.log(that);
|
||||
};
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
var self = this;
|
||||
return function() {
|
||||
console.log(self);
|
||||
};
|
||||
}
|
||||
```
|
||||
- Don't double name your functions. It makes refactoring more difficult.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var log = function log(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
// good
|
||||
var log = function(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
```
|
||||
|
||||
The style guide is enforced using ESLint. Run `$ npm run lint` to ensure you are
|
||||
adhering to the style guide.
|
||||
|
||||
## Getting Help
|
||||
|
||||
- Chat to us in the `#clay` channel on slack. http://slack.pbldev.io/
|
||||
- Visit the [Pebble Forums](https://forums.pebble.com/)
|
||||
- Tweet at [@pebbledev](https://twitter.com/pebbledev)
|
||||
- More options at https://developer.pebble.com/community/online/
|
||||
@@ -1,10 +1,17 @@
|
||||
# Clay
|
||||
# Clay - Experimental
|
||||
|
||||
Welcome to the experimental branch of Clay. Expect this branch to be buggy, with incorrect docs, and with APIs that often change. DO NOT use this branch for your own projets but feel free to provide feedback via the Clay channel at http://discord.gg/aRUAYFN
|
||||
|
||||
---
|
||||
|
||||
Clay is a JavaScript library that makes it easy to add offline configuration pages to your Pebble apps. All you need to get started is a couple lines of JavaScript and a JSON file; no servers or HTML required.
|
||||
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `messageKey` as defined in `appinfo.json` (or PebbleKit JS Message Keys on CloudPebble), and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `messageKey` as defined in `package.json` (or PebbleKit JS Message Keys on CloudPebble), and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
|
||||
Clay is distributed as a [Pebble package](https://developer.pebble.com/guides/pebble-packages/) so it is super easy to include in your project. If you are upgrading from v0.1.x of Clay you need to follow the [migration guide](#migrating-from-v01x-to-v1x) before you can get started.
|
||||
|
||||
If you would like to contribute to Clay, check out the [contributing guide.](CONTRIBUTING.md)
|
||||
|
||||
# Getting Started (SDK 3.13 or higher)
|
||||
|
||||
1. Run `pebble package install pebble-clay` to install the package in your project
|
||||
@@ -786,7 +793,7 @@ Clay will by default, automatically handle the 'showConfiguration' and 'webviewc
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clayConfigAplite = require('./config-aplite');
|
||||
var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
||||
@@ -829,7 +836,7 @@ If you are using [Pebble.js](https://developer.pebble.com/docs/pebblejs/) and wo
|
||||
|
||||
```javascript
|
||||
var Settings = require('settings');
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig, null, {autoHandleEvents: false});
|
||||
|
||||
@@ -899,7 +906,39 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
| `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})` <br> `config` - an Array representing your config <br> `customFn` - function to be run in the context of the generated page <br> `options.autoHandleEvents` - set to `false` to prevent Clay from automatically handling the "showConfiguration" and "webviewclosed" events | `Clay` - a new instance of Clay. |
|
||||
| `.registerComponent( [ClayComponent] component )` <br> Registers a custom component. | `void`. |
|
||||
| `.generateUrl()` | `string` - The URL to open with `Pebble.openURL()` to use the Clay-generated config page. |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. This method will do some conversions depending on the type of the setting. Arrays containing strings will have zeros inserted before each item. eg `['one', 'two']` becomes `['one', 0, 'two', 0]`. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. Pass `false` as the second parameter to disable this behavior |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. <br><br>This method will do some conversions depending on the type of the setting. Arrays will use message key array syntax to make the values of each item in the array available as individual message keys. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. If the value is a number or an array of numbers and the optional property: "precision" is the power of precision (value * 10 ^ precision) and then floored. Eg: `1.4567` with a precision set to `3` will become `1456`. Pass `false` as the second parameter to disable this behavior. See the example below for how this all works |
|
||||
|
||||
#### `.getSettings()` Example
|
||||
|
||||
```javascript
|
||||
|
||||
// webviewclosed response
|
||||
{
|
||||
"favorite_food": {"value": [1, 0, 1]},
|
||||
"cool_things_enabled": {"value": true},
|
||||
"user_name": {"value": "Jane Doe"},
|
||||
"date_of_birth[0]": {"value": 1989},
|
||||
"date_of_birth[1]": {"value": 11},
|
||||
"date_of_birth[2]": {"value": 28},
|
||||
"rating": {"value": 3.5, "precision": 1},
|
||||
}
|
||||
|
||||
// resulting converted values
|
||||
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
messageKeys.favorite_food + 0 = 1;
|
||||
messageKeys.favorite_food + 1 = 0;
|
||||
messageKeys.favorite_food + 2 = 1;
|
||||
messageKeys.cool_things_enabled = 1;
|
||||
messageKeys.user_name = 'Jane Doe';
|
||||
messageKeys.date_of_birth + 0 = 1989;
|
||||
messageKeys.date_of_birth + 1 = 11;
|
||||
messageKeys.date_of_birth + 2 = 28;
|
||||
messageKeys.rating = 35;
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -919,7 +958,7 @@ Make sure to always wait for the config page to be built before manipulating ite
|
||||
##### app.js
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var customClay = require('./custom-clay');
|
||||
var userData = {token: 'abc123'}
|
||||
@@ -1056,7 +1095,7 @@ Components are simple objects with the following properties.
|
||||
Components must be registered before the config page is built. The easiest way to do this is in your `app.js` after you have initialized Clay:
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
|
||||
@@ -1093,56 +1132,6 @@ clay.registerComponent(require('./my-custom-component'));
|
||||
- `_.template()`
|
||||
- `_.isObject()`
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
|
||||
#### index.js
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`. It is responsible for serializing the provided config into a data URI that will be opened using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
|
||||
#### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page, and is responsible for passing the injected config and other components to the `ClayConfig` class.
|
||||
|
||||
|
||||
### Building
|
||||
|
||||
There are two ways to build Clay, production mode and development mode.
|
||||
|
||||
#### Production Mode
|
||||
|
||||
```
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Packages up the entire Clay project into `dist/clay.js` to be required in the developer's `app.js`.
|
||||
|
||||
#### Development Mode
|
||||
|
||||
```
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
Packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory so `dev/dev.html` can include them as script tags. This will also watch for changes in the project.
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to work with the files in the `dev/` directory than on a phone or emulator. Below is an explanation of the files and their purpose.
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependencies into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
|
||||
## Functionality
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js` initializes a new instance of `ClayConfig` and calls the injected custom function (`window.customFn`) with the `ClayConfig` as its context. This allows developers to add extra functionality to the config page, such as setting values of items dynamically or registering small custom components.
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over the config and injects each item into the page. Each item is an instance of `ClayItem`. It also indexes the items to later be retrieved with `.getAllItems()`, `.getItemByMessageKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
|
||||
# Migrating from v0.1.x to v1.x
|
||||
|
||||
There were some changes in the 3.13 SDK that required Clay to undergo some major changes. For the majority of developers a simple find and replace over your config will do the trick.
|
||||
@@ -1176,6 +1165,74 @@ becomes:
|
||||
|
||||
If you have a [custom function](#custom-function) and are using the `clayConfig.getItemByAppKey()` method you will need to change this to `clayConfig.getItemByMessageKey()`
|
||||
|
||||
### clay.getSettings() will now by default, return an object where the keys are numbers.
|
||||
|
||||
In the past, `clay.getSettings()` would return something that looked like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
BACKGROUND_COLOR: 0,
|
||||
NAME: 'Jane Doe',
|
||||
ENABLE_TOOLS: 1
|
||||
}
|
||||
```
|
||||
|
||||
It now uses the values provided in the `message_keys` module to construct this object.
|
||||
The new format looks something like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
```
|
||||
|
||||
If you wish to find out what keys are associated with what values, you must use the `message_keys` module.
|
||||
|
||||
```javascript
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
// Get the keys and values from each config item
|
||||
var claySettings = clay.getSettings(e.response);
|
||||
|
||||
// In this example messageKeys.NAME is equal to 10001
|
||||
console.log('Name is ' + claySettings[messageKeys.NAME]); // Logs: "Name is Jane Doe"
|
||||
});
|
||||
```
|
||||
|
||||
**NOTE:** The above only applies to the default behavior of the method. If you pass
|
||||
`false` to the second argument, a standard object will be returned with the `messageKey`
|
||||
as the key.
|
||||
|
||||
```javascript
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
clay.getSettings(e.response);
|
||||
/* returns:
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
*/
|
||||
|
||||
clay.getSettings(e.response, false);
|
||||
/* returns:
|
||||
{
|
||||
BACKGROUND_COLOR: {value: 0},
|
||||
NAME: {value: 'Jane Doe'},
|
||||
ENABLE_TOOLS: {value: true}
|
||||
}
|
||||
|
||||
Notice that the value for ENABLE_TOOLS was not converted to a number from a boolean
|
||||
*/
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Checkbox groups now use arrays.
|
||||
|
||||
In the previous version of Clay, checkbox groups would split the values of the items with zeros. This made for clumsy usage on the C side. Checkbox groups are now much simpler to use thanks to message keys. You will however need to update you config to the new format.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Ignore build generated files
|
||||
build/
|
||||
dist/
|
||||
dist.zip
|
||||
|
||||
# Ignore waf lock file
|
||||
.lock-waf*
|
||||
|
||||
# Ignore installed node modules
|
||||
node_modules/
|
||||
@@ -0,0 +1,30 @@
|
||||
cmake_minimum_required (VERSION 3.2)
|
||||
project (test-project)
|
||||
|
||||
set(CMAKE_C_FLAGS "-std=c11 -mthumb -ffunction-sections -g -fno-diagnostics-show-caret -D_REENT_SMALL=1 -Wall -Wextra -Werror -Wpointer-arith -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-parameter -Wno-error=unused-but-set-variable -Wno-packed-bitfield-compat -mcpu=cortex-m3 -Os -Werror=return-type")
|
||||
|
||||
file(GLOB_RECURSE src "src/*")
|
||||
file(GLOB_RECURSE build "build/basalt/*.c")
|
||||
|
||||
set(SOURCES
|
||||
${src}
|
||||
${build}
|
||||
)
|
||||
|
||||
set(INCLUDES
|
||||
~/Library/Application\ Support/Pebble\ SDK/SDKs/current/sdk-core/pebble/basalt/include
|
||||
./node_modules/pebble-events/dist/include
|
||||
./node_modules/@keegan-stoneware/simple-dict/dist/include
|
||||
./node_modules/pebble-clay/dist/include
|
||||
./build/include
|
||||
./build
|
||||
./include
|
||||
)
|
||||
|
||||
add_definitions(-DPEBBLE)
|
||||
add_definitions(-DPBL_COLOR)
|
||||
|
||||
include_directories(${INCLUDES})
|
||||
|
||||
add_executable(app ${SOURCES})
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "clay-test",
|
||||
"author": "MakeAwesomeHappen",
|
||||
"version": "1.0.0",
|
||||
"keywords": [
|
||||
"pebble-app"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "./scripts/build.sh"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"pebble-clay": "../"
|
||||
},
|
||||
"pebble": {
|
||||
"displayName": "clay-test",
|
||||
"uuid": "3fff53d2-1b59-48d7-8187-0c2f3674c32d",
|
||||
"sdkVersion": "3",
|
||||
"enableMultiJS": true,
|
||||
"targetPlatforms": [
|
||||
"aplite",
|
||||
"basalt",
|
||||
"chalk",
|
||||
"diorite",
|
||||
"emery"
|
||||
],
|
||||
"watchapp": {
|
||||
"watchface": false
|
||||
},
|
||||
"messageKeys": [],
|
||||
"resources": {
|
||||
"media": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
test_app_folder_name="clay-test"
|
||||
if [ "$(basename $(pwd))" != "$test_app_folder_name" ]; then
|
||||
echo "Must be executed from $test_app_folder_name folder"
|
||||
exit
|
||||
fi
|
||||
|
||||
pebble clean && cd .. && npm run pebble-build || { cd $test_app_folder_name && exit; } && cd $test_app_folder_name && pebble build
|
||||
@@ -0,0 +1,133 @@
|
||||
#include <inttypes.h>
|
||||
#include <pebble.h>
|
||||
#include <pebble-clay/clay.h>
|
||||
|
||||
#define CLAY_INBOX_SIZE (64)
|
||||
#define CHAR_SIZE (10)
|
||||
#define ARRAY_SIZE (3)
|
||||
#define INT_DEFAULT (0xff0000)
|
||||
#define CHAR_DEFAULT ("default")
|
||||
#define BOOL_DEFAULT (false)
|
||||
|
||||
static Window *s_window;
|
||||
static int s_background_color = INT_DEFAULT;
|
||||
static char s_label_char_value[CHAR_SIZE] = CHAR_DEFAULT;
|
||||
static bool s_label_bool_value = BOOL_DEFAULT;
|
||||
static bool s_label_array_value_raw[ARRAY_SIZE] = {true, false, true};
|
||||
static char s_label_array_value[ARRAY_SIZE + 1] = {'0', '0', '0'};
|
||||
static TextLayer *s_label_char;
|
||||
static TextLayer *s_label_bool;
|
||||
static TextLayer *s_label_array;
|
||||
|
||||
static void prv_update_display(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, GColorFromHEX(s_background_color));
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||
|
||||
text_layer_set_text(s_label_char, s_label_char_value);
|
||||
text_layer_set_text(s_label_bool, s_label_bool_value ? "true" : "false");
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE; ++i) {
|
||||
if (s_label_array_value_raw[i]) {
|
||||
s_label_array_value[i] = '1';
|
||||
}
|
||||
}
|
||||
|
||||
text_layer_set_text(s_label_array, s_label_array_value);
|
||||
}
|
||||
|
||||
static void prv_clay_updated_handler(void *context) {
|
||||
clay_get_int("test_int", &s_background_color);
|
||||
clay_get_bool("test_bool", &s_label_bool_value);
|
||||
clay_get_string("test_char", s_label_char_value, CHAR_SIZE);
|
||||
|
||||
layer_mark_dirty(window_get_root_layer(s_window));
|
||||
}
|
||||
|
||||
static void prv_window_unload(Window *window) {
|
||||
layer_destroy(text_layer_get_layer(s_label_char));
|
||||
layer_destroy(text_layer_get_layer(s_label_bool));
|
||||
layer_destroy(text_layer_get_layer(s_label_array));
|
||||
window_destroy(window);
|
||||
}
|
||||
|
||||
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
s_background_color = 0x00ff00;
|
||||
clay_set_int("test_int", &s_background_color);
|
||||
|
||||
s_label_bool_value = true;
|
||||
clay_set_bool("test_bool", &s_label_bool_value);
|
||||
|
||||
strcpy(s_label_char_value, "internal");
|
||||
clay_set_string("test_char", s_label_char_value);
|
||||
|
||||
layer_mark_dirty(window_get_root_layer(s_window));
|
||||
}
|
||||
|
||||
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
s_background_color = INT_DEFAULT;
|
||||
clay_set_int("test_int", &s_background_color);
|
||||
|
||||
s_label_bool_value = BOOL_DEFAULT;
|
||||
clay_set_bool("test_bool", &s_label_bool_value);
|
||||
|
||||
strcpy(s_label_char_value, CHAR_DEFAULT);
|
||||
clay_set_string("test_char", s_label_char_value);
|
||||
|
||||
layer_mark_dirty(window_get_root_layer(s_window));
|
||||
}
|
||||
|
||||
|
||||
static void prv_click_config_provider(void *context) {
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, prv_select_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_UP, prv_up_click_handler);
|
||||
}
|
||||
|
||||
static void prv_window_load(Window *window) {
|
||||
Layer *window_layer = window_get_root_layer(s_window);
|
||||
|
||||
layer_set_update_proc(window_layer, prv_update_display);
|
||||
|
||||
GRect bounds = layer_get_bounds(window_layer);
|
||||
|
||||
s_label_char = text_layer_create(GRect(0, bounds.size.h / 4, bounds.size.w, 30));
|
||||
text_layer_set_text_alignment(s_label_char, GTextAlignmentCenter);
|
||||
text_layer_set_background_color(s_label_char, GColorClear);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_label_char));
|
||||
|
||||
s_label_bool = text_layer_create(GRect(0, bounds.size.h / 2, bounds.size.w, 30));
|
||||
text_layer_set_text_alignment(s_label_bool, GTextAlignmentCenter);
|
||||
text_layer_set_background_color(s_label_bool, GColorClear);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_label_bool));
|
||||
|
||||
s_label_array = text_layer_create(GRect(0, 3 * (bounds.size.h / 4), bounds.size.w, 30));
|
||||
text_layer_set_text_alignment(s_label_array, GTextAlignmentCenter);
|
||||
text_layer_set_background_color(s_label_array, GColorClear);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_label_array));
|
||||
|
||||
prv_clay_updated_handler(NULL);
|
||||
}
|
||||
|
||||
static void prv_init(void) {
|
||||
|
||||
const ClayCallbacks clay_callbacks = {
|
||||
.settings_updated = prv_clay_updated_handler,
|
||||
};
|
||||
|
||||
clay_register_callbacks(&clay_callbacks, NULL);
|
||||
clay_init(CLAY_INBOX_SIZE, true);
|
||||
|
||||
s_window = window_create();
|
||||
window_set_window_handlers(s_window, (WindowHandlers) {
|
||||
.load = prv_window_load,
|
||||
.unload = prv_window_unload,
|
||||
});
|
||||
|
||||
window_set_click_config_provider(s_window, prv_click_config_provider);
|
||||
|
||||
window_stack_push(s_window, true);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
prv_init();
|
||||
app_event_loop();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
var Clay = require('pebble-clay');
|
||||
var clay = new Clay({
|
||||
config: [
|
||||
{
|
||||
type: 'section',
|
||||
items: [
|
||||
{
|
||||
label: 'int',
|
||||
type: 'color',
|
||||
messageKey: 'test_int'
|
||||
},
|
||||
{
|
||||
label: 'char',
|
||||
type: 'input',
|
||||
messageKey: 'test_char'
|
||||
},
|
||||
{
|
||||
label: 'bool',
|
||||
type: 'toggle',
|
||||
messageKey: 'test_bool'
|
||||
},
|
||||
{
|
||||
label: 'array',
|
||||
type: 'checkboxgroup',
|
||||
messageKey: 'test_array',
|
||||
options: ['one', 'two', 'three']
|
||||
},
|
||||
{
|
||||
type: 'submit',
|
||||
defaultValue: 'submit'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
closedCallback: function(response) {
|
||||
console.log('closedcallback: arguments' + JSON.stringify(arguments));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#
|
||||
# This file is the default set of rules to compile a Pebble application.
|
||||
#
|
||||
# Feel free to customize this to your needs.
|
||||
#
|
||||
import os.path
|
||||
import shutil
|
||||
import waflib
|
||||
|
||||
top = '.'
|
||||
out = 'build'
|
||||
|
||||
|
||||
def options(ctx):
|
||||
ctx.load('pebble_sdk')
|
||||
|
||||
|
||||
def distclean(ctx):
|
||||
node_modules_dir = ctx.path.find_node('node_modules')
|
||||
if node_modules_dir:
|
||||
shutil.rmtree(node_modules_dir.abspath())
|
||||
waflib.Scripting.distclean(ctx)
|
||||
|
||||
|
||||
def configure(ctx):
|
||||
"""
|
||||
This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures
|
||||
a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your
|
||||
change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first.
|
||||
Universal configuration: add your change prior to calling ctx.load('pebble_sdk').
|
||||
"""
|
||||
ctx.load('pebble_sdk')
|
||||
|
||||
|
||||
def build(ctx):
|
||||
ctx.load('pebble_sdk')
|
||||
|
||||
build_worker = os.path.exists('worker_src')
|
||||
binaries = []
|
||||
|
||||
cached_env = ctx.env
|
||||
for platform in ctx.env.TARGET_PLATFORMS:
|
||||
ctx.env = ctx.all_envs[platform]
|
||||
ctx.set_group(ctx.env.PLATFORM_NAME)
|
||||
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
|
||||
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), target=app_elf)
|
||||
|
||||
if build_worker:
|
||||
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
|
||||
binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
|
||||
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), target=worker_elf)
|
||||
else:
|
||||
binaries.append({'platform': platform, 'app_elf': app_elf})
|
||||
ctx.env = cached_env
|
||||
|
||||
ctx.set_group('bundle')
|
||||
ctx.pbl_bundle(binaries=binaries,
|
||||
js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']),
|
||||
js_entry_file='src/js/app.js')
|
||||
@@ -12,6 +12,13 @@ module.exports = [
|
||||
"type": "text",
|
||||
"defaultValue": "This is config 2"
|
||||
},
|
||||
{
|
||||
type: 'thing',
|
||||
defaultValue: {
|
||||
en_US: 'foo',
|
||||
fr_FR: 'bar'
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ module.exports = [
|
||||
"messageKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Input Field",
|
||||
"description": "This is a description for the input component. " +
|
||||
"description": "{{i18n.foo}} This is a description for the input component. " +
|
||||
"You can add <strong>html</strong> in here too.",
|
||||
"attributes": {
|
||||
"placeholder": "Placeholder set with attributes"
|
||||
|
||||
@@ -109,6 +109,7 @@ gulp.task('dev-js', ['js', 'sass'], function() {
|
||||
.transform('deamdify')
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
.ignore('message_keys')
|
||||
.bundle()
|
||||
.pipe(source('dev.js'))
|
||||
.pipe(gulp.dest('./tmp/'));
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <@keegan-stoneware/simple-app-message/simple-app-message.h>
|
||||
|
||||
typedef void (*ClayUpdatedCallback)(void *context);
|
||||
|
||||
typedef struct ClayCallbacks {
|
||||
ClayUpdatedCallback settings_updated;
|
||||
} ClayCallbacks;
|
||||
|
||||
void clay_init(uint32_t inbox_size, bool open_app_message);
|
||||
|
||||
void clay_register_callbacks(const ClayCallbacks *callbacks, void *context);
|
||||
|
||||
bool clay_remove(const char *key);
|
||||
|
||||
bool clay_set_bool(const char *key, bool *value);
|
||||
|
||||
bool clay_set_data(const char *key, const void *value, size_t size);
|
||||
|
||||
bool clay_set_int(const char *key, int *value);
|
||||
|
||||
bool clay_set_string(const char *key, const char *value);
|
||||
|
||||
bool clay_get_bool(const char *key, bool *value_out);
|
||||
|
||||
bool clay_get_data(const char *key, void *value_out, size_t size);
|
||||
|
||||
bool clay_get_int(const char *key, int *value_out);
|
||||
|
||||
bool clay_get_string(const char *key, char *value_out, size_t size);
|
||||
@@ -5,34 +5,30 @@ var toSource = require('tosource');
|
||||
var standardComponents = require('./src/scripts/components');
|
||||
var deepcopy = require('deepcopy/build/deepcopy.min');
|
||||
var version = require('./package.json').version;
|
||||
var messageKeys = require('message_keys');
|
||||
var simpleAppMessage = require('@keegan-stoneware/simple-app-message');
|
||||
var utils = require('./src/scripts/lib/utils');
|
||||
|
||||
/**
|
||||
* @param {Array} config - the Clay config
|
||||
* @param {function} [customFn] - Custom code to run from the config page. Will run
|
||||
* with the ClayConfig instance as context
|
||||
* @param {Object} [options] - Additional options to pass to Clay
|
||||
* @param {boolean} [options.autoHandleEvents=true] - If false, Clay will not
|
||||
* automatically handle the 'showConfiguration' and 'webviewclosed' events
|
||||
* @param {*} [options.userData={}] - Arbitrary data to pass to the config page. Will
|
||||
* be available as `clayConfig.meta.userData`
|
||||
* @param {Object} options - Clay options
|
||||
* @param {Array} [options.config] - The config
|
||||
* @param {function} [options.openCallback]
|
||||
* @param {function} [options.closedCallback]
|
||||
* @param {Object} [options.locales]
|
||||
* @param {function} [options.customFunction] - Custom code to run from the config
|
||||
* page. Will run with the ClayConfig instance as context
|
||||
* @constructor
|
||||
*/
|
||||
function Clay(config, customFn, options) {
|
||||
function Clay(options) {
|
||||
var self = this;
|
||||
|
||||
if (!Array.isArray(config)) {
|
||||
throw new Error('config must be an Array');
|
||||
if (!options) {
|
||||
utils.throw('You must define options');
|
||||
}
|
||||
|
||||
if (customFn && typeof customFn !== 'function') {
|
||||
throw new Error('customFn must be a function or "null"');
|
||||
}
|
||||
options = deepcopy(options);
|
||||
|
||||
options = options || {};
|
||||
|
||||
self.config = deepcopy(config);
|
||||
self.customFn = customFn || function() {};
|
||||
self.config = options.config;
|
||||
self.customFn = options.customFn || function() {};
|
||||
self.components = {};
|
||||
self.meta = {
|
||||
activeWatchInfo: null,
|
||||
@@ -57,30 +53,30 @@ function Clay(config, customFn, options) {
|
||||
}
|
||||
|
||||
// Let Clay handle all the magic
|
||||
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
|
||||
Pebble.addEventListener('showConfiguration', function() {
|
||||
_populateMeta();
|
||||
Pebble.openURL(self.generateUrl());
|
||||
});
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function() {
|
||||
_populateMeta();
|
||||
Pebble.openURL(self.generateUrl());
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
if (!e || !e.response) { return; }
|
||||
|
||||
var settings = self.getSettings(e.response, false);
|
||||
|
||||
if (options.closedCallback) {
|
||||
options.closedCallback(settings);
|
||||
}
|
||||
|
||||
simpleAppMessage.send('CLAY', settings, function(response) {
|
||||
if (response.error) {
|
||||
utils.log('Failed to send config data!');
|
||||
utils.log(response.error);
|
||||
} else {
|
||||
utils.log('Sent config data to Pebble');
|
||||
}
|
||||
});
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
if (!e || !e.response) { return; }
|
||||
|
||||
// Send settings to Pebble watchapp
|
||||
Pebble.sendAppMessage(self.getSettings(e.response), function() {
|
||||
console.log('Sent config data to Pebble');
|
||||
}, function(error) {
|
||||
console.log('Failed to send config data!');
|
||||
console.log(JSON.stringify(error));
|
||||
});
|
||||
});
|
||||
} else if (typeof Pebble !== 'undefined') {
|
||||
Pebble.addEventListener('ready', function() {
|
||||
_populateMeta();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* If this function returns true then the callback will be executed
|
||||
@@ -195,9 +191,10 @@ Clay.prototype.getSettings = function(response, convert) {
|
||||
try {
|
||||
settings = JSON.parse(response);
|
||||
} catch (e) {
|
||||
throw new Error('The provided response was not valid JSON');
|
||||
utils.error('The provided response was not valid JSON');
|
||||
}
|
||||
|
||||
// @todo do something with the persist flag here
|
||||
// flatten the settings for localStorage
|
||||
var settingsStorage = {};
|
||||
Object.keys(settings).forEach(function(key) {
|
||||
@@ -210,9 +207,7 @@ Clay.prototype.getSettings = function(response, convert) {
|
||||
|
||||
localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
|
||||
|
||||
return convert === false ?
|
||||
settings :
|
||||
Clay.prepareSettingsForAppMessage(settings, messageKeys);
|
||||
return convert === false ? settingsStorage : Clay.prepareSettingsForAppMessage(settings);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -230,8 +225,8 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Strings will be returned without modification
|
||||
* - Numbers will be returned without modification
|
||||
* - Booleans will be converted to a 0 or 1
|
||||
* - Arrays that contain strings will be split with a zero.
|
||||
* eg: ['one', 'two'] becomes ['one', 0, 'two', 0]
|
||||
* - Arrays that contain strings will be returned without modification
|
||||
* eg: ['one', 'two'] becomes ['one', 'two']
|
||||
* - Arrays that contain numbers will be returned without modification
|
||||
* eg: [1, 2] becomes [1, 2]
|
||||
* - Arrays that contain booleans will be converted to a 0 or 1
|
||||
@@ -239,7 +234,7 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Arrays must be single dimensional
|
||||
* - Objects that have a "value" property will apply the above rules to the type of
|
||||
* value. If the value is a number or an array of numbers and the optional
|
||||
* property: "precision" is provided, then the number will be multipled by 10 to
|
||||
* property: "precision" is provided, then the number will be multiplied by 10 to
|
||||
* the power of precision (value * 10 ^ precision) and then floored.
|
||||
* Eg: 1.4567 with a precision set to 3 will become 1456
|
||||
* @param {number|string|boolean|Array|Object} val
|
||||
@@ -323,24 +318,26 @@ Clay.prepareSettingsForAppMessage = function(settings) {
|
||||
|
||||
var result = {};
|
||||
Object.keys(flatSettings).forEach(function(key) {
|
||||
var messageKey = messageKeys[key];
|
||||
var settingArr = Clay.prepareForAppMessage(flatSettings[key]);
|
||||
settingArr = Array.isArray(settingArr) ? settingArr : [settingArr];
|
||||
// var messageKey = messageKeys[key];
|
||||
// var settingArr = Clay.prepareForAppMessage(flatSettings[key]);
|
||||
// settingArr = Array.isArray(settingArr) ? settingArr : [settingArr];
|
||||
//
|
||||
// settingArr.forEach(function(setting, index) {
|
||||
// result[messageKey + index] = setting;
|
||||
// });
|
||||
|
||||
settingArr.forEach(function(setting, index) {
|
||||
result[messageKey + index] = setting;
|
||||
});
|
||||
result[key] = Clay.prepareForAppMessage(flatSettings[key]);
|
||||
});
|
||||
|
||||
// validate the settings
|
||||
Object.keys(result).forEach(function(key) {
|
||||
if (Array.isArray(result[key])) {
|
||||
throw new Error('Clay does not support 2 dimensional arrays for item ' +
|
||||
'values. Make sure you are not attempting to use array ' +
|
||||
'syntax (eg: "myMessageKey[2]") in the messageKey for ' +
|
||||
'components that return an array, such as a checkboxgroup');
|
||||
}
|
||||
});
|
||||
// Object.keys(result).forEach(function(key) {
|
||||
// if (Array.isArray(result[key])) {
|
||||
// throw new Error('Clay does not support 2 dimensional arrays for item ' +
|
||||
// 'values. Make sure you are not attempting to use array ' +
|
||||
// 'syntax (eg: "myMessageKey[2]") in the messageKey for ' +
|
||||
// 'components that return an array, such as a checkboxgroup');
|
||||
// }
|
||||
// });
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
+8
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pebble-clay",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.2",
|
||||
"description": "Pebble Config Framework",
|
||||
"scripts": {
|
||||
"test-travis": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run --browsers chromeTravisCI && ./node_modules/.bin/eslint ./",
|
||||
@@ -40,7 +40,10 @@
|
||||
],
|
||||
"resources": {
|
||||
"media": []
|
||||
}
|
||||
},
|
||||
"capabilities": [
|
||||
"configurable"
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/pebble/clay#readme",
|
||||
"devDependencies": {
|
||||
@@ -84,5 +87,7 @@
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"watchify": "^3.7.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"@keegan-stoneware/simple-app-message": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "clay.h"
|
||||
#include "hash.h"
|
||||
|
||||
#define SIMPLE_APP_MESSAGE_NAMESPACE ("CLAY")
|
||||
|
||||
static ClayCallbacks s_callbacks;
|
||||
|
||||
static uint32_t prv_hash_key(const char *key) {
|
||||
return hash((uint8_t *)key, (uint32_t)strlen(key));
|
||||
}
|
||||
|
||||
static bool prv_read(const char *key, void *value_out, size_t size) {
|
||||
uint32_t persist_key = prv_hash_key(key);
|
||||
int bytes_read = persist_read_data(persist_key, value_out, size);
|
||||
return bytes_read >= 0 && (size_t)bytes_read == size;
|
||||
}
|
||||
|
||||
static bool prv_write(const char *key, const void *data, size_t size) {
|
||||
uint32_t persist_key = prv_hash_key(key);
|
||||
int bytes_written = persist_write_data(persist_key, data, size);
|
||||
return bytes_written >= 0 && (size_t)bytes_written == size;
|
||||
}
|
||||
|
||||
static bool prv_simple_dict_foreach_callback(
|
||||
const char *key, SimpleDictDataType type, const void *data, size_t size, void *context) {
|
||||
return prv_write(key, data, size);
|
||||
}
|
||||
|
||||
static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) {
|
||||
if (!message) return;
|
||||
|
||||
simple_dict_foreach(message, prv_simple_dict_foreach_callback, NULL);
|
||||
s_callbacks.settings_updated(context);
|
||||
}
|
||||
|
||||
// ----- PUBLIC API -----
|
||||
|
||||
void clay_init(uint32_t inbox_size, bool open_app_message) {
|
||||
const bool request_inbox_size_success = simple_app_message_request_inbox_size(inbox_size);
|
||||
if (!request_inbox_size_success) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to request inbox size of %d", (int)inbox_size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!open_app_message) return;
|
||||
|
||||
const AppMessageResult open_state = simple_app_message_open();
|
||||
if (open_state != APP_MSG_OK) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to open appmessage inbox. Code: %d", open_state);
|
||||
}
|
||||
}
|
||||
|
||||
void clay_register_callbacks(const ClayCallbacks *callbacks, void *context) {
|
||||
s_callbacks = *callbacks;
|
||||
|
||||
const SimpleAppMessageCallbacks simple_app_message_callbacks = {
|
||||
.message_received = prv_simple_app_message_received_callback,
|
||||
};
|
||||
const bool register_success = simple_app_message_register_callbacks(
|
||||
SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context);
|
||||
|
||||
if (!register_success) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to register callbacks for namespace %s",
|
||||
SIMPLE_APP_MESSAGE_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
bool clay_get_int(const char *key, int *value_out) {
|
||||
return prv_read(key, value_out, sizeof(*value_out));
|
||||
}
|
||||
|
||||
bool clay_get_bool(const char *key, bool *value_out) {
|
||||
return prv_read(key, value_out, sizeof(*value_out));
|
||||
}
|
||||
|
||||
bool clay_get_string(const char *key, char *value_out, size_t size) {
|
||||
return prv_read(key, value_out, size);
|
||||
}
|
||||
|
||||
bool clay_get_data(const char *key, void *value_out, size_t size) {
|
||||
return prv_read(key, value_out, size);
|
||||
}
|
||||
|
||||
bool clay_set_int(const char *key, int *value) {
|
||||
return prv_write(key, value, sizeof(value));
|
||||
}
|
||||
|
||||
bool clay_set_bool(const char *key, bool *value) {
|
||||
return prv_write(key, value, sizeof(value));
|
||||
}
|
||||
|
||||
bool clay_set_data(const char *key, const void *value, size_t size) {
|
||||
return prv_write(key, value, size);
|
||||
}
|
||||
|
||||
bool clay_set_string(const char *key, const char *value) {
|
||||
return prv_write(key, value, strlen(value));
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "hash.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Based on DJB2 Hash
|
||||
uint32_t hash(const uint8_t *bytes, const uint32_t length) {
|
||||
uint32_t hash = 5381;
|
||||
|
||||
if (length == 0) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint8_t c;
|
||||
const uint8_t *last_byte = bytes + length;
|
||||
while (bytes != last_byte) {
|
||||
c = *bytes;
|
||||
hash = ((hash << 5) + hash) + c;
|
||||
bytes++;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t hash(const uint8_t *bytes, const uint32_t length);
|
||||
@@ -116,12 +116,13 @@ module.exports = {
|
||||
function autoLayout() {
|
||||
if (!clay.meta.activeWatchInfo ||
|
||||
clay.meta.activeWatchInfo.firmware.major === 2 ||
|
||||
clay.meta.activeWatchInfo.platform === 'aplite' &&
|
||||
['aplite', 'diorite'].indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
!self.config.allowGray) {
|
||||
return standardLayouts.BLACK_WHITE;
|
||||
}
|
||||
|
||||
if (clay.meta.activeWatchInfo.platform === 'aplite' && self.config.allowGray) {
|
||||
if (['aplite', 'diorite'].indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
self.config.allowGray) {
|
||||
return standardLayouts.GRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,3 +133,11 @@ module.exports.includesCapability = function(activeWatchInfo, capabilities) {
|
||||
|
||||
return result.indexOf(false) === -1;
|
||||
};
|
||||
|
||||
module.exports.log = function(message) {
|
||||
console.log('Clay: ' + JSON.stringify(message));
|
||||
};
|
||||
|
||||
module.exports.throw = function(error) {
|
||||
throw new Error('Clay: '+ error)
|
||||
};
|
||||
|
||||
@@ -434,6 +434,28 @@ describe('component - color', function() {
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.BLACK_WHITE, false, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.GRAY, true, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
|
||||
testCustomLayout();
|
||||
testCustomLayout('COLOR');
|
||||
|
||||
Reference in New Issue
Block a user