From 9f4118066464ce438e18ed5686190c0a196227f9 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 5 Jun 2020 11:22:43 +0100 Subject: [PATCH] Dependency handling fix - now choose the dependency highest up the JSON list (before sorting, not after!) --- js/comms.js | 13 ++++++++++--- js/index.js | 15 +++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/js/comms.js b/js/comms.js index 4ae7c9a21..160e5c0e9 100644 --- a/js/comms.js +++ b/js/comms.js @@ -1,16 +1,23 @@ -Puck.debug=3; +//Puck.debug=3; +console.log("=============================================") +console.log("Type 'Puck.debug=3' for full BLE debug info") +console.log("=============================================") // FIXME: use UART lib so that we handle errors properly const Comms = { reset : (opt) => new Promise((resolve,reject) => { - let tries = 5; + let tries = 8; + console.log(" reset"); Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`,function rstHandler(result) { console.log(" reset: got "+JSON.stringify(result)); if (result===null) return reject("Connection failed"); if (result=="" && (tries-- > 0)) { console.log(` reset: no response. waiting ${tries}...`); Puck.write("\x03",rstHandler); - } else setTimeout(resolve,250); + } else { + console.log(` reset: complete.`); + setTimeout(resolve,250); + } }); }), uploadApp : (app,skipReset) => { // expects an apps.json structure (i.e. with `storage`) diff --git a/js/index.js b/js/index.js index 8e1338675..c32e5342f 100644 --- a/js/index.js +++ b/js/index.js @@ -15,7 +15,6 @@ httpGet("apps.json").then(apps=>{ console.log(e); showToast("App List Corrupted","error"); } - appJSON.sort(appSorter); refreshLibrary(); refreshFilter(); }); @@ -225,7 +224,7 @@ function refreshSort(){ } function refreshLibrary() { let panelbody = document.querySelector("#librarycontainer .panel-body"); - let visibleApps = appJSON; + let visibleApps = appJSON.slice(); // clone so we don't mess with the original let favourites = SETTINGS.favourites; if (activeFilter) { @@ -240,8 +239,8 @@ function refreshLibrary() { visibleApps = visibleApps.filter(app => app.name.toLowerCase().includes(currentSearch) || app.tags.includes(currentSearch)); } + visibleApps.sort(appSorter); if (activeSort) { - visibleApps = visibleApps.slice(); // clone the array so sort doesn't mess with original if (activeSort=="created" || activeSort=="modified") { visibleApps = visibleApps.sort((a,b) => appSortInfo[b.id][activeSort] - appSortInfo[a.id][activeSort]); } else throw new Error("Unknown sort type "+activeSort); @@ -404,12 +403,16 @@ function checkDependencies(app, uploadOptions) { if (found) console.log(`Found dependency in installed app '${found.id}'`); else { - found = appJSON.find(app=>app.type==dependency); - if (!found) throw new Error(`Dependency of '${dependency}' listed, but nothing satisfies it!`); + var foundApps = appJSON.filter(app=>app.type==dependency); + if (!foundApps.length) throw new Error(`Dependency of '${dependency}' listed, but nothing satisfies it!`); + console.log(`Apps ${foundApps.map(f=>`'${f.id}'`).join("/")} implement '${dependency}'`); + found = foundApps[0]; // choose first app in list console.log(`Dependency not installed. Installing app id '${found.id}'`); promise.then(new Promise((resolve,reject)=>{ console.log(`Install dependency '${dependency}':'${found.id}'`); - return Comms.uploadApp(found); + return Comms.uploadApp(found).then(appJSON => { + if (appJSON) appsInstalled.push(appJSON); + }); })); } });