var appJSON = []; // List of apps and info from apps.json var appsInstalled = []; // list of app JSON var files = []; // list of files on Bangle httpGet("apps.json").then(apps=>{ try { appJSON = JSON.parse(apps); } catch(e) { console.log(e); showToast("App List Corrupted","error"); } appJSON.sort(appSorter); refreshLibrary(); }); // Status // =========================================== Top Navigation function showToast(message, type) { // toast-primary, toast-success, toast-warning or toast-error var style = "toast-primary"; if (type=="success") style = "toast-success"; else if (type=="error") style = "toast-error"; else if (type!==undefined) console.log("showToast: unknown toast "+type); var toastcontainer = document.getElementById("toastcontainer"); var msgDiv = htmlElement(`
`); msgDiv.innerHTML = message; toastcontainer.append(msgDiv); setTimeout(function() { msgDiv.remove(); }, 5000); } var progressToast; // the DOM element var progressSticky; // showProgress(,,"sticky") don't remove until hideProgress("sticky") var progressInterval; // the interval used if showProgress(..., "animate") var progressPercent; // the current progress percentage function showProgress(text, percent, sticky) { if (sticky=="sticky") progressSticky = true; if (!progressToast) { if (progressInterval) { clearInterval(progressInterval); progressInterval = undefined; } if (percent == "animate") { progressInterval = setInterval(function() { progressPercent += 2; if (progressPercent>100) progressPercent=0; showProgress(undefined, progressPercent); }, 100); percent = 0; } progressPercent = percent; var toastcontainer = document.getElementById("toastcontainer"); progressToast = htmlElement(`
${text ? `
${text}
`:``}
`); toastcontainer.append(progressToast); } else { var pt=document.getElementById("progressToast"); pt.setAttribute("aria-valuenow",percent); pt.style.width = percent+"%"; } } function hideProgress(sticky) { if (progressSticky && sticky!="sticky") return; progressSticky = false; if (progressInterval) { clearInterval(progressInterval); progressInterval = undefined; } if (progressToast) progressToast.remove(); progressToast = undefined; } Puck.writeProgress = function(charsSent, charsTotal) { if (charsSent===undefined) { hideProgress(); return; } var percent = Math.round(charsSent*100/charsTotal); showProgress(undefined, percent); } function showPrompt(title, text, buttons) { if (!buttons) buttons={yes:1,no:1}; return new Promise((resolve,reject) => { var modal = htmlElement(``); document.body.append(modal); modal.querySelector("a[href='#close']").addEventListener("click",event => { event.preventDefault(); reject("User cancelled"); modal.remove(); }); htmlToArray(modal.getElementsByTagName("button")).forEach(button => { button.addEventListener("click",event => { event.preventDefault(); var isYes = event.target.getAttribute("isyes")=="1"; if (isYes) resolve(); else reject("User cancelled"); modal.remove(); }); }); }); } function showChangeLog(appid) { var app = appNameToApp(appid); function show(contents) { showPrompt(app.name+" Change Log",contents,{ok:true}).catch(()=>{});; } httpGet(`apps/${appid}/ChangeLog`). then(show).catch(()=>show("No Change Log available")); } function handleCustomApp(appTemplate) { // Pops up an IFRAME that allows an app to be customised if (!appTemplate.custom) throw new Error("App doesn't have custom HTML"); return new Promise((resolve,reject) => { var modal = htmlElement(`