BangleApps/apps/chronowid/app.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-16 08:07:39 +00:00
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
const storage = require('Storage');
let settingsChronowid;
function updateSettings() {
var now = new Date();
const goal = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
now.getHours() + settingsChronowid.hours, now.getMinutes() + settingsChronowid.minutes, now.getSeconds() + settingsChronowid.seconds);
settingsChronowid.goal = goal.getTime();
storage.writeJSON('chronowid.json', settingsChronowid);
if (WIDGETS["chronowid"]) WIDGETS["chronowid"].reload();
2020-04-16 08:07:39 +00:00
}
function resetSettings() {
settingsChronowid = {
hours : 0,
minutes : 0,
seconds : 0,
started : false,
counter : 0,
goal : 0,
};
updateSettings();
}
settingsChronowid = storage.readJSON('chronowid.json',1);
2020-04-16 08:32:41 +00:00
if (!settingsChronowid) resetSettings();
2020-04-16 08:07:39 +00:00
E.on('kill', () => {
updateSettings();
});
function showMenu() {
const timerMenu = {
'': {
'title': 'Set timer'
2020-04-16 08:07:39 +00:00
},
'< Back' : ()=>{load();},
2020-04-17 13:55:41 +00:00
'Reset values': function() {
settingsChronowid.hours = 0;
settingsChronowid.minutes = 0;
settingsChronowid.seconds = 0;
settingsChronowid.started = false;
updateSettings();
showMenu();
2020-04-17 13:55:41 +00:00
},
2020-04-16 08:07:39 +00:00
'Hours': {
value: settingsChronowid.hours,
min: 0,
max: 24,
step: 1,
onchange: v => {
settingsChronowid.hours = v;
updateSettings();
}
},
'Minutes': {
value: settingsChronowid.minutes,
min: 0,
max: 59,
step: 1,
onchange: v => {
settingsChronowid.minutes = v;
updateSettings();
}
},
'Seconds': {
value: settingsChronowid.seconds,
min: 0,
max: 59,
step: 1,
onchange: v => {
settingsChronowid.seconds = v;
updateSettings();
}
},
'Timer on': {
value: settingsChronowid.started,
format: v => v ? "On" : "Off",
2020-04-16 08:07:39 +00:00
onchange: v => {
settingsChronowid.started = v;
updateSettings();
}
},
};
2020-04-16 08:07:39 +00:00
return E.showMenu(timerMenu);
}
showMenu();