Allow easier emu testing; clean up unconfigured state logic
This commit is contained in:
55
src/c/main.c
55
src/c/main.c
@@ -3,6 +3,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// #define DEBUG_MODE 1
|
||||
|
||||
// declare settings-derived statics
|
||||
static uint8_t s_is_jellyfin;
|
||||
static GColor s_color_primary = GColorWhite;
|
||||
@@ -81,13 +83,9 @@ static void pin_icon_update_proc(Layer *layer, GContext *ctx) {
|
||||
}
|
||||
|
||||
static void main_window_load(Window *window) {
|
||||
// sleep bar and icon
|
||||
s_sleep_bar_layer = layer_create(s_sleep_bar_start);
|
||||
s_sleep_icon_layer = layer_create(s_sleep_icon_start);
|
||||
|
||||
if (s_is_jellyfin > 0) { // display help instead of sleep icon if app is unconfigured
|
||||
layer_set_update_proc(s_sleep_icon_layer, sleep_icon_update_proc);
|
||||
} else {
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
if (s_is_jellyfin == 0) {
|
||||
window_set_background_color(window, GColorWhite);
|
||||
#if PBL_DISPLAY_WIDTH >= 200
|
||||
s_config_app_layer = text_layer_create(GRect(4, (PBL_DISPLAY_HEIGHT / 2) - PBL_IF_ROUND_ELSE(33, 49), PBL_DISPLAY_WIDTH - 8, PBL_DISPLAY_HEIGHT));
|
||||
text_layer_set_font(s_config_app_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
|
||||
@@ -95,10 +93,18 @@ static void main_window_load(Window *window) {
|
||||
s_config_app_layer = text_layer_create(GRect(4, (PBL_DISPLAY_HEIGHT / 2) - PBL_IF_ROUND_ELSE(43, 32), PBL_DISPLAY_WIDTH - 8, PBL_DISPLAY_HEIGHT));
|
||||
text_layer_set_font(s_config_app_layer, fonts_get_system_font(PBL_IF_ROUND_ELSE(FONT_KEY_GOTHIC_24_BOLD, FONT_KEY_GOTHIC_18_BOLD)));
|
||||
#endif
|
||||
text_layer_set_background_color(s_config_app_layer, GColorClear);
|
||||
text_layer_set_text(s_config_app_layer, "Please configure the app's settings from your phone");
|
||||
text_layer_set_text_alignment(s_config_app_layer, GTextAlignmentCenter);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_config_app_layer));
|
||||
return;
|
||||
}
|
||||
|
||||
// sleep bar and icon
|
||||
s_sleep_bar_layer = layer_create(s_sleep_bar_start);
|
||||
s_sleep_icon_layer = layer_create(s_sleep_icon_start);
|
||||
layer_set_update_proc(s_sleep_icon_layer, sleep_icon_update_proc);
|
||||
|
||||
// pin icon
|
||||
s_pin_icon_layer = layer_create(GRect(PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(27, 25), (PBL_DISPLAY_HEIGHT / 2) - 13, 25, 25));
|
||||
layer_set_update_proc(s_pin_icon_layer, pin_icon_update_proc);
|
||||
@@ -143,7 +149,6 @@ static void main_window_load(Window *window) {
|
||||
}
|
||||
|
||||
// add layers as children to windows
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
#if PBL_ROUND
|
||||
text_layer_set_text_alignment(s_last_watched_layer, GTextAlignmentCenter);
|
||||
#else
|
||||
@@ -157,22 +162,26 @@ static void main_window_load(Window *window) {
|
||||
layer_add_child(window_layer, s_sleep_bar_layer);
|
||||
layer_add_child(window_layer, s_sleep_icon_layer);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_layer));
|
||||
if (s_is_jellyfin == 0) {
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_config_app_layer));
|
||||
}
|
||||
}
|
||||
|
||||
static void main_window_unload(Window *window) {
|
||||
pin_animation_deinit();
|
||||
text_layer_destroy(s_last_watched_layer);
|
||||
text_layer_destroy(s_sleep_time_layer);
|
||||
layer_destroy(s_sleep_icon_layer);
|
||||
layer_destroy(s_sleep_bar_layer);
|
||||
layer_destroy(s_pin_icon_layer);
|
||||
layer_destroy(s_button_bar_layer);
|
||||
if (s_is_jellyfin == 0) {
|
||||
text_layer_destroy(s_config_app_layer);
|
||||
} else {
|
||||
pin_animation_deinit();
|
||||
text_layer_destroy(s_last_watched_layer);
|
||||
text_layer_destroy(s_sleep_time_layer);
|
||||
layer_destroy(s_sleep_icon_layer);
|
||||
layer_destroy(s_sleep_bar_layer);
|
||||
layer_destroy(s_pin_icon_layer);
|
||||
layer_destroy(s_button_bar_layer);
|
||||
}
|
||||
}
|
||||
|
||||
static void send_sleep_time_to_pkjs() {
|
||||
if (s_is_jellyfin == 0) {
|
||||
return;
|
||||
}
|
||||
DictionaryIterator *out;
|
||||
AppMessageResult result = app_message_outbox_begin(&out);
|
||||
if (result != APP_MSG_OK) {
|
||||
@@ -293,10 +302,14 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
}
|
||||
|
||||
static void init() {
|
||||
// set colors if is_jellyfin is locally set;
|
||||
// if it has not yet been set, it will be once
|
||||
// the user saves their settings
|
||||
// set colors if is_jellyfin is locally set;
|
||||
// if it has not yet been set, it will be once
|
||||
// the user saves their settings
|
||||
#if DEBUG_MODE
|
||||
s_is_jellyfin = 1; // allow forcing configured state for emu testing
|
||||
#else
|
||||
s_is_jellyfin = persist_read_int(0);
|
||||
#endif
|
||||
switch (s_is_jellyfin) {
|
||||
case 1:
|
||||
s_color_primary = GColorVividViolet;
|
||||
|
||||
@@ -13,7 +13,7 @@ Pebble.addEventListener("appmessage", function (dict) {
|
||||
const cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
||||
|
||||
// report to user if some configuration is missing
|
||||
if (cfg.CLAY_API_HOST == "" || cfg.CLAY_API_KEY == "" || cfg.CLAY_USER == "") {
|
||||
if (!cfg || cfg.CLAY_API_HOST == "" || cfg.CLAY_API_KEY == "" || cfg.CLAY_USER == "") {
|
||||
Pebble.sendAppMessage({ PKJS_LAST_WATCHED: "SOME APP SETTINGS ARE UNSET" });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user