change menu to match theme switching from settings

master
stweedo 2023-05-06 07:25:34 -05:00
parent 52c8df698b
commit 10905e98cc
1 changed files with 58 additions and 41 deletions

View File

@ -1,5 +1,4 @@
(function (back) { (function (back) {
// Constants
const LOC = "shadowclk.json"; const LOC = "shadowclk.json";
const SYS = "setting.json"; const SYS = "setting.json";
const teletextColors = ["#000", "#f00", "#0f0", "#ff0", "#00f", "#f0f", "#0ff", "#fff"]; const teletextColors = ["#000", "#f00", "#0f0", "#ff0", "#00f", "#f0f", "#0ff", "#fff"];
@ -16,52 +15,70 @@
require('Storage').writeJSON(LOC, appSettings); require('Storage').writeJSON(LOC, appSettings);
} }
// Sync theme with current Bangle.js theme // Colors from 'Ligh BW' and 'Dark BW' themes
function syncTheme() { function createThemeColors(mode) {
let sysSettings = require('Storage').readJSON(SYS, 1) || {}; const cl = x => g.setColor(x).getColor();
appSettings.theme = sysSettings.theme && sysSettings.theme.dark ? 'dark' : 'light'; 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
};
} }
// Switch theme and save to storage // Switch theme and save to storage
function switchTheme(mode) { function switchTheme(mode) {
if (mode === g.theme.dark) return; if (mode === g.theme.dark) return;
let s = require("Storage").readJSON(SYS, 1) || {}; let s = require("Storage").readJSON(SYS, 1) || {};
const cl = x => g.setColor(x).getColor(); s.theme = createThemeColors(mode);
s.theme = mode ? { require("Storage").writeJSON(SYS, s);
fg: cl("#fff"), bg: cl("#000"), fg2: cl("#0ff"), bg2: cl("#000"), fgH: cl("#fff"), bgH: cl("#00f"), dark: true updateTheme(mode);
} : {
fg: cl("#000"), bg: cl("#fff"), fg2: cl("#000"), bg2: cl("#cff"), fgH: cl("#000"), bgH: cl("#0ff"), dark: false
};
require("Storage").writeJSON("setting.json", s);
if (Bangle.CLOCK) load(global.__FILE__);
} }
// Sync theme before showing settings menu // Update the current menu with the new theme
syncTheme(); 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();
}
// Show settings menu // Read the current system theme
E.showMenu({ function getCurrentTheme() {
"": {"title": "Shadow Clock"}, let s = require("Storage").readJSON(SYS, 1) || {};
"< Back": () => back(), return s.theme.dark ? 'dark' : 'light';
'Theme:': { }
value: (appSettings.theme === 'dark'),
format: v => v ? "Dark" : "Light", function showMenu() {
onchange: v => { appSettings.theme = getCurrentTheme();
const newTheme = v ? 'dark' : 'light'; E.showMenu({
switchTheme(newTheme === 'dark'); "": { "title": "Shadow Clock" },
appSettings.theme = newTheme; "< Back": () => back(),
writeSettings(); 'Theme:': {
} value: (appSettings.theme === 'dark'),
}, format: v => v ? "Dark" : "Light",
'Color:': { onchange: v => {
value: teletextColors.indexOf(appSettings.color), switchTheme(v);
min: 0, }
max: 7,
onchange: v => {
appSettings.color = teletextColors[v];
writeSettings();
}, },
format: v => teletextColorNames[v] '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();
}); });