Resolve some conceptual conflicts between chained timers and snoozing
1. Make snoozing only available for non-chained timers (or the last timer in a chain) 2. Don't let dismissing a snoozed timer restart the chained timer if it was paused (though 1. should preclude this from happening anyway)master
parent
fe04af7cc2
commit
931b1f6cef
|
|
@ -16,13 +16,16 @@ function showAlarm(alarm) {
|
||||||
}
|
}
|
||||||
let message = timer.display_name() + '\n' + alarm.msg;
|
let message = timer.display_name() + '\n' + alarm.msg;
|
||||||
|
|
||||||
// If there's a timer chained from this one, start it
|
// If there's a timer chained from this one, start it (only for
|
||||||
if (timer.chain_id !== null) {
|
// alarms not in snoozed status)
|
||||||
const chainTimer = tt.TIMERS[tt.find_timer_by_id(timer.chain_id)];
|
var isChainedTimer = false;
|
||||||
|
if (timer.chain_id !== null && alarm.ot === undefined) {
|
||||||
|
var chainTimer = tt.TIMERS[tt.find_timer_by_id(timer.chain_id)];
|
||||||
if (chainTimer !== undefined) {
|
if (chainTimer !== undefined) {
|
||||||
chainTimer.reset();
|
chainTimer.reset();
|
||||||
chainTimer.start();
|
chainTimer.start();
|
||||||
tt.set_last_viewed_timer(chainTimer);
|
tt.set_last_viewed_timer(chainTimer);
|
||||||
|
isChainedTimer = true;
|
||||||
} else {
|
} else {
|
||||||
console.warn("tevtimer: unable to find chained timer with ID " + timer.chain_id);
|
console.warn("tevtimer: unable to find chained timer with ID " + timer.chain_id);
|
||||||
}
|
}
|
||||||
|
|
@ -43,13 +46,20 @@ function showAlarm(alarm) {
|
||||||
// buzzCount should really be called buzzRepeat, so subtract 1
|
// buzzCount should really be called buzzRepeat, so subtract 1
|
||||||
let buzzCount = timer.buzz_count - 1;
|
let buzzCount = timer.buzz_count - 1;
|
||||||
|
|
||||||
|
// Alarm options for non-chained timer are OK (dismiss the alarm) and
|
||||||
|
// Snooze (retrigger the alarm after a delay).
|
||||||
|
// Alarm options for chained timer are OK (dismiss) and Halt (dismiss
|
||||||
|
// and pause the triggering timer).
|
||||||
|
let promptButtons = isChainedTimer
|
||||||
|
? { "Halt": 'halt', "OK": 'ok' }
|
||||||
|
: { "Snooze": 'snooze', "OK": 'ok' };
|
||||||
E.showPrompt(message, {
|
E.showPrompt(message, {
|
||||||
title: 'tev timer',
|
title: 'tev timer',
|
||||||
buttons: { "Snooze": true, "Stop": false } // default is sleep so it'll come back in some mins
|
buttons: promptButtons,
|
||||||
}).then(function (sleep) {
|
}).then(function (action) {
|
||||||
buzzCount = 0;
|
buzzCount = 0;
|
||||||
|
|
||||||
if (sleep) {
|
if (action === 'snooze') {
|
||||||
if (alarm.ot === undefined) {
|
if (alarm.ot === undefined) {
|
||||||
alarm.ot = alarm.t;
|
alarm.ot = alarm.t;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +68,8 @@ function showAlarm(alarm) {
|
||||||
alarm.t = currentTime + settings.defaultSnoozeMillis;
|
alarm.t = currentTime + settings.defaultSnoozeMillis;
|
||||||
alarm.t %= 86400000;
|
alarm.t %= 86400000;
|
||||||
Bangle.emit("alarmSnooze", alarm);
|
Bangle.emit("alarmSnooze", alarm);
|
||||||
} else {
|
}
|
||||||
|
if (action === 'ok' || action === 'halt') {
|
||||||
// Don't do timer deletions here; this is handled by the
|
// Don't do timer deletions here; this is handled by the
|
||||||
// tevtimer library code (and it may rearrange the alarm indeces
|
// tevtimer library code (and it may rearrange the alarm indeces
|
||||||
// in the process)
|
// in the process)
|
||||||
|
|
@ -76,6 +87,10 @@ function showAlarm(alarm) {
|
||||||
alarm.on = false;
|
alarm.on = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (action === 'halt') {
|
||||||
|
timer.pause();
|
||||||
|
chainTimer.pause();
|
||||||
|
}
|
||||||
Bangle.emit("alarmDismiss", alarm);
|
Bangle.emit("alarmDismiss", alarm);
|
||||||
|
|
||||||
// The updated alarm is still a member of 'alarms'
|
// The updated alarm is still a member of 'alarms'
|
||||||
|
|
@ -85,7 +100,12 @@ function showAlarm(alarm) {
|
||||||
// Update system alarms for any changed timers just before we finish
|
// Update system alarms for any changed timers just before we finish
|
||||||
tt.update_system_alarms();
|
tt.update_system_alarms();
|
||||||
|
|
||||||
load();
|
// Load `tevtimer` app upon halt, else the default (clock) app
|
||||||
|
if (action === 'halt') {
|
||||||
|
load('tevtimer.app.js');
|
||||||
|
} else {
|
||||||
|
load();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function buzz() {
|
function buzz() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue