1
0
Fork 0
BangleApps/apps/run/settings.js

130 lines
3.9 KiB
JavaScript
Raw Normal View History

(function(back) {
const SETTINGS_FILE = "run.json";
var ExStats = require("exstats");
var statsList = ExStats.getList();
statsList.unshift({name:"-",id:""}); // add blank menu item
var statsIDs = statsList.map(s=>s.id);
// ...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 = Object.assign({
2022-03-01 05:54:27 +00:00
record: true,
B1: "dist",
B2: "time",
B3: "pacea",
2022-03-01 06:16:24 +00:00
B4: "bpm",
B5: "step",
B6: "caden",
paceLength: 1000, // TODO: Default to either 1km or 1mi based on locale
notify: {
dist: {
increment: 0,
2022-03-05 09:28:23 +00:00
notifications: [],
},
2022-03-05 09:07:10 +00:00
step: {
increment: 0,
2022-03-05 09:28:23 +00:00
notifications: [],
},
time: {
increment: 0,
2022-03-05 09:28:23 +00:00
notifications: [],
},
},
}, storage.readJSON(SETTINGS_FILE, 1) || {});
function saveSettings() {
storage.write(SETTINGS_FILE, settings)
}
function getBoxChooser(boxID) {
return {
2022-03-01 05:54:27 +00:00
min: 0, max: statsIDs.length-1,
value: Math.max(statsIDs.indexOf(settings[boxID]),0),
format: v => statsList[v].name,
onchange: v => {
settings[boxID] = statsIDs[v];
saveSettings();
},
}
}
2022-03-05 09:28:23 +00:00
function sampleBuzz(buzzPatterns) {
2022-03-05 09:42:07 +00:00
return buzzPatterns.reduce(function (promise, buzzPattern) {
return promise.then(function () {
2022-03-05 09:28:23 +00:00
return Bangle.buzz(buzzPattern[0], buzzPattern[1]);
});
}, Promise.resolve());
}
var menu = {
'': { 'title': 'Run' },
'< Back': back,
};
if (global.WIDGETS&&WIDGETS["recorder"])
menu[/*LANG*/"Record Run"] = {
value : !!settings.record,
onchange : v => {
settings.record = v;
saveSettings();
}
};
var notificationsMenu = {
'< Back': function() { E.showMenu(menu) },
}
menu[/*LANG*/"Notifications"] = function() { E.showMenu(notificationsMenu)};
2022-03-05 08:22:14 +00:00
ExStats.appendMenuItems(menu, settings, saveSettings);
ExStats.appendNotifyMenuItems(notificationsMenu, settings, saveSettings);
var vibPatterns = [/*LANG*/"Off", ".", "-", "--", "-.-", "---"];
2022-03-05 09:01:02 +00:00
var vibTimes = [
[],
[[100, 1]],
2022-03-05 20:05:48 +00:00
[[300, 1]],
[[300, 1], [300, 0], [300, 1]],
[[300, 1],[300, 0], [100, 1], [300, 0], [300, 1]],
[[300, 1],[300, 0],[300, 1],[300, 0],[300, 1]],
2022-03-05 09:01:02 +00:00
];
2022-03-05 22:14:07 +00:00
notificationsMenu[/*LANG*/"Dist Pattern"] = {
value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.dist.notifications))),
min: 0, max: vibTimes.length - 1,
format: v => vibPatterns[v]||/*LANG*/"Off",
onchange: v => {
2022-03-05 20:38:23 +00:00
settings.notify.dist.notifications = vibTimes[v];
sampleBuzz(vibTimes[v]);
saveSettings();
}
}
2022-03-05 22:14:07 +00:00
notificationsMenu[/*LANG*/"Step Pattern"] = {
value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.step.notifications))),
min: 0, max: vibTimes.length - 1,
format: v => vibPatterns[v]||/*LANG*/"Off",
onchange: v => {
2022-03-05 20:38:23 +00:00
settings.notify.step.notifications = vibTimes[v];
sampleBuzz(vibTimes[v]);
saveSettings();
}
}
2022-03-05 22:14:07 +00:00
notificationsMenu[/*LANG*/"Time Pattern"] = {
value: Math.max(0,vibTimes.findIndex((p) => JSON.stringify(p) === JSON.stringify(settings.notify.time.notifications))),
min: 0, max: vibTimes.length - 1,
format: v => vibPatterns[v]||/*LANG*/"Off",
onchange: v => {
2022-03-05 20:38:23 +00:00
settings.notify.time.notifications = vibTimes[v];
sampleBuzz(vibTimes[v]);
saveSettings();
}
}
2022-03-05 22:14:07 +00:00
var boxMenu = {
'< Back': function() { E.showMenu(menu) },
}
Object.assign(boxMenu,{
'Box 1': getBoxChooser("B1"),
'Box 2': getBoxChooser("B2"),
'Box 3': getBoxChooser("B3"),
'Box 4': getBoxChooser("B4"),
'Box 5': getBoxChooser("B5"),
'Box 6': getBoxChooser("B6"),
});
2022-03-05 22:14:07 +00:00
menu[/*LANG*/"Boxes"] = function() { E.showMenu(boxMenu)};
E.showMenu(menu);
})