Skip to content

Commit bc1eedb

Browse files
committed
Changes for #69
1 parent 9cc7224 commit bc1eedb

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

js/comms.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const Comms = {
246246
} */
247247
uploadApp : (app,options) => {
248248
options = options||{};
249-
Progress.show({title:`Uploading ${app.name}`,sticky:true});
249+
Progress.show({title:`Uploading ${Utils.formatAppName(app)}`,sticky:true});
250250
return AppInfo.getFiles(app, {
251251
fileGetter : httpGet,
252252
settings : SETTINGS,
@@ -317,7 +317,7 @@ const Comms = {
317317

318318
// Start the upload
319319
function doUpload() {
320-
Comms.showMessage(`Uploading\n${app.id}...`).
320+
Comms.showMessage(`Installing\n${app.id}...`).
321321
then(() => Comms.write("\x10"+Comms.getProgressCmd()+"\n")).
322322
then(() => {
323323
doUploadFiles();
@@ -496,7 +496,7 @@ const Comms = {
496496
if options.noFinish is true, showUploadFinished isn't called (displaying the reboot message) */
497497
removeApp : (app, options) => {
498498
options = options||{};
499-
Progress.show({title:`Removing ${app.id}`,sticky:true});
499+
Progress.show({title:`Removing ${Utils.formatAppName(app)}`,sticky:true});
500500
/* App Info now doesn't contain .files, so to erase, we need to
501501
read the info file ourselves. */
502502
return (options.noReset ? Promise.resolve() : Comms.reset()).

js/index.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -841,38 +841,30 @@ function uploadApp(app, options) {
841841
if (appJSON) {
842842
device.appsInstalled.push(appJSON);
843843
}
844-
showToast(formatAppName(app)+ ' Uploaded!', 'success');
844+
showToast(`${Utils.formatAppName(app)} Uploaded!`, 'success');
845845
}).catch(err => {
846-
showToast("Upload of" +formatAppName(app)+" failed", + err, 'error');
846+
showToast(`Upload of ${Utils.formatAppName(app)} failed`, + err, 'error');
847847
});
848848
}));
849849
}
850-
/** Format app name into a string like App Name (AppID)*/
851-
function formatAppName(app){
852-
//check if id is the same as the name, in which case we can just return the name...
853-
if(app.name.trim().toLowerCase()===app.id.trim().toLowerCase()){
854-
return app.name;
855-
}else{
856-
return formatAppName(app);
857-
}
858-
}
850+
859851
/** Prompt user and then remove app from the device */
860852
function removeApp(app) {
861-
return showPrompt("Delete", "Are you sure you want to delete "+formatAppName(app)+"?")
853+
return showPrompt("Delete", `Are you sure you want to delete ${Utils.formatAppName(app)}?`)
862854
.then(() => startOperation({ name: "Remove App" }, () => getInstalledApps()
863855
.then(()=> Comms.removeApp(device.appsInstalled.find(a => a.id === app.id))) // a = from appid.info, app = from apps.json
864856
.then(()=>{
865857
device.appsInstalled = device.appsInstalled.filter(a=>a.id!=app.id);
866-
showToast(formatAppName(app)+" removed successfully","success");
858+
showToast(`${Utils.formatAppName(app)} removed successfully`,"success");
867859
}, err=>{
868-
showToast("Removal of "+formatAppName(app)+" failed, "+err,"error");
860+
showToast(`Removal of ${Utils.formatAppName(app)} failed, ${err}`,"error");
869861
})));
870862
}
871863

872864
/** Show window for a new app and finally upload it */
873865
function customApp(app) {
874866
return handleCustomApp(app).then(() => {
875-
showToast(formatAppName()+" Uploaded!", "success");
867+
showToast(`${Utils.formatAppName()} Uploaded!`, "success");
876868
refreshMyApps();
877869
refreshLibrary();
878870
}).catch(err => {
@@ -960,13 +952,13 @@ function updateApp(app, options) {
960952
remove.data = AppInfo.makeDataString(data)
961953
return Comms.removeApp(remove, {containsFileList:true, noReset:options.noReset, noFinish:options.noFinish});
962954
}).then(()=>{
963-
showToast("Updating "+formatAppName(app)+"...");
955+
showToast(`Updating ${Utils.formatAppName(app)}...`);
964956
device.appsInstalled = device.appsInstalled.filter(a=>a.id!=app.id);
965957
return checkDependencies(app,{checkForClashes:false});
966958
}).then(()=>Comms.uploadApp(app,{device:device,language:LANGUAGE,noReset:options.noReset, noFinish:options.noFinish})
967959
).then((appJSON) => {
968960
if (appJSON) device.appsInstalled.push(appJSON);
969-
showToast(formatAppName(app)+" Updated!", "success");
961+
showToast(`${Utils.formatAppName(app)} Updated!`, "success");
970962
}));
971963
}
972964

js/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ function parseRJSON(str) {
515515
return json;
516516
}
517517

518+
/** Format app name into a string like "App Name (AppID)" */
519+
function formatAppName(app){
520+
if (!app.name) return app.id; // just in case we don't have name (eg when removing)
521+
// check if id is the same as the name, in which case we can just return the name...
522+
if(app.name.trim().toLowerCase()===app.id.trim().toLowerCase()){
523+
return app.name;
524+
}else{
525+
return `${app.name} (${app.id})`;
526+
}
527+
}
528+
518529
let Utils = {
519530
Const : Const,
520531
DEVICEINFO : DEVICEINFO,
@@ -534,7 +545,8 @@ let Utils = {
534545
versionLess : versionLess,
535546
debounce : debounce,
536547
atobSafe : atobSafe, // version of 'window.atob' that doesn't fail on 'not correctly encoded' strings
537-
parseRJSON : parseRJSON // parse relaxed JSON which Espruino's writeJSON uses for settings/etc (returns undefined on failure)
548+
parseRJSON : parseRJSON, // parse relaxed JSON which Espruino's writeJSON uses for settings/etc (returns undefined on failure)
549+
formatAppName : formatAppName // Format app name into a string like "App Name (AppID)"
538550
};
539551

540552
if ("undefined"!=typeof module)

0 commit comments

Comments
 (0)