2023-05-05 17:09:58 +00:00
|
|
|
(function (back) {
|
2023-05-08 02:28:56 +00:00
|
|
|
let teletextColors = ["#000", "#f00", "#0f0", "#ff0", "#00f", "#f0f", "#0ff", "#fff"];
|
|
|
|
let teletextColorNames = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"];
|
2023-05-05 17:09:58 +00:00
|
|
|
|
|
|
|
// Load and set default settings
|
|
|
|
let appSettings = Object.assign({
|
|
|
|
color: teletextColors[6],
|
|
|
|
theme: 'light',
|
2023-05-08 02:28:56 +00:00
|
|
|
}, require('Storage').readJSON(shadowclk.json, true) || {});
|
2023-05-05 17:09:58 +00:00
|
|
|
|
|
|
|
// Save settings to storage
|
|
|
|
function writeSettings() {
|
2023-05-08 02:28:56 +00:00
|
|
|
require('Storage').writeJSON(shadowclk.json, appSettings);
|
2023-05-05 17:09:58 +00:00
|
|
|
}
|
2023-05-06 12:25:34 +00:00
|
|
|
|
2023-05-08 02:24:00 +00:00
|
|
|
// Colors from 'Light BW' and 'Dark BW' themes
|
2023-05-06 12:25:34 +00:00
|
|
|
function createThemeColors(mode) {
|
|
|
|
const cl = x => g.setColor(x).getColor();
|
|
|
|
return mode ? {
|
|
|
|
fg: cl("#fff"), bg: cl("#000"), fg2: cl("#fff"), bg2: cl("#004"), fgH: cl("#fff"), bgH: cl("#00f"), dark: true
|
|
|
|
} : {
|
|
|
|
fg: cl("#000"), bg: cl("#fff"), fg2: cl("#000"), bg2: cl("#cff"), fgH: cl("#000"), bgH: cl("#0ff"), dark: false
|
|
|
|
};
|
2023-05-05 18:32:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 17:09:58 +00:00
|
|
|
// Switch theme and save to storage
|
|
|
|
function switchTheme(mode) {
|
|
|
|
if (mode === g.theme.dark) return;
|
2023-05-08 02:28:56 +00:00
|
|
|
let s = require("Storage").readJSON(setting.json, 1) || {};
|
2023-05-06 12:25:34 +00:00
|
|
|
s.theme = createThemeColors(mode);
|
2023-05-08 02:28:56 +00:00
|
|
|
require("Storage").writeJSON(setting.json, s);
|
2023-05-06 12:25:34 +00:00
|
|
|
updateTheme(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the current menu with the new theme
|
|
|
|
function updateTheme(mode) {
|
|
|
|
let newTheme = createThemeColors(mode);
|
|
|
|
g.theme = newTheme;
|
|
|
|
appSettings.theme = mode ? 'dark' : 'light';
|
|
|
|
writeSettings();
|
|
|
|
delete g.reset;
|
|
|
|
g._reset = g.reset;
|
|
|
|
g.reset = function (n) { return g._reset().setColor(newTheme.fg).setBgColor(newTheme.bg); };
|
|
|
|
g.clear = function (n) { if (n) g.reset(); return g.clearRect(0, 0, g.getWidth(), g.getHeight()); };
|
|
|
|
g.clear(1);
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
showMenu();
|
2023-05-05 17:09:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 12:25:34 +00:00
|
|
|
// Read the current system theme
|
|
|
|
function getCurrentTheme() {
|
2023-05-08 02:28:56 +00:00
|
|
|
let s = require("Storage").readJSON(setting.json, 1) || {};
|
2023-05-06 12:25:34 +00:00
|
|
|
return s.theme.dark ? 'dark' : 'light';
|
|
|
|
}
|
2023-05-05 18:32:11 +00:00
|
|
|
|
2023-05-06 12:25:34 +00:00
|
|
|
function showMenu() {
|
|
|
|
appSettings.theme = getCurrentTheme();
|
|
|
|
E.showMenu({
|
|
|
|
"": { "title": "Shadow Clock" },
|
|
|
|
"< Back": () => back(),
|
|
|
|
'Theme:': {
|
|
|
|
value: (appSettings.theme === 'dark'),
|
|
|
|
format: v => v ? "Dark" : "Light",
|
|
|
|
onchange: v => {
|
|
|
|
switchTheme(v);
|
|
|
|
}
|
2023-05-05 17:09:58 +00:00
|
|
|
},
|
2023-05-06 12:25:34 +00:00
|
|
|
'Color:': {
|
|
|
|
value: teletextColors.indexOf(appSettings.color),
|
|
|
|
min: 0,
|
|
|
|
max: 7,
|
|
|
|
onchange: v => {
|
|
|
|
appSettings.color = teletextColors[v];
|
|
|
|
writeSettings();
|
|
|
|
},
|
|
|
|
format: v => teletextColorNames[v]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Initially show the menu
|
|
|
|
showMenu();
|
2023-05-07 19:52:00 +00:00
|
|
|
});
|