From 652ffaca4265db06990349d776edb47eaa146103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Drobni=C4=8D?= Date: Tue, 29 Nov 2016 15:37:29 +0100 Subject: [PATCH] Quiet time respecting. --- src/MainMenuWindow.c | 22 +++++++++++++++++++--- src/MainMenuWindow.h | 1 + src/NotificationCenter.c | 32 +++++++++++++++++++++++++++----- src/NotificationCenter.h | 1 + 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/MainMenuWindow.c b/src/MainMenuWindow.c index 089a907..f4b8c29 100755 --- a/src/MainMenuWindow.c +++ b/src/MainMenuWindow.c @@ -72,10 +72,26 @@ void show_disconnected_error(void) text_layer_set_text(loadingLayer, "Notification Center\n\nPhone is not connected."); } +void show_quitting(void) +{ + layer_set_hidden((Layer *) loadingLayer, true); + layer_set_hidden((Layer *) quitTitle, false); + layer_set_hidden((Layer *) quitText, false); + +#ifndef PBL_LOW_MEMORY + activity_indicator_layer_set_animating(loadingIndicator, false); + layer_set_hidden(activity_indicator_layer_get_layer(loadingIndicator), true); +#endif + + text_layer_set_text(quitTitle, "Press back again if app does not close in several seconds"); + text_layer_set_text(quitText, "Quitting...\n Please wait"); +} + static void show_error_base(void) { layer_set_hidden((Layer *) loadingLayer, false); - layer_set_hidden((Layer *) quitTitle, true); + layer_set_hidden((Layer *) menuLayer, true); + layer_set_hidden((Layer *) quitTitle, true); layer_set_hidden((Layer *) quitText, true); if (menuLayer != NULL) layer_set_hidden((Layer *) menuLayer, true); @@ -293,12 +309,10 @@ static void window_appears(Window* window) quitTitle = text_layer_create(GRect(0, 70 + STATUSBAR_Y_OFFSET, windowWidth, 50)); text_layer_set_text_alignment(quitTitle, GTextAlignmentCenter); - text_layer_set_text(quitTitle, "Press back again if app does not close in several seconds"); layer_add_child(topLayer, (Layer*) quitTitle); quitText = text_layer_create(GRect(0, 10 + STATUSBAR_Y_OFFSET, windowWidth, 50)); text_layer_set_text_alignment(quitText, GTextAlignmentCenter); - text_layer_set_text(quitText, "Quitting...\n Please wait"); text_layer_set_font(quitText, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(topLayer, (Layer*) quitText); @@ -339,6 +353,8 @@ static void window_appears(Window* window) setCurWindow(0); if (menuLoaded && !closingMode) show_menu(); + else + show_quitting(); app_timer_register(3000, closing_timer, NULL); } diff --git a/src/MainMenuWindow.h b/src/MainMenuWindow.h index e3d0b71..5422485 100755 --- a/src/MainMenuWindow.h +++ b/src/MainMenuWindow.h @@ -14,5 +14,6 @@ void show_menu(void); void show_old_watchapp_error(void); void show_old_android_error(void); void show_disconnected_error(void); +void show_quitting(void); #endif /* MAINMENU_H_ */ diff --git a/src/NotificationCenter.c b/src/NotificationCenter.c index 7c5c31c..f8e5b26 100755 --- a/src/NotificationCenter.c +++ b/src/NotificationCenter.c @@ -5,7 +5,7 @@ #include "NotificationListWindow.h" #include "NotificationsWindow/Comm.h" -const uint16_t PROTOCOL_VERSION = 42; +const uint16_t PROTOCOL_VERSION = 43; int8_t curWindow = 0; bool gotConfig = false; @@ -38,6 +38,7 @@ uint32_t appmessage_max_size; bool closingMode = false; bool loadingMode = false; +bool rejectNotifications = false; static const char* fonts[] = { FONT_KEY_GOTHIC_14, @@ -164,11 +165,31 @@ static void received_config(DictionaryIterator *received) config_skew_background_image_colors = (data[13] & 0x10) != 0; #endif - gotConfig = true; loadingMode = false; + gotConfig = true; - if (!main_noMenu) - show_menu(); + bool respectQuietTime = (data[13] & 0x20) != 0; + if (respectQuietTime && quiet_time_is_active()) + { + AppLaunchReason launchReason = launch_reason(); + if (launchReason == APP_LAUNCH_PHONE) + { + // App was launched by phone, but quiet time is active. Lets bail out. + closingMode = true; + rejectNotifications = true; + gotConfig = false; + } + + } + + if (rejectNotifications) + { + show_quitting(); + } + else if (!main_noMenu) + { + show_menu(); + } } static void received_data(DictionaryIterator *received, void *context) { @@ -228,7 +249,8 @@ void closeApp(void) app_message_outbox_begin(&iterator); dict_write_uint8(iterator, 0, 0); dict_write_uint8(iterator, 1, 3); - app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); + dict_write_uint8(iterator, 2, rejectNotifications ? 1 : 0); + app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); app_message_outbox_send(); closingMode = true; diff --git a/src/NotificationCenter.h b/src/NotificationCenter.h index 8dd39f2..7d1eb47 100755 --- a/src/NotificationCenter.h +++ b/src/NotificationCenter.h @@ -47,6 +47,7 @@ extern bool main_noMenu; extern bool closingMode; extern bool loadingMode; +extern bool rejectNotifications; extern uint32_t appmessage_max_size;