Allow easier emu testing; clean up unconfigured state logic
This commit is contained in:
41
src/c/main.c
41
src/c/main.c
@@ -3,6 +3,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// #define DEBUG_MODE 1
|
||||||
|
|
||||||
// declare settings-derived statics
|
// declare settings-derived statics
|
||||||
static uint8_t s_is_jellyfin;
|
static uint8_t s_is_jellyfin;
|
||||||
static GColor s_color_primary = GColorWhite;
|
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) {
|
static void main_window_load(Window *window) {
|
||||||
// sleep bar and icon
|
Layer *window_layer = window_get_root_layer(window);
|
||||||
s_sleep_bar_layer = layer_create(s_sleep_bar_start);
|
if (s_is_jellyfin == 0) {
|
||||||
s_sleep_icon_layer = layer_create(s_sleep_icon_start);
|
window_set_background_color(window, GColorWhite);
|
||||||
|
|
||||||
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 {
|
|
||||||
#if PBL_DISPLAY_WIDTH >= 200
|
#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));
|
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));
|
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));
|
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)));
|
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
|
#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(s_config_app_layer, "Please configure the app's settings from your phone");
|
||||||
text_layer_set_text_alignment(s_config_app_layer, GTextAlignmentCenter);
|
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
|
// 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));
|
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);
|
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
|
// add layers as children to windows
|
||||||
Layer *window_layer = window_get_root_layer(window);
|
|
||||||
#if PBL_ROUND
|
#if PBL_ROUND
|
||||||
text_layer_set_text_alignment(s_last_watched_layer, GTextAlignmentCenter);
|
text_layer_set_text_alignment(s_last_watched_layer, GTextAlignmentCenter);
|
||||||
#else
|
#else
|
||||||
@@ -157,12 +162,12 @@ static void main_window_load(Window *window) {
|
|||||||
layer_add_child(window_layer, s_sleep_bar_layer);
|
layer_add_child(window_layer, s_sleep_bar_layer);
|
||||||
layer_add_child(window_layer, s_sleep_icon_layer);
|
layer_add_child(window_layer, s_sleep_icon_layer);
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_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) {
|
static void main_window_unload(Window *window) {
|
||||||
|
if (s_is_jellyfin == 0) {
|
||||||
|
text_layer_destroy(s_config_app_layer);
|
||||||
|
} else {
|
||||||
pin_animation_deinit();
|
pin_animation_deinit();
|
||||||
text_layer_destroy(s_last_watched_layer);
|
text_layer_destroy(s_last_watched_layer);
|
||||||
text_layer_destroy(s_sleep_time_layer);
|
text_layer_destroy(s_sleep_time_layer);
|
||||||
@@ -170,9 +175,13 @@ static void main_window_unload(Window *window) {
|
|||||||
layer_destroy(s_sleep_bar_layer);
|
layer_destroy(s_sleep_bar_layer);
|
||||||
layer_destroy(s_pin_icon_layer);
|
layer_destroy(s_pin_icon_layer);
|
||||||
layer_destroy(s_button_bar_layer);
|
layer_destroy(s_button_bar_layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_sleep_time_to_pkjs() {
|
static void send_sleep_time_to_pkjs() {
|
||||||
|
if (s_is_jellyfin == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
DictionaryIterator *out;
|
DictionaryIterator *out;
|
||||||
AppMessageResult result = app_message_outbox_begin(&out);
|
AppMessageResult result = app_message_outbox_begin(&out);
|
||||||
if (result != APP_MSG_OK) {
|
if (result != APP_MSG_OK) {
|
||||||
@@ -293,10 +302,14 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
// set colors if is_jellyfin is locally set;
|
// set colors if is_jellyfin is locally set;
|
||||||
// if it has not yet been set, it will be once
|
// if it has not yet been set, it will be once
|
||||||
// the user saves their settings
|
// 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);
|
s_is_jellyfin = persist_read_int(0);
|
||||||
|
#endif
|
||||||
switch (s_is_jellyfin) {
|
switch (s_is_jellyfin) {
|
||||||
case 1:
|
case 1:
|
||||||
s_color_primary = GColorVividViolet;
|
s_color_primary = GColorVividViolet;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Pebble.addEventListener("appmessage", function (dict) {
|
|||||||
const cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
const cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
||||||
|
|
||||||
// report to user if some configuration is missing
|
// 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" });
|
Pebble.sendAppMessage({ PKJS_LAST_WATCHED: "SOME APP SETTINGS ARE UNSET" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user