add settings.js

pull/1385/head
Ronin0000 2022-02-02 15:29:32 -08:00 committed by GitHub
parent 0b4d2b5b5d
commit 0020533864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 0 deletions

38
apps/torch/settings.js Normal file
View File

@ -0,0 +1,38 @@
(function(back) {
const SETTINGS_FILE = "torch.json";
// initialize with default settings...
let s = {'bg': '#0f0', 'color': 'Green'}
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage')
let settings = storage.readJSON(SETTINGS_FILE, 1) || s;
const saved = settings || {}
for (const key in saved) {
s[key] = saved[key]
}
function save() {
settings = s
storage.write(SETTINGS_FILE, settings)
}
var color_options = ['Green','Orange','Cyan','Purple','Red','Blue','Yellow'];
var bg_code = ['#0f0','#ff0','#0ff','#f0f','#f00','#00f','#ffef00'];
E.showMenu({
'': { 'title': 'Torch' },
'< Back': back,
'Colour': {
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();
},
}
});
})