Send current time to PKJS if no sleep session was found (show the last thing played in general)
This commit is contained in:
11
src/c/main.c
11
src/c/main.c
@@ -23,6 +23,7 @@ static GRect s_sleep_icon_start = GRect((PBL_DISPLAY_WIDTH / 2) - 13, (PBL_DISPL
|
||||
|
||||
// declare time tracking statics
|
||||
static time_t s_sleep_timestamp;
|
||||
static bool s_sleep_session_found;
|
||||
static bool s_sleep_data_accessible;
|
||||
|
||||
static void load_complete_animation_handler(Animation *animation, bool finished, void *context) {
|
||||
@@ -37,7 +38,12 @@ static void send_sleep_time_to_pkjs() {
|
||||
text_layer_set_text(s_last_watched_layer, "outbox_begin failure");
|
||||
return;
|
||||
}
|
||||
if (s_sleep_session_found) {
|
||||
dict_write_uint32(out, MESSAGE_KEY_PKJS_SLEEP_TIMESTAMP, s_sleep_timestamp);
|
||||
} else {
|
||||
// send current UNIX timestamp to fetch the last thing played
|
||||
dict_write_uint32(out, MESSAGE_KEY_PKJS_SLEEP_TIMESTAMP, time(NULL));
|
||||
}
|
||||
result = app_message_outbox_send();
|
||||
if (result != APP_MSG_OK) {
|
||||
text_layer_set_text(s_last_watched_layer, "outbox_send failure");
|
||||
@@ -163,7 +169,7 @@ static void main_window_load(Window *window) {
|
||||
strftime(buffer, sizeof(buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", timeinfo);
|
||||
text_layer_set_text(s_sleep_time_layer, buffer);
|
||||
} else {
|
||||
text_layer_set_text(s_sleep_time_layer, "No sleep last night");
|
||||
text_layer_set_text(s_sleep_time_layer, "No sleep times found");
|
||||
}
|
||||
layer_set_hidden(text_layer_get_layer(s_sleep_time_layer), true);
|
||||
|
||||
@@ -248,6 +254,9 @@ static void init() {
|
||||
if (health_service_any_activity_accessible(HealthActivitySleep, start, end) == HealthServiceAccessibilityMaskAvailable) {
|
||||
s_sleep_data_accessible = true;
|
||||
update_sleep_time(start, end);
|
||||
if (s_sleep_timestamp > 0) {
|
||||
s_sleep_session_found = true;
|
||||
}
|
||||
} else {
|
||||
s_sleep_data_accessible = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user