Backport: Open straight to alarm window when recovery alarm is set

This commit is contained in:
RandyTheSilly committed 2026-11-01 11:09:48 -05:00
1 parent 018eda0235
commit 7c4f0804f4
1 file changed
+11 -11
+11 -11
View File
@@ -236,16 +236,18 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
case WAKE_RECOVERY_MAIN_ALARM:
case WAKE_RECOVERY_AWARENESS_ALARM:
target = time(NULL) + 15;
// no need to cancel alarms, as recovery alarms short-lived and is expired by the time another is being scheduled
// no need to cancel alarms, as recovery alarms are short-lived and are expired by the time another is being scheduled
status = wakeup_schedule_simple_robust(target, 15, schedule_reason);
}
if (status < 0) {
push_status_window(STATUS_SET_FAILURE);
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_MAIN_ALARM);
s_alarm_reason = WAKE_MAIN_ALARM;
return false;
}
if (persist_read_int(STORAGE_KEY_ALARM_REASON) != schedule_reason) {
persist_write_int(STORAGE_KEY_ALARM_REASON, schedule_reason);
s_alarm_reason = schedule_reason;
}
return true;
}
@@ -830,8 +832,6 @@ static void alarm_window_unload() {
}
static void push_alarm_window() {
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
switch (s_alarm_reason) {
case WAKE_RECOVERY_MAIN_ALARM:
send_zap(settings.PavlokMax);
@@ -945,11 +945,6 @@ 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(settings.PavlokMax);
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
@@ -1067,8 +1062,6 @@ static void setter_window_unload() {
}
static void push_setter_window() {
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
window_set_window_handlers(
s_window,
(WindowHandlers){.load = setter_window_load, .unload = setter_window_unload});
@@ -1086,7 +1079,7 @@ static void init() {
// initialize pkjs
app_message_register_inbox_received(inbox_received_handler);
app_message_open(128, 128); // TODO tighten sizes
app_message_open(128, 128);
// load settings from persist (or set defaults if not present)
if (persist_exists(STORAGE_KEY_SETTINGS)) {
@@ -1103,12 +1096,19 @@ static void init() {
settings.AwarenessTimeLimitSeconds = 30;
}
// read even when opening setter to ensure a recovery alarm is not able to be overwritten
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
switch (launch_reason()) {
case APP_LAUNCH_WAKEUP:
push_alarm_window();
break;
default:
if (s_alarm_reason == WAKE_RECOVERY_MAIN_ALARM || s_alarm_reason == WAKE_RECOVERY_AWARENESS_ALARM) {
push_alarm_window();
} else {
push_setter_window();
}
};
}