runplus: update status depending on if in the pause window
parent
984f38d60c
commit
020d26ddef
|
|
@ -1,4 +1,5 @@
|
|||
let runInterval;
|
||||
let statusTimeout;
|
||||
let screen = "main"; // main | karvonen | menu | zoom
|
||||
// Run interface wrapped in a function
|
||||
const ExStats = require("exstats");
|
||||
|
|
@ -53,9 +54,15 @@ let statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti
|
|||
let exs = ExStats.getStats(statIDs, settings);
|
||||
// ---------------------------
|
||||
|
||||
function inPauseWindow() {
|
||||
return exs.state.duration <= settings.resume.promptAfter;
|
||||
}
|
||||
|
||||
function setStatus(running) {
|
||||
layout.button.label = running ? "STOP" : "START";
|
||||
layout.status.label = running ? "RUN" : "STOP";
|
||||
const paused = inPauseWindow();
|
||||
|
||||
layout.button.label = running ? "STOP" : paused ? "RESUME" : "START";
|
||||
layout.status.label = running ? "RUN" : paused ? "PAUSE" : "STOP";
|
||||
layout.status.bgCol = running ? "#0f0" : "#f00";
|
||||
if (screen === "main") layout.render();
|
||||
}
|
||||
|
|
@ -71,7 +78,7 @@ function onStartStop() {
|
|||
var shouldResume = settings.resume.default;
|
||||
var promise = Promise.resolve();
|
||||
|
||||
if (running && exs.state.duration > settings.resume.promptAfter) { // if more than N seconds of duration, ask if we should resume?
|
||||
if (running && !inPauseWindow()) { // if more than N seconds of duration, ask if we should resume?
|
||||
promise = promise.
|
||||
then(() => {
|
||||
screen = "menu";
|
||||
|
|
@ -107,6 +114,8 @@ function onStartStop() {
|
|||
}
|
||||
|
||||
promise.then(() => {
|
||||
if(statusTimeout) clearTimeout(statusTimeout);
|
||||
|
||||
if (running) {
|
||||
if (shouldResume)
|
||||
exs.resume();
|
||||
|
|
@ -114,6 +123,12 @@ function onStartStop() {
|
|||
exs.start();
|
||||
} else {
|
||||
exs.stop();
|
||||
|
||||
// convert start/stop label when pause-window ends
|
||||
statusTimeout = setTimeout(() => {
|
||||
statusTimeout = undefined;
|
||||
setStatus(running);
|
||||
}, settings.resume.promptAfter);
|
||||
}
|
||||
// if stopping running, don't clear state
|
||||
// so we can at least refer to what we've done
|
||||
|
|
|
|||
Loading…
Reference in New Issue