Clean up example and re-enable localstorage saving

This commit is contained in:
Keegan
2016-10-25 03:11:38 -07:00
parent 6e6440c9fb
commit 74d6d0d21d
2 changed files with 16 additions and 35 deletions
+6 -25
View File
@@ -5,33 +5,25 @@
#define CLAY_INBOX_SIZE (64)
static Window *s_window;
static int s_background_color;
static int s_background_color = 0xff0000;
static void draw_background(Layer *layer, GContext *ctx) {
static void prv_update_layer(Layer *layer, GContext *ctx) {
graphics_context_set_fill_color(ctx, GColorFromHEX(s_background_color));
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
}
static void prv_update_layer(Layer *layer, GContext *ctx) {
draw_background(layer, ctx);
static void prv_clay_updated_handler(void *context) {
clay_get_int("test_int", &s_background_color);
layer_mark_dirty(window_get_root_layer(s_window));
}
static void prv_window_unload(Window *window) {
window_destroy(window);
}
static void prv_window_load(Window *window) {
layer_set_update_proc(window_get_root_layer(s_window), prv_update_layer);
}
static void prv_clay_updated_handler(void *context) {
int value_int;
if (clay_get_int("test_int", &value_int)) {
s_background_color = value_int;
}
layer_mark_dirty(window_get_root_layer(s_window));
prv_clay_updated_handler(NULL);
}
static void prv_init(void) {
@@ -56,14 +48,3 @@ int main(void) {
prv_init();
app_event_loop();
}
//int s_background_color = 0xffffff;
//#define TEXT_SIZE 20;
//char s_text [TEXT_SIZE];
//
//void clay_update_handler(void *ctx) {
// clay_get_int("background_color", &s_background_color);
// clay_get_string("background_color", &s_text, TEXT_SIZE - 1);
//}
+10 -10
View File
@@ -196,16 +196,16 @@ Clay.prototype.getSettings = function(response, convert) {
// @todo do something with the persist flag here
// flatten the settings for localStorage
// var settingsStorage = {};
// Object.keys(settings).forEach(function(key) {
// if (typeof settings[key] === 'object' && settings[key]) {
// settingsStorage[key] = settings[key].value;
// } else {
// settingsStorage[key] = settings[key];
// }
// });
//
// localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
var settingsStorage = {};
Object.keys(settings).forEach(function(key) {
if (typeof settings[key] === 'object' && settings[key]) {
settingsStorage[key] = settings[key].value;
} else {
settingsStorage[key] = settings[key];
}
});
localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
return convert === false ? settings : Clay.prepareSettingsForAppMessage(settings);
};