// check icon to figure out what we should do
if (icon.classList.contains("icon-delete")) removeApp(app);
if (icon.classList.contains("icon-refresh")) updateApp(app);
- if (icon.classList.contains("icon-download")) handleAppInterface(app)
+ if (icon.classList.contains("icon-download")) handleAppInterface(app);
});
});
}
@@ -405,7 +433,7 @@ return `
let haveInstalledApps = false;
function getInstalledApps(refresh) {
if (haveInstalledApps && !refresh) {
- return Promise.resolve(appsInstalled)
+ return Promise.resolve(appsInstalled);
}
showLoadingIndicator("myappscontainer");
// Get apps and files
@@ -453,7 +481,7 @@ filtersContainer.addEventListener('click', ({ target }) => {
activeFilter = target.getAttribute('filterid') || '';
refreshFilter();
refreshLibrary();
- window.location.hash = activeFilter
+ window.location.hash = activeFilter;
});
var librarySearchInput = document.querySelector("#searchform input");
@@ -526,7 +554,7 @@ document.getElementById("installdefault").addEventListener("click",event=>{
upload();
}).catch(function() {
Progress.hide({sticky:true});
- reject()
+ reject();
});
}
upload();
@@ -541,3 +569,48 @@ document.getElementById("installdefault").addEventListener("click",event=>{
showToast("App Install failed, "+err,"error");
});
});
+
+// Install all favoutrie apps in one go
+document.getElementById("installfavourite").addEventListener("click",event=>{
+ var defaultApps, appCount;
+ asyncLocalStorage.getItem(FAVOURITE).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";
+ appCount = defaultApps.length;
+ return showPrompt("Install Defaults","Remove everything and install favourite apps?");
+ }).then(() => {
+ return Comms.removeAllApps();
+ }).then(()=>{
+ Progress.hide({sticky:true});
+ appsInstalled = [];
+ showToast(`Existing apps removed. Installing ${appCount} apps...`);
+ return new Promise((resolve,reject) => {
+ function upload() {
+ var app = defaultApps.shift();
+ if (app===undefined) return resolve();
+ Progress.show({title:`${app.name} (${appCount-defaultApps.length}/${appCount})`,sticky:true});
+ Comms.uploadApp(app,"skip_reset").then((appJSON) => {
+ Progress.hide({sticky:true});
+ if (appJSON) appsInstalled.push(appJSON);
+ showToast(`(${appCount-defaultApps.length}/${appCount}) ${app.name} Uploaded`);
+ upload();
+ }).catch(function() {
+ Progress.hide({sticky:true});
+ reject();
+ });
+ }
+ upload();
+ });
+ }).then(()=>{
+ return Comms.setTime();
+ }).then(()=>{
+ showToast("Favourites apps successfully installed!","success");
+ return getInstalledApps(true);
+ }).catch(err=>{
+ Progress.hide({sticky:true});
+ showToast("App Install failed, "+err,"error");
+ });
+});
+
diff --git a/js/ui.js b/js/ui.js
index 616a92555..ea6885eac 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -86,6 +86,7 @@ function showToast(message, type) {
var style = "toast-primary";
if (type=="success") style = "toast-success";
else if (type=="error") style = "toast-error";
+ else if (type=="warning") style = "toast-warning";
else if (type!==undefined) console.log("showToast: unknown toast "+type);
var toastcontainer = document.getElementById("toastcontainer");
var msgDiv = htmlElement(`
`);
diff --git a/js/utils.js b/js/utils.js
index 85b6eb0a1..4913c7129 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -67,3 +67,16 @@ function getVersionInfo(appListing, appInstalled) {
canUpdate : canUpdate
}
}
+
+const asyncLocalStorage = {
+ setItem: function (key, value) {
+ return Promise.resolve().then(function () {
+ localStorage.setItem(key, value);
+ });
+ },
+ getItem: function (key) {
+ return Promise.resolve().then(function () {
+ return localStorage.getItem(key);
+ });
+ }
+};