Add Select Clock option to settings app

This adds an option to select the preferred clock to show on the
main screen.

The settings app menu lists all apps of type 'clock' with the
current one marked with a *. It stores the src property
of the selected clock as settings.clock.

The bootloader app checks this property and tries to load
that app. If the property is not set, or the app not found
then it reverts to the current behaviour of using the first
clock app it finds.
pull/49/head
Nick O'Leary 2019-11-16 22:13:49 +00:00
parent 9de2210084
commit c89ad11d69
3 changed files with 60 additions and 11 deletions

View File

@ -101,12 +101,28 @@ if (startapp) {
function drawWidgets() {
for (var w of WIDGETS) w.draw();
}
var clockApps = require("Storage").list().filter(a=>a[0]=='+').map(app=>{
try { return require("Storage").readJSON(app); }
catch (e) {}
}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder);
if (clockApps && clockApps.length > 0) eval(require("Storage").read(clockApps[0].src));
var settings;
try {
settings = require("Storage").readJSON('@setting');
} catch (e) {
settings = {}
}
var clockApp = settings.clock;
if (clockApp) {
clockApp = require("Storage").read(clockApp)
}
if (!clockApp) {
var clockApps = require("Storage").list().filter(a=>a[0]=='+').map(app=>{
try { return require("Storage").readJSON(app); }
catch (e) {}
}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder);
if (clockApps && clockApps.length > 0) {
clockApp = require("Storage").read(clockApps[0].src);
}
}
if (clockApp) eval(clockApp);
else E.showMessage("No Clock Found");
delete clockApps;
require("Storage").list().filter(a=>a[0]=='=').forEach(widget=>eval(require("Storage").read(widget)));
setTimeout(drawWidgets,100);

View File

@ -27,6 +27,7 @@ function resetSettings() {
HID : false,
HIDGestures: false,
debug: false,
clock: null
};
setLCDTimeout(settings.timeout);
updateSettings();
@ -92,6 +93,7 @@ function showMainMenu() {
}
}
},
'Select Clock': showClockMenu,
'Time Zone': {
value: settings.timezone,
min: -11,
@ -174,6 +176,37 @@ function makeConnectable() {
showMainMenu();
});
}
function showClockMenu() {
var clockApps = require("Storage").list().filter(a=>a[0]=='+').map(app=>{
try { return require("Storage").readJSON(app); }
catch (e) {}
}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder);
const clockMenu = {
'': {
'title': 'Select Clock',
},
'< Back': showMainMenu,
};
clockApps.forEach(app => {
var label = app.name;
if (settings.clock === app.src) {
label = "* "+label;
}
clockMenu[label] = () => {
if (settings.clock !== app.src) {
settings.clock = app.src;
updateSettings();
showMainMenu();
}
};
});
if (clockApps.length === 0) {
clockMenu["No Clocks Found"] = () => {};
}
return Bangle.menu(clockMenu);
}
function showSetTimeMenu() {
d = new Date();

File diff suppressed because one or more lines are too long