Skip to content

Commit

Permalink
Quiet time respecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
matejdro committed Nov 29, 2016
1 parent 0b3889a commit 652ffac
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
22 changes: 19 additions & 3 deletions src/MainMenuWindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/MainMenuWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
32 changes: 27 additions & 5 deletions src/NotificationCenter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/NotificationCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern bool main_noMenu;

extern bool closingMode;
extern bool loadingMode;
extern bool rejectNotifications;

extern uint32_t appmessage_max_size;

Expand Down

0 comments on commit 652ffac

Please sign in to comment.