1
0
Fork 0

Dependency handling fix - now choose the dependency highest up the JSON list (before sorting, not after!)

master
Gordon Williams 2020-06-05 11:22:43 +01:00
parent 77de51dac4
commit 9f41180664
2 changed files with 19 additions and 9 deletions

View File

@ -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("<COMMS> reset");
Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`,function rstHandler(result) {
console.log("<COMMS> reset: got "+JSON.stringify(result));
if (result===null) return reject("Connection failed");
if (result=="" && (tries-- > 0)) {
console.log(`<COMMS> reset: no response. waiting ${tries}...`);
Puck.write("\x03",rstHandler);
} else setTimeout(resolve,250);
} else {
console.log(`<COMMS> reset: complete.`);
setTimeout(resolve,250);
}
});
}),
uploadApp : (app,skipReset) => { // expects an apps.json structure (i.e. with `storage`)

View File

@ -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);
});
}));
}
});