mirror of https://github.com/espruino/BangleApps
Merge pull request #194 from rigrig/app_settings
Settings: Add support for app/widget settingspull/195/head
commit
5e8d6beefe
|
@ -117,7 +117,7 @@
|
|||
{ "id": "setting",
|
||||
"name": "Settings",
|
||||
"icon": "settings.png",
|
||||
"version":"0.07",
|
||||
"version":"0.08",
|
||||
"description": "A menu for setting up Bangle.js",
|
||||
"tags": "tool,system",
|
||||
"storage": [
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
0.05: Fix Settings json
|
||||
0.06: Remove distance setting as there's a separate app for Locale now
|
||||
0.07: Added vibrate as beep workaround
|
||||
0.08: Add support for app/widget settings
|
||||
|
|
|
@ -114,6 +114,7 @@ function showMainMenu() {
|
|||
}
|
||||
},
|
||||
'Set Time': showSetTimeMenu,
|
||||
'App/widget settings': showAppSettingsMenu,
|
||||
'Reset Settings': showResetMenu,
|
||||
'Turn Off': Bangle.off,
|
||||
'< Back': ()=> {load();}
|
||||
|
@ -295,4 +296,48 @@ function showSetTimeMenu() {
|
|||
return E.showMenu(timemenu);
|
||||
}
|
||||
|
||||
function showAppSettingsMenu(){
|
||||
let appmenu = {
|
||||
'': {'title': 'App Settings'},
|
||||
'< Back': showMainMenu,
|
||||
}
|
||||
const apps = storage.list(/\.info$/)
|
||||
.map(app => storage.readJSON(app, 1))
|
||||
.filter(app => app && app.settings)
|
||||
.sort((a, b) => a.sortorder - b.sortorder)
|
||||
if (apps.length === 0) {
|
||||
appmenu['No app has settings'] = () => {};
|
||||
}
|
||||
apps.forEach(function (app) {
|
||||
appmenu[app.name] = () => {showAppSettings(app)};
|
||||
})
|
||||
E.showMenu(appmenu)
|
||||
}
|
||||
function showAppSettings(app) {
|
||||
const showError = msg => {
|
||||
E.showMessage(`${app.name}:\n${msg}!\n\nBTN1 to go back`);
|
||||
setWatch(showAppSettingsMenu, BTN1, { repeat: false });
|
||||
}
|
||||
let appSettings = storage.read(app.settings);
|
||||
if (!appSettings) {
|
||||
return showError('Missing settings');
|
||||
}
|
||||
try {
|
||||
appSettings = eval(appSettings);
|
||||
} catch (e) {
|
||||
console.log(`${app.name} settings error:`, e)
|
||||
return showError('Error in settings');
|
||||
}
|
||||
if (typeof appSettings !== "function") {
|
||||
return showError('Invalid settings');
|
||||
}
|
||||
try {
|
||||
// pass showAppSettingsMenu as "back" argument
|
||||
appSettings(showAppSettingsMenu);
|
||||
} catch (e) {
|
||||
console.log(`${app.name} settings error:`, e)
|
||||
return showError('Error in settings');
|
||||
}
|
||||
}
|
||||
|
||||
showMainMenu();
|
||||
|
|
|
@ -60,6 +60,8 @@ var AppInfo = {
|
|||
if (app.type && app.type!="app") json.type = app.type;
|
||||
if (fileContents.find(f=>f.name==app.id+".app.js"))
|
||||
json.src = app.id+".app.js";
|
||||
if (fileContents.find(f=>f.name==app.id+".settings.js"))
|
||||
json.settings = app.id+".settings.js";
|
||||
if (fileContents.find(f=>f.name==app.id+".img"))
|
||||
json.icon = app.id+".img";
|
||||
if (app.sortorder) json.sortorder = app.sortorder;
|
||||
|
|
Loading…
Reference in New Issue