Skip to content

Commit 516c0ff

Browse files
committed
tried to fix occasional missing alarm trigger O_O
1 parent 744911f commit 516c0ff

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

www/scripts/sepiaFW.ui.events.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function sepiaFW_build_events(){
466466
clearTimeout(Timer.action);
467467
Timer.action = setTimeout(function(){
468468
SepiaFW.debug.info("TimeEvent - " + Timer.name + ': ACTIVATED'); //DEBUG
469-
//remove
469+
//remove the timer and trigger the UI foreground action
470470
Events.removeTimeEvent(Timer.name, "", function(){
471471
//remove success - to prevent conflict between notification and trigger
472472
Events.triggerAlarm(Timer, '', '', ''); //start, end, error
@@ -631,38 +631,51 @@ function sepiaFW_build_events(){
631631
}
632632
}
633633

634-
//Alarm clock
634+
//Alarm clock - Triggered when UI is on foreground (system notification is removed before)
635635
Events.triggerAlarm = function(Timer, startCallback, endCallback, errorCallback){
636636
//console.log('triggerAlarm'); //DEBUG
637+
var showSimpleNote = true;
638+
var playSound = true;
639+
var showMissedNote = true;
640+
var doBroadcast = true;
637641
//in case the app was in background while the timer expired we block certain actions
638-
if ((new Date().getTime() - Timer.targetTime) > 5000){
639-
//block all if not triggered within 5s (optical feedback is triggered by interval action)
640-
//TODO: show some message? Check once for animation!
641-
return;
642+
if ((new Date().getTime() - Timer.targetTime) > 15000){
643+
//TODO: How can we land here again?? Awake from sleep-mode?
644+
showSimpleNote = false;
645+
playSound = false;
646+
//we keep the 'missed' note and broadcast
642647
}
643648
//if the app is open we trigger a simple notification just to give some visual feedback when the app is in background - it is delayed
644649
var titleS = SepiaFW.local.g(Timer.type); //+ ": " + (new Date().toLocaleString());
645650
var textS = SepiaFW.local.g('expired') + ": " + Timer.data.name;
646-
setTimeout(function(){
647-
Events.showSimpleSilentNotification(titleS, textS);
648-
}, 50);
651+
if (showSimpleNote){
652+
setTimeout(function(){
653+
Events.showSimpleSilentNotification(titleS, textS);
654+
}, 50);
655+
}
649656
//play sound
650-
if (SepiaFW.audio){
651-
SepiaFW.audio.playAlarmSound(startCallback, endCallback, errorCallback);
652-
}else{
653-
SepiaFW.debug.err("Alarm: Audio CANNOT be played, SepiaFW.audio is missing!");
657+
if (playSound){
658+
if (SepiaFW.audio){
659+
SepiaFW.audio.playAlarmSound(startCallback, endCallback, errorCallback);
660+
}else{
661+
SepiaFW.debug.err("Alarm: Audio CANNOT be played, SepiaFW.audio is missing!");
662+
}
654663
}
655664
//add missed message?
656-
if (!SepiaFW.ui.isVisible()
657-
|| (SepiaFW.frames && SepiaFW.frames.isOpen)
658-
|| (SepiaFW.teach && SepiaFW.teach.isOpen)
659-
){
660-
//SepiaFW.ui.addMissedMessage(); //this is handled inside UI.addDataToResultView call of the 'showInfo' item
661-
var customTag = Timer.data.eventId;
662-
SepiaFW.ui.showInfo(SepiaFW.local.g('missed') + "? " + titleS + " " + textS, true, customTag);
665+
if (showMissedNote){
666+
if (!SepiaFW.ui.isVisible()
667+
|| (SepiaFW.frames && SepiaFW.frames.isOpen)
668+
|| (SepiaFW.teach && SepiaFW.teach.isOpen)
669+
){
670+
//SepiaFW.ui.addMissedMessage(); //this is handled inside UI.addDataToResultView call of the 'showInfo' item
671+
var customTag = Timer.data.eventId;
672+
SepiaFW.ui.showInfo(SepiaFW.local.g('missed') + "? " + titleS + " " + textS, true, customTag);
673+
}
663674
}
664675
//broadcast event
665-
broadcastAlarmTrigger();
676+
if (doBroadcast){
677+
broadcastAlarmTrigger();
678+
}
666679
}
667680

668681
//------------- other notifications --------------

0 commit comments

Comments
 (0)