scheduler implementation part/3; do not allow start = end; allow start < end

This commit is contained in:
Jeremy Schomery 2017-05-03 21:24:57 +04:30
parent c2f993db27
commit 52ae781960
3 changed files with 10 additions and 3 deletions

View File

@ -713,7 +713,10 @@
"scheduleButtonActive": {
"message": "Scheduled"
},
"scheduleMSG": {
"scheduleOneEntry": {
"message": "Either clear both start and end values to disable the schedule or set both to enable it"
},
"scheduleEqualEntries": {
"message": "Start and end times cannot be equal"
}
}

View File

@ -76,7 +76,7 @@ schedule.execute = (name, request) => {
chrome.alarms.create(name, {when});
getStylesSafe({id: request.id}).then(([style]) => {
if (style) {
const enabled = start <= 0 && end > 0;
const enabled = (start <= 0 && end > 0) || (start > end && start * end > 0) ;
console.log(`style with id = ${style.id}; enabled = `, enabled);
saveStyleSafe({

View File

@ -36,10 +36,14 @@ document.addEventListener('click', e => {
});
break;
case 1: // when only start or end value is set; display an alert
window.alert(t('scheduleMSG'));
window.alert(t('scheduleOneEntry'));
[start, end].filter(o => !o.value).forEach(o => o.focus());
return;
default:
if (start.value === end.value) {
window.alert(t('scheduleEqualEntries'));
return start.focus();
}
chrome.runtime.sendMessage({
method: 'schedule',
enabled: true,