forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockFace_menu.js
More file actions
52 lines (49 loc) · 1.43 KB
/
Copy pathClockFace_menu.js
File metadata and controls
52 lines (49 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Add setting items to a menu
*
* @param {object} menu Menu to add items to
* @param {function} callback Callback when value changes
* @param {object} items Menu items to add, with their current value
*/
exports.addItems = function(menu, callback, items) {
Object.keys(items).forEach(key => {
let value = items[key];
const label = {
showDate:/*LANG*/"Show date",
loadWidgets:/*LANG*/"Load widgets",
powerSave:/*LANG*/"Power saving",
}[key];
switch(key) {
// boolean options which default to true
case "showDate":
case "loadWidgets":
if (value===undefined) value = true;
// fall through
case "powerSave":
// same for all boolean options:
menu[label] = {
value: !!value,
onchange: v => callback(key, v),
};
}
});
};
/**
* Create a basic settings menu for app, reading/writing to settings file
*
* @param {object} menu Menu to add settings to
* @param {string} settingsFile File to read/write settings to/from
* @param {string[]} items List of settings to add
*/
exports.addSettingsFile = function(menu, settingsFile, items) {
let s = require("Storage").readJSON(settingsFile, true) || {};
function save(key, value) {
s[key] = value;
require("Storage").writeJSON(settingsFile, s);
}
let toAdd = {};
items.forEach(function(key) {
toAdd[key] = s[key];
});
exports.addItems(menu, save, toAdd);
};