From 2f9c24d433c07c5593b83c30083d707d3b3bc196 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 6 Nov 2019 15:53:38 +0000 Subject: [PATCH] Improve error handling, fix delete regression --- comms.js | 19 ++++++++++++------- index.js | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/comms.js b/comms.js index a5f0569d8..7be1ca4bd 100644 --- a/comms.js +++ b/comms.js @@ -20,13 +20,15 @@ uploadApp : app => { Promise.all(app.storage.map(storageFile => httpGet("apps/"+storageFile.file) // map each file to a command to load into storage .then(contents=>`\x10require('Storage').write(${toJS(storageFile.name)},${storageFile.evaluate ? contents.trim() : toJS(contents)});`))) - .then(function(fileContents) { + .then((fileContents) => { fileContents = fileContents.join("\n")+"\n"; console.log("uploadApp",fileContents); // reset to ensure we have enough memory to upload what we need to - Puck.write("\x03reset();\n", function() { - setTimeout(function() { // wait for reset - Puck.write(fileContents,function() { + Puck.write("\x03reset();\n", (result) => { + if (result===null) return reject(""); + setTimeout(() => { // wait for reset + Puck.write(fileContents,(result) => { + if (result===null) return reject(""); resolve(); }); },500); @@ -36,8 +38,10 @@ uploadApp : app => { }, getInstalledApps : () => { return new Promise((resolve,reject) => { - Puck.write("\x03",() => { - Puck.eval('require("Storage").list().filter(f=>f[0]=="+").map(f=>f.substr(1))', appList => { + Puck.write("\x03",(result) => { + if (result===null) return reject(""); + Puck.eval('require("Storage").list().filter(f=>f[0]=="+").map(f=>f.substr(1))', (appList,err) => { + if (appList===null) return reject(err || ""); console.log("getInstalledApps", appList); resolve(appList); }); @@ -50,7 +54,8 @@ removeApp : app => { // expects an app structure }).join(""); console.log("removeApp", cmds); return new Promise((resolve,reject) => { - Puck.write("\x03"+cmds,() => { + Puck.write("\x03"+cmds,(result) => { + if (result===null) return reject(""); resolve(); }); }); diff --git a/index.js b/index.js index d4c5ed37a..6e8f74084 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,7 @@ refreshLibrary(); // =========================================== My Apps function removeApp(app) { - return showPrompt("Delete","Really remove app '"+appid+"'?").then(() => { + return showPrompt("Delete","Really remove '"+app.name+"'?").then(() => { Comms.removeApp(app).then(()=>{ appsInstalled = appsInstalled.filter(id=>id!=app.id); showToast(app.name+" removed successfully","success"); @@ -188,6 +188,8 @@ function getInstalledApps() { appsInstalled = appIDs; refreshMyApps(); refreshLibrary(); + }).catch(err => { + showToast("Getting app list failed, "+err,"error"); }); }