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"];
@ -15,53 +14,71 @@
function writeSettings() { function writeSettings() {
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
}; // Update the current menu with the new theme
require("Storage").writeJSON("setting.json", s); function updateTheme(mode) {
if (Bangle.CLOCK) load(global.__FILE__); 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();
} }
// Sync theme before showing settings menu // Read the current system theme
syncTheme(); function getCurrentTheme() {
let s = require("Storage").readJSON(SYS, 1) || {};
return s.theme.dark ? 'dark' : 'light';
}
// Show settings menu function showMenu() {
E.showMenu({ appSettings.theme = getCurrentTheme();
"": {"title": "Shadow Clock"}, E.showMenu({
"< Back": () => back(), "": { "title": "Shadow Clock" },
'Theme:': { "< Back": () => back(),
value: (appSettings.theme === 'dark'), 'Theme:': {
format: v => v ? "Dark" : "Light", value: (appSettings.theme === 'dark'),
onchange: v => { format: v => v ? "Dark" : "Light",
const newTheme = v ? 'dark' : 'light'; onchange: v => {
switchTheme(newTheme === 'dark'); switchTheme(v);
appSettings.theme = newTheme; }
writeSettings();
}
},
'Color:': {
value: teletextColors.indexOf(appSettings.color),
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();
});