1
0
Fork 0

Merge pull request #3258 from jla-42/master

Two new apps: sleep quiet and theme switcher
master
Rob Pilling 2024-03-16 14:23:36 +00:00 committed by GitHub
commit d05dbd03d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 791 additions and 0 deletions

1
apps/slpquiet/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

27
apps/slpquiet/README.md Normal file
View File

@ -0,0 +1,27 @@
# Sleep Quiet
Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated)
## Usage
When activated, app disables all notifications / all except alarms when sleep detected.
## Controls
In the app you can activate / deactivate the functionality and define if all notifications / all except alarms are to be silenced.
## Creator
[jla-42](https://github.com/jla-42)
## Note
The app is based upon the [sleeplog](https://github.com/espruino/BangleApps/tree/master/apps/sleeplog) app.
It reuses the widget from [Quiet Mode Schedule and Widget](https://github.com/espruino/BangleApps/tree/master/apps/qmsched), as it does exactly what I needed, so why reinvent the wheel.
## ToDos
-further code clean up
-optimization of code (and check if needed)
-feedback is always welcome

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEw4UA///jc+tfUvk+Jf8AhWoBhUoBZWgBRMCwAvKHa5bTG5UqJ4OqBY+qBYJpIBYRpIBYRRIBYQAIBbJhJBYIBBktVAAVoBYmoj//AAXWBYsdC4d1BZVdGwILO0ALIAAWdBY+vIQILI04LBrojKAAoLyX40CBeUqBZD1HAH8AA="))

33
apps/slpquiet/app.js Normal file
View File

@ -0,0 +1,33 @@
const SETTINGS_FILE = "quietSwitch.json";
const storage = require("Storage");
let saved = storage.readJSON(SETTINGS_FILE, 1) || {};
// Main menu
var mainmenu = {
"": {
"title": "Quiet Switch"
},
"Quiet Switch": {
value: saved.quietWhenSleep,
format: v => v ? "On" : "Off",
min: 0, max: 1, step: 1,
onchange: v => {
saved.quietWhenSleep = v;
storage.writeJSON(SETTINGS_FILE, saved);
}
},
"Quiet Mode": {
value: saved.quietMode,
format: v => v ? "Alerts" : "Silent",
min: 0, max: 1, step: 1,
onchange: v => {
saved.quietMode = v;
storage.writeJSON(SETTINGS_FILE, saved);
}
},
"Exit": function () { load(); },
};
// Actually display the menu
E.showMenu(mainmenu);

BIN
apps/slpquiet/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

52
apps/slpquiet/boot.js Normal file
View File

@ -0,0 +1,52 @@
// first ensure that the sleeplog trigger object is available (sleeplog is enabled)
if (typeof (global.sleeplog || {}).trigger === "object") {
// then add your parameters with the function to call as object into the trigger object
sleeplog.trigger["quietMode"] = {
onChange: true, // false as default, if true call fn only on a status change
from: 0, // 0 as default, in ms, first time fn will be called
// to: 24*60*60*1000, // 24h as default, in ms, last time fn will be called
to: 0,
// reference time to from & to is rounded to full minutes
fn: function (data, thisTriggerEntry) {
let aSettings = require('Storage').readJSON('quietSwitch.json', 1) || {};
const DEFAULTS = {
'quietWhenSleep': false,
'quietMode': 1
};
Object.keys(DEFAULTS).forEach(k => {
if (aSettings[k] === undefined) aSettings[k] = DEFAULTS[k];
});
if (aSettings && aSettings['quietWhenSleep']) {
console.log("the sleep status is: " + data.status);
let quietMode = aSettings['quietMode'];
delete aSettings;
if ((data.status === 3 || data.status === 4)
&& (data.prevStatus !== 3 && data.prevStatus !== 4)) {
let bSettings = require("Storage").readJSON('setting.json', true) || {};
let current = 0 | bSettings.quiet;
console.log("quiet mode is:" + current);
if (current !== quietMode) {
console.log("fallen asleep");
bSettings.quiet = quietMode;
require("Storage").writeJSON("setting.json", bSettings);
}
delete bSettings;
}
if ((data.status === 2 || data.status === 1)
&& (data.prevStatus !== 2 && data.prevStatus !== 1)) {
let bSettings = require("Storage").readJSON('setting.json', true) || {};
let current = 0 | bSettings.quiet;
console.log("quiet mode is:" + current);
if (current !== 0) {
console.log("woken up");
bSettings.quiet = 0;
require("Storage").writeJSON("setting.json", bSettings);
}
delete bSettings;
}
}
}
};
}

View File

@ -0,0 +1,17 @@
{ "id": "slpquiet",
"name": "Sleep Quiet (activate quiet mode when asleep)",
"shortName":"Sleep Quiet",
"version":"0.01",
"description": "Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated)",
"icon": "app.png",
"tags": "tool,widget",
"dependencies": {"sleeplog":"app"},
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"slpquiet.app.js","url":"app.js"},
{"name":"slpquiet.boot.js","url":"boot.js"},
{"name":"slpquiet.img","url":"app-icon.js","evaluate":true},
{"name":"slpquiet.wid.js","url":"widget.js"}
]
}

36
apps/slpquiet/widget.js Normal file
View File

@ -0,0 +1,36 @@
(function () {
WIDGETS["slpquiet"] = {
area: "tl",
width: ((require("Storage").readJSON("setting.json", 1) || {}).quiet | 0) ? 24 : 0,
draw: function () {
const mode = (require("Storage").readJSON("setting.json", 1) || {}).quiet | 0;
if (mode === 0) { // Off
if (this.width !== 0) {
this.width = 0;
Bangle.drawWidgets();
}
return;
}
// not Off: make sure width is correct
if (this.width !== 24) {
this.width = 24;
Bangle.drawWidgets();
return; // drawWidgets will call draw again
}
let x = this.x, y = this.y;
g.reset().clearRect(x, y, x + 23, y + 23);
// quiet mode: draw red one-way-street sign (dim red on Bangle.js 1)
x = this.x + 11; y = this.y + 11; // center of widget
g.setColor(process.env.HWVERSION === 2 ? 1 : 0.8, 0, 0).fillCircle(x, y, 8);
g.setColor(g.theme.bg).fillRect(x - 6, y - 2, x + 6, y + 2);
if (mode > 1) { return; } // no alarms
// alarms still on: draw alarm icon in bottom-right corner
x = this.x + 18; y = this.y + 17; // center of alarm
g.setColor(1, 1, 0)
.fillCircle(x, y, 3) // alarm body
.fillRect(x - 5, y + 2, x + 5, y + 3) // bottom ridge
.fillRect(x - 1, y - 5, x + 1, y + 5).drawLine(x, y - 6, x, y + 6) // top+bottom
.drawLine(x + 5, y - 3, x + 3, y - 5).drawLine(x - 5, y - 3, x - 3, y - 5); // wriggles
},
};
})();

1
apps/thmswtch/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

35
apps/thmswtch/README.md Normal file
View File

@ -0,0 +1,35 @@
# Theme Switcher
Switch Dark/Light theme based on time or on sunrise/sunset
## Usage
When activated, switches automaticaly the theme based on time or on sunrise/sunset.
## Controls
In the app you can:
-activate / deactivate the general functionality
-manualy switch dark/light theme
-define times for light / dark switch (at the moment 1 --> dark and 1 --> light switch time)
-set automatic witching based on sunrise/sunset times privided by the [suncalc](https://github.com/jla-42/BangleApps/blob/master/modules/suncalc.js) module
## Creator
[jla-42](https://github.com/jla-42)
## Note
The app functionality is inspired by the [Quiet Mode Schedule and Widget](https://github.com/espruino/BangleApps/tree/master/apps/qmsched) app, where i missed the sunrise/sunset functionality, and wanted an indipendent switch of the theme and notifications.
## ToDos
-further code clean up
-optimization of code (and check if needed)
-transfer of configuration into settings, so app can be used as a shortcut to switch theme.
-feedback is always welcome

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwgIWTj/4Aof//4ECgYFB4AFBh4FB+AWCAoIYCn///18AoN/BYMeEQf/h8AgIFCg+AFAX/gfAAocB4EHAofgAocA8A6CAoPwAolwAopGC/wFGnAFI/gFKMgIFDOAIFJ8AFERAJBDOoIFCGgIFDRoXwMoIcBMoJ/BAgJxBgYFDQYKwCAYINBAoIVCWwShBgF4AQKtCnwCBXIUfwEBG4UPSQIaCborpFCQT/HABY="))

253
apps/thmswtch/app.js Normal file
View File

@ -0,0 +1,253 @@
const SETTINGS_FILE = "themeSwitch.json";
const storage = require("Storage");
var sunrise, sunset, date;
var SunCalc = require("suncalc"); // from modules folder
let settings = storage.readJSON('setting.json', 1);
let saved = storage.readJSON(SETTINGS_FILE, 1) || {};
if (settings.theme.fg > 0) {
saved.darkModeActive = 1;
} else {
saved.darkModeActive = 0;
}
let dmH, dmM, lmH, lmM;
if (require("Storage").readJSON("themeSwitch.json", 1) !== undefined) {
dmH = parseInt(saved.darkModeAt.split(":")[0] | 0);
dmM = parseInt(saved.darkModeAt.split(":")[1] | 0);
lmH = parseInt(saved.lightModeAt.split(":")[0] | 0);
lmM = parseInt(saved.lightModeAt.split(":")[1] | 0);
} else {
dmH = 0;
dmM = 0;
lmH = 0;
lmM = 0;
}
// Main menu
var mainmenu = {
"": {
"title": "Theme Switch"
},
"< Back": function () { load(); },
"Automatic Dark Mode": {
value: saved.darkMode | false,
format: v => v ? "On" : "Off",
min: 0, max: 1, step: 1,
onchange: v => {
saved.darkMode = v;
storage.writeJSON(SETTINGS_FILE, saved);
}
},
"Dark Mode Active": {
value: saved.darkModeActive | false,
format: v => v ? "On" : "Off",
min: 0, max: 1, step: 1,
onchange: v => {
saved.darkModeActive = v;
storage.writeJSON(SETTINGS_FILE, saved);
if (v !== 0) {
setDarkTheme();
Bangle.drawWidgets();
} else {
setLightTheme();
Bangle.drawWidgets();
}
}
},
"Dark Mode by Sun": {
value: saved.darkModeBySun | false,
format: v => v ? "On" : "Off",
min: 0, max: 1, step: 1,
onchange: v => {
saved.darkModeBySun = v;
if (v !== 0) {
//print("calculating sun times");
calculateSunTimes();
saved.lightModeAt = sunrise;
saved.darkModeAt = sunset;
//print("sunrise" +sunrise);
//print("sunset" +sunset);
}
storage.writeJSON(SETTINGS_FILE, saved);
},
},
"light mode at": {
value: saved.lightModeAt,
format: v => saved.lightModeAt,
onchange: function () {
if (saved.darkModeBySun === 0) {
E.showMenu(lightModeAtMenu);
}
else {
E.showAlert("Deactivate dark mode first!", "Action Blocked").then(
function () { E.showMenu(mainmenu); });
}
}
},
"dark mode at": {
value: saved.darkModeAt,
format: v => saved.darkModeAt,
onchange: function () {
if (saved.darkModeBySun === 0) {
E.showMenu(darkModeAtMenu);
}
else {
E.showAlert("Deactivate dark mode first!", "Action Blocked").then(function () { E.showMenu(mainmenu); });
}
}
},
"Exit": function () { load(); },
};
var lightModeAtMenu = {
"": {
"title": "light mode at"
},
"Hour": {
value: lmH,
min: 0, max: 23, step: 1,
onchange: v => { lmH = v; }
},
"Minute": {
value: lmM,
min: 0, max: 59, step: 1,
onchange: v => { lmM = v; }
},
"< Back": function () {
saved.lightModeAt = fixTime(lmH, lmM);
storage.writeJSON(SETTINGS_FILE, saved);
E.showMenu(mainmenu);
},
};
var darkModeAtMenu = {
"": {
"title": "dark mode at"
},
"Hour": {
value: dmH,
min: 0, max: 23, step: 1,
onchange: v => { dmH = v; }
},
"Minute": {
value: dmM,
min: 0, max: 59, step: 1,
onchange: v => { dmM = v; }
},
"< Back": function () {
saved.darkModeAt = fixTime(dmH, dmM);
storage.writeJSON(SETTINGS_FILE, saved);
E.showMenu(mainmenu);
},
};
// Actually display the menu
E.showMenu(mainmenu);
// Function to fix time format
function fixTime(h, m) {
if (h.toString().length < 2) {
h = "0" + h.toString();
}
if (m.toString().length < 2) {
m = "0" + m.toString();
}
return h.toString() + ":" + m.toString();
}
function calculateSunTimes() {
var location = require("Storage").readJSON("mylocation.json", 1) || {};
location.lat = location.lat || 51.5072;
location.lon = location.lon || 0.1276; // London
date = new Date(Date.now());
var times = SunCalc.getTimes(date, location.lat, location.lon);
sunrise = fixTime(times.sunrise.getHours(), times.sunrise.getMinutes());
sunset = fixTime(times.sunset.getHours(), times.sunset.getMinutes());
/* do we want to re-calculate this every day? Or we just assume
that 'show' will get called once a day? */
}
function cl(x) { return g.setColor(x).getColor(); }
function upd(th) {
g.theme = th;
settings.theme = th;
storage.write('setting.json', settings);
delete g.reset;
g._reset = g.reset;
g.reset = function (n) { return g._reset().setColor(th.fg).setBgColor(th.bg); };
g.clear = function (n) { if (n) g.reset(); return g.clearRect(0, 0, g.getWidth(), g.getHeight()); };
g.clear(1);
}
function setDarkTheme() {
if (!g.theme.dark) {
upd({
fg: cl("#fff"), bg: cl("#000"),
fg2: cl("#fff"), bg2: cl("#004"),
fgH: cl("#fff"), bgH: cl("#00f"),
dark: true
});
}
}
function setLightTheme() {
if (g.theme.dark) {
upd({
fg: cl("#000"), bg: cl("#fff"),
fg2: cl("#000"), bg2: cl("#cff"),
fgH: cl("#000"), bgH: cl("#0ff"),
dark: false
});
}
}
// const SETTINGS_FILE = "themeSwitch.json";
// const storage = require("Storage");
// let settings = storage.readJSON('setting.json', 1);
// let saved = storage.readJSON(SETTINGS_FILE, 1) || {};
// function cl(x) { return g.setColor(x).getColor(); }
// function upd(th) {
// g.theme = th;
// settings.theme = th;
// storage.write('setting.json', settings);
// delete g.reset;
// g._reset = g.reset;
// g.reset = function (n) { return g._reset().setColor(th.fg).setBgColor(th.bg); };
// g.clear = function (n) { if (n) g.reset(); return g.clearRect(0, 0, g.getWidth(), g.getHeight()); };
// g.clear(1);
// }
// function flipTheme(saved) {
// if (!g.theme.dark) {
// upd({
// fg: cl("#fff"), bg: cl("#000"),
// fg2: cl("#fff"), bg2: cl("#004"),
// fgH: cl("#fff"), bgH: cl("#00f"),
// dark: true
// });
// saved.darkModeActive = 1;
// } else {
// upd({
// fg: cl("#000"), bg: cl("#fff"),
// fg2: cl("#000"), bg2: cl("#cff"),
// fgH: cl("#000"), bgH: cl("#0ff"),
// dark: false
// });
// saved.darkModeActive = 0;
// }
// return saved;
// }
// if (settings.theme.fg > 0) {
// saved.darkModeActive = 1;
// } else {
// saved.darkModeActive = 0;
// }
// saved = flipTheme(saved);
// storage.writeJSON(SETTINGS_FILE, saved);
// Bangle.drawWidgets();
// load();

BIN
apps/thmswtch/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

117
apps/thmswtch/boot.js Normal file
View File

@ -0,0 +1,117 @@
(function dm() {
function selectRightMode(lt, dt, at) {
if (at < lt && at < dt) {
return "lightT";
} else if (at > lt && at < dt) {
return "darkT";
} else if (at > lt && at > dt) {
return "lightN";
}
}
function setDarkTheme() {
if (!g.theme.dark) {
upd({
fg: cl("#fff"), bg: cl("#000"),
fg2: cl("#fff"), bg2: cl("#004"),
fgH: cl("#fff"), bgH: cl("#00f"),
dark: true
});
}
}
function setLightTheme() {
if (g.theme.dark) {
upd({
fg: cl("#000"), bg: cl("#fff"),
fg2: cl("#000"), bg2: cl("#cff"),
fgH: cl("#000"), bgH: cl("#0ff"),
dark: false
});
}
}
function fixTime(h, m) {
if (h.toString().length < 2) {
h = "0" + h.toString();
}
if (m.toString().length < 2) {
m = "0" + m.toString();
}
return h.toString() + ":" + m.toString();
}
function calculateSunTimes() {
var location = require("Storage").readJSON("mylocation.json", 1) || {};
location.lat = location.lat || 51.5072;
location.lon = location.lon || 0.1276; // London
date = new Date(Date.now());
var times = SunCalc.getTimes(date, location.lat, location.lon);
sunrise = fixTime(times.sunrise.getHours(), times.sunrise.getMinutes());
sunset = fixTime(times.sunset.getHours(), times.sunset.getMinutes());
/* do we want to re-calculate this every day? Or we just assume
that 'show' will get called once a day? */
}
function cl(x) { return g.setColor(x).getColor(); }
function upd(th) {
g.theme = th;
let settings = storage.readJSON('setting.json', 1)
settings.theme = th;
storage.write('setting.json', settings);
delete g.reset;
g._reset = g.reset;
g.reset = function (n) { return g._reset().setColor(th.fg).setBgColor(th.bg); };
g.clear = function (n) { if (n) g.reset(); return g.clearRect(0, 0, g.getWidth(), g.getHeight()); };
g.clear(1);
}
try {
if (Bangle.dmTimeout) clearTimeout(Bangle.dmTimeout); // so the app can eval() this file to apply changes right away
delete Bangle.dmTimeout;
} catch (e) {
print("Bangle.dmTimeout does not exist");
}
const SETTINGS_FILE = "themeSwitch.json";
const storage = require("Storage");
var sunrise, sunset, date;
var SunCalc = require("suncalc"); // from modules folder
let bSettings = storage.readJSON(SETTINGS_FILE, true) || {};
const now = new Date();
let hr = now.getHours() + (now.getMinutes() / 60) + (now.getSeconds() / 3600); // current (decimal) hour
let dmH = parseFloat(bSettings.darkModeAt.split(":")[0]);
let dmM = parseFloat(bSettings.darkModeAt.split(":")[1]);
let lmH = parseFloat(bSettings.lightModeAt.split(":")[0]);
let lmM = parseFloat(bSettings.lightModeAt.split(":")[1]);
print("reading switch timeslots.....");
let dmDec = parseFloat(dmH) + parseFloat(dmM) / parseFloat(60);
let lmDec = parseFloat(lmH) + parseFloat(lmM) / parseFloat(60);
let targetMode = selectRightMode(parseFloat(lmDec), parseFloat(dmDec), parseFloat(hr));
let nextH, nextM;
if (targetMode === "lightT" || targetMode === "lightN") {
nextH = lmH;
nextM = lmM;
} else {
nextH = dmH;
nextM = dmM;
}
let nextDecH = parseFloat(nextH) + parseFloat(nextM) / parseFloat(60);
let t = 3600000 * (nextDecH - hr); // timeout in milliseconds
if (t < 0) { t += 86400000; } // scheduled for tomorrow: add a day
/* update theme mode at the correct time. */
Bangle.dmTimeout = setTimeout(() => {
if (bSettings.darkMode !== 0) {
if (targetMode === "lightT" || targetMode === "lightN") {
setLightTheme();
} else {
setDarkTheme();
}
Bangle.loadWidgets();
Bangle.drawWidgets();
setTimeout(load, 20);
if (bSettings.darkModeBySun !== 0) {
calculateSunTimes();
bSettings.lightModeAt = sunrise;
bSettings.darkModeAt = sunset;
storage.writeJSON(SETTINGS_FILE, bSettings);
}
dm(); // schedule next update
}
}, t);
})();

View File

@ -0,0 +1,15 @@
{ "id": "thmswtch",
"name": "Theme Switcher",
"shortName":"Theme Switcher",
"version":"0.01",
"description": "change theme based on time or sunset/sunrise",
"icon": "app.png",
"tags": "tool",
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"thmswtch.app.js","url":"app.js"},
{"name":"thmswtch.boot.js","url":"boot.js"},
{"name":"thmswtch.img","url":"app-icon.js","evaluate":true}
]
}

202
apps/thmswtch/settings.js Normal file
View File

@ -0,0 +1,202 @@
// const SETTINGS_FILE = "themeSwitch.json";
// const storage = require("Storage");
// var sunrise, sunset, date;
// var SunCalc = require("suncalc"); // from modules folder
// let settings = storage.readJSON('setting.json', 1);
// let saved = storage.readJSON(SETTINGS_FILE, 1) || {};
// if (settings.theme.fg > 0) {
// saved.darkModeActive = 1;
// } else {
// saved.darkModeActive = 0;
// }
// let dmH, dmM, lmH, lmM;
// if (require("Storage").readJSON("themeSwitch.json", 1) !== undefined) {
// dmH = parseInt(saved.darkModeAt.split(":")[0] | 0);
// dmM = parseInt(saved.darkModeAt.split(":")[1] | 0);
// lmH = parseInt(saved.lightModeAt.split(":")[0] | 0);
// lmM = parseInt(saved.lightModeAt.split(":")[1] | 0);
// } else {
// dmH = 0;
// dmM = 0;
// lmH = 0;
// lmM = 0;
// }
// // Main menu
// var mainmenu = {
// "": {
// "title": "Theme Switch"
// },
// "< Back": function () { load(); },
// "Automatic Dark Mode": {
// value: saved.darkMode | false,
// //format: v => v ? "On" : "Off",
// min: 0, max: 1, step: 1,
// onchange: v => {
// saved.darkMode = v;
// storage.writeJSON(SETTINGS_FILE, saved);
// }
// },
// "Dark Mode Active": {
// value: saved.darkModeActive | false,
// format: v => v ? "On" : "Off",
// min: 0, max: 1, step: 1,
// onchange: v => {
// saved.darkModeActive = v;
// storage.writeJSON(SETTINGS_FILE, saved);
// if (v !== 0) {
// setDarkTheme();
// Bangle.drawWidgets();
// } else {
// setLightTheme();
// Bangle.drawWidgets();
// }
// }
// },
// "Dark Mode by Sun": {
// value: saved.darkModeBySun | false,
// format: v => v ? "On" : "Off",
// min: 0, max: 1, step: 1,
// onchange: v => {
// saved.darkModeBySun = v;
// if (v !== 0) {
// //print("calculating sun times");
// calculateSunTimes();
// saved.lightModeAt = sunrise;
// saved.darkModeAt = sunset;
// //print("sunrise" +sunrise);
// //print("sunset" +sunset);
// }
// storage.writeJSON(SETTINGS_FILE, saved);
// },
// },
// "light mode at": {
// value: saved.lightModeAt,
// format: v => saved.lightModeAt,
// onchange: function () {
// if (saved.darkModeBySun === 0) {
// E.showMenu(lightModeAtMenu);
// }
// else {
// E.showAlert("Deactivate dark mode first!", "Action Blocked").then(
// function () { E.showMenu(mainmenu); });
// }
// }
// },
// "dark mode at": {
// value: saved.darkModeAt,
// format: v => saved.darkModeAt,
// onchange: function () {
// if (saved.darkModeBySun === 0) {
// E.showMenu(darkModeAtMenu);
// }
// else {
// E.showAlert("Deactivate dark mode first!", "Action Blocked").then(function () { E.showMenu(mainmenu); });
// }
// }
// },
// "Exit": function () { load(); },
// };
// var lightModeAtMenu = {
// "": {
// "title": "light mode at"
// },
// "Hour": {
// value: lmH,
// min: 0, max: 23, step: 1,
// onchange: v => { lmH = v; }
// },
// "Minute": {
// value: lmM,
// min: 0, max: 59, step: 1,
// onchange: v => { lmM = v; }
// },
// "< Back": function () {
// saved.lightModeAt = fixTime(lmH, lmM);
// storage.writeJSON(SETTINGS_FILE, saved);
// E.showMenu(mainmenu);
// },
// };
// var darkModeAtMenu = {
// "": {
// "title": "dark mode at"
// },
// "Hour": {
// value: dmH,
// min: 0, max: 23, step: 1,
// onchange: v => { dmH = v; }
// },
// "Minute": {
// value: dmM,
// min: 0, max: 59, step: 1,
// onchange: v => { dmM = v; }
// },
// "< Back": function () {
// saved.darkModeAt = fixTime(dmH, dmM);
// storage.writeJSON(SETTINGS_FILE, saved);
// E.showMenu(mainmenu);
// },
// };
// // Actually display the menu
// E.showMenu(mainmenu);
// // Function to fix time format
// function fixTime(h, m) {
// if (h.toString().length < 2) {
// h = "0" + h.toString();
// }
// if (m.toString().length < 2) {
// m = "0" + m.toString();
// }
// return h.toString() + ":" + m.toString();
// }
// function calculateSunTimes() {
// var location = require("Storage").readJSON("mylocation.json", 1) || {};
// location.lat = location.lat || 51.5072;
// location.lon = location.lon || 0.1276; // London
// date = new Date(Date.now());
// var times = SunCalc.getTimes(date, location.lat, location.lon);
// sunrise = fixTime(times.sunrise.getHours(), times.sunrise.getMinutes());
// sunset = fixTime(times.sunset.getHours(), times.sunset.getMinutes());
// /* do we want to re-calculate this every day? Or we just assume
// that 'show' will get called once a day? */
// }
// function cl(x) { return g.setColor(x).getColor(); }
// function upd(th) {
// g.theme = th;
// settings.theme = th;
// storage.write('setting.json', settings);
// delete g.reset;
// g._reset = g.reset;
// g.reset = function (n) { return g._reset().setColor(th.fg).setBgColor(th.bg); };
// g.clear = function (n) { if (n) g.reset(); return g.clearRect(0, 0, g.getWidth(), g.getHeight()); };
// g.clear(1);
// }
// function setDarkTheme() {
// if (!g.theme.dark) {
// upd({
// fg: cl("#fff"), bg: cl("#000"),
// fg2: cl("#fff"), bg2: cl("#004"),
// fgH: cl("#fff"), bgH: cl("#00f"),
// dark: true
// });
// }
// }
// function setLightTheme() {
// if (g.theme.dark) {
// upd({
// fg: cl("#000"), bg: cl("#fff"),
// fg2: cl("#000"), bg2: cl("#cff"),
// fgH: cl("#000"), bgH: cl("#0ff"),
// dark: false
// });
// }
// }