Improve error handling, fix delete regression

pull/5/head
Gordon Williams 2019-11-06 15:53:38 +00:00
parent 6671bc098f
commit 2f9c24d433
2 changed files with 15 additions and 8 deletions

View File

@ -20,13 +20,15 @@ uploadApp : app => {
Promise.all(app.storage.map(storageFile => httpGet("apps/"+storageFile.file) Promise.all(app.storage.map(storageFile => httpGet("apps/"+storageFile.file)
// map each file to a command to load into storage // 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(contents=>`\x10require('Storage').write(${toJS(storageFile.name)},${storageFile.evaluate ? contents.trim() : toJS(contents)});`)))
.then(function(fileContents) { .then((fileContents) => {
fileContents = fileContents.join("\n")+"\n"; fileContents = fileContents.join("\n")+"\n";
console.log("uploadApp",fileContents); console.log("uploadApp",fileContents);
// reset to ensure we have enough memory to upload what we need to // reset to ensure we have enough memory to upload what we need to
Puck.write("\x03reset();\n", function() { Puck.write("\x03reset();\n", (result) => {
setTimeout(function() { // wait for reset if (result===null) return reject("");
Puck.write(fileContents,function() { setTimeout(() => { // wait for reset
Puck.write(fileContents,(result) => {
if (result===null) return reject("");
resolve(); resolve();
}); });
},500); },500);
@ -36,8 +38,10 @@ uploadApp : app => {
}, },
getInstalledApps : () => { getInstalledApps : () => {
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
Puck.write("\x03",() => { Puck.write("\x03",(result) => {
Puck.eval('require("Storage").list().filter(f=>f[0]=="+").map(f=>f.substr(1))', appList => { 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); console.log("getInstalledApps", appList);
resolve(appList); resolve(appList);
}); });
@ -50,7 +54,8 @@ removeApp : app => { // expects an app structure
}).join(""); }).join("");
console.log("removeApp", cmds); console.log("removeApp", cmds);
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
Puck.write("\x03"+cmds,() => { Puck.write("\x03"+cmds,(result) => {
if (result===null) return reject("");
resolve(); resolve();
}); });
}); });

View File

@ -117,7 +117,7 @@ refreshLibrary();
// =========================================== My Apps // =========================================== My Apps
function removeApp(app) { function removeApp(app) {
return showPrompt("Delete","Really remove app '"+appid+"'?").then(() => { return showPrompt("Delete","Really remove '"+app.name+"'?").then(() => {
Comms.removeApp(app).then(()=>{ Comms.removeApp(app).then(()=>{
appsInstalled = appsInstalled.filter(id=>id!=app.id); appsInstalled = appsInstalled.filter(id=>id!=app.id);
showToast(app.name+" removed successfully","success"); showToast(app.name+" removed successfully","success");
@ -188,6 +188,8 @@ function getInstalledApps() {
appsInstalled = appIDs; appsInstalled = appIDs;
refreshMyApps(); refreshMyApps();
refreshLibrary(); refreshLibrary();
}).catch(err => {
showToast("Getting app list failed, "+err,"error");
}); });
} }