Add button clear everything and reload default apps

pull/94/head
Gordon Williams 2020-02-04 16:13:06 +00:00
parent 8992ad545a
commit 692ff509e5
3 changed files with 36 additions and 1 deletions

1
defaultapps.json Normal file
View File

@ -0,0 +1 @@
["boot","launch","mclock","setting","sbat","sbt"]

View File

@ -126,7 +126,8 @@
<h3>Utilities</h3>
<p><button class="btn" id="settime">Set Bangle.js Time</button>
<button class="btn" id="removeall">Remove all Apps</button></p>
<button class="btn" id="removeall">Remove all Apps</button>
<button class="btn" id="installdefault">Install default apps</button></p>
</div>
</div>

View File

@ -432,3 +432,36 @@ document.getElementById("removeall").addEventListener("click",event=>{
});
});
});
// Install all default apps in one go
document.getElementById("installdefault").addEventListener("click",event=>{
var defaultApps
httpGet("defaultapps.json").then(json=>{
defaultApps = JSON.parse(json);
defaultApps = defaultApps.map( appid => appJSON.find(app=>app.id==appid) );
if (defaultApps.some(x=>x===undefined))
throw "Not all apps found";
return showPrompt("Install Defaults","Remove everything and install default apps?");
}).then(() => {
return Comms.removeAllApps();
}).then(()=>{
showToast("Existing apps removed","success");
return new Promise(resolve => {
function upload() {
var app = defaultApps.shift();
if (app===undefined) return resolve();
Comms.uploadApp(app).then((appJSON) => {
if (appJSON) appsInstalled.push(appJSON);
showToast(app.name+" Uploaded", "success");
upload();
});
}
upload();
});
}).then(()=>{
showToast("Default apps successfully installed!","success");
refreshMyApps();
refreshLibrary();
}).catch(err=>{
showToast("App Install failed, "+err,"error");
});
});