BangleApps/apps/pebble/pebble.settings.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-11-29 20:12:25 +00:00
(function(back) {
const SETTINGS_FILE = "pebble.json";
// TODO Only the color/theme indices should be written in the settings file so the labels can be translated
// Initialize with default settings...
2022-03-29 14:27:34 +00:00
let s = {'bg': '#0f0', 'color': 'Green', 'theme':'System', 'showlock':false}
2021-11-29 20:12:25 +00:00
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage');
2021-11-29 20:12:25 +00:00
let settings = storage.readJSON(SETTINGS_FILE, 1) || s;
const saved = settings || {};
2021-11-29 20:12:25 +00:00
for (const key in saved) {
s[key] = saved[key]
}
function save() {
settings = s;
storage.write(SETTINGS_FILE, settings);
2021-11-29 20:12:25 +00:00
}
var color_options = ['Green','Orange','Cyan','Purple','Red','Blue'];
2021-11-29 20:12:25 +00:00
var bg_code = ['#0f0','#ff0','#0ff','#f0f','#f00','#00f'];
2022-03-29 11:39:55 +00:00
var theme_options = ['System', 'Light', 'Dark'];
2021-11-29 20:12:25 +00:00
E.showMenu({
'': { 'title': 'Pebble Clock' },
/*LANG*/'< Back': back,
/*LANG*/'Colour': {
2021-11-29 20:12:25 +00:00
value: 0 | color_options.indexOf(s.color),
min: 0, max: 5,
format: v => color_options[v],
onchange: v => {
s.color = color_options[v];
s.bg = bg_code[v];
save();
2022-03-29 12:10:48 +00:00
}
},
/*LANG*/'Theme': {
2022-03-29 11:39:55 +00:00
value: 0 | theme_options.indexOf(s.theme),
min: 0, max: theme_options.length - 1,
format: v => theme_options[v],
onchange: v => {
s.theme = theme_options[v];
save();
2022-03-29 12:00:55 +00:00
}
2022-03-29 14:24:13 +00:00
},
/*LANG*/'Show Lock': {
2022-03-29 14:27:34 +00:00
value: settings.showlock,
onchange: () => {
settings.showlock = !settings.showlock;
2022-03-29 14:24:13 +00:00
save();
}
2022-03-29 14:27:34 +00:00
},
2021-11-29 20:12:25 +00:00
});
})