mirror of
https://git.wetfence.xyz/RandyTheSilly/Trigalarm.git
synced 2026-09-01 16:27:14 -04:00
Vibe(+zap) when attempting to overwrite recovery/awareness alarm
This commit is contained in:
+11
-11
@@ -200,6 +200,7 @@ static void send_zap() {
|
||||
if (result != APP_MSG_OK) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
////////////////////// MISC //////////////////////
|
||||
@@ -213,17 +214,11 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
|
||||
target = time(NULL) + 15;
|
||||
// no need to cancel alarms, as RECOVERY_ALARM is short-lived and is expired by the time another is being scheduled
|
||||
status = wakeup_schedule_simple_robust(target, 15, schedule_reason);
|
||||
if (s_alarm_reason != WAKE_RECOVERY_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_RECOVERY_ALARM);
|
||||
}
|
||||
break;
|
||||
case WAKE_AWARENESS_ALARM:
|
||||
target = time(NULL) + 9 * SECONDS_PER_MINUTE;
|
||||
wakeup_cancel_all();
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, schedule_reason);
|
||||
if (s_alarm_reason != WAKE_AWARENESS_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_AWARENESS_ALARM);
|
||||
}
|
||||
break;
|
||||
case WAKE_MAIN_ALARM: {
|
||||
time_t now = time(NULL);
|
||||
@@ -237,15 +232,16 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
|
||||
}
|
||||
wakeup_cancel_all();
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, schedule_reason);
|
||||
if (s_alarm_reason != WAKE_MAIN_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_MAIN_ALARM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status < 0) {
|
||||
push_status_window(STATUS_SET_FAILURE);
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_MAIN_ALARM);
|
||||
return false;
|
||||
}
|
||||
if (s_alarm_reason != schedule_reason) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, schedule_reason);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -838,6 +834,11 @@ static void setter_down_click_handler(void *recognizer, void *ctx) {
|
||||
|
||||
static void setter_select_click_handler(void *recognizer, void *ctx) {
|
||||
if (s_highlight_pos == 2) {
|
||||
if (s_alarm_reason != WAKE_MAIN_ALARM) {
|
||||
send_zap();
|
||||
vibes_double_pulse();
|
||||
return; // early return to avoid overwriting recovery/awareness alarm
|
||||
}
|
||||
bool success = schedule_alarm(WAKE_MAIN_ALARM);
|
||||
if (!success) {
|
||||
return; // early return to avoid indicating alarm was set when it was not
|
||||
@@ -967,10 +968,9 @@ static void init() {
|
||||
app_message_register_inbox_received(inbox_received_handler);
|
||||
app_message_open(64, 64); // TODO tighten sizes
|
||||
|
||||
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
|
||||
switch (launch_reason()) {
|
||||
// case APP_LAUNCH_PHONE: // DEBUG, REMOVE PRIOR TO RELEASE!
|
||||
case APP_LAUNCH_WAKEUP:
|
||||
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
|
||||
if (s_alarm_reason == WAKE_RECOVERY_ALARM) {
|
||||
send_zap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user