Skip to content

Commit f5dfee3

Browse files
authored
Move name into a function, avoiding reusing logic, don't show both id and name if they are the same
1 parent 0f76f8e commit f5dfee3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

js/index.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -841,30 +841,38 @@ function uploadApp(app, options) {
841841
if (appJSON) {
842842
device.appsInstalled.push(appJSON);
843843
}
844-
showToast(app.name +" ("+app.id+") "+ ' Uploaded!', 'success');
844+
showToast(formatAppName(app)+ ' Uploaded!', 'success');
845845
}).catch(err => {
846-
showToast("Upload of" +app.name +" ("+app.id+") "+" failed", + err, 'error');
846+
showToast("Upload of" +formatAppName(app)+" failed", + err, 'error');
847847
});
848848
}));
849849
}
850-
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+
}
851859
/** Prompt user and then remove app from the device */
852860
function removeApp(app) {
853-
return showPrompt("Delete", "Are you sure you want to delete "+app.name +" ("+app.id+")?")
861+
return showPrompt("Delete", "Are you sure you want to delete "+formatAppName(app)+"?")
854862
.then(() => startOperation({ name: "Remove App" }, () => getInstalledApps()
855863
.then(()=> Comms.removeApp(device.appsInstalled.find(a => a.id === app.id))) // a = from appid.info, app = from apps.json
856864
.then(()=>{
857865
device.appsInstalled = device.appsInstalled.filter(a=>a.id!=app.id);
858-
showToast(app.name +" ("+app.id+")"+" removed successfully","success");
866+
showToast(formatAppName(app)+" removed successfully","success");
859867
}, err=>{
860-
showToast("Removal of "+app.name +" ("+app.id+")"+" failed, "+err,"error");
868+
showToast("Removal of "+formatAppName(app)+" failed, "+err,"error");
861869
})));
862870
}
863871

864872
/** Show window for a new app and finally upload it */
865873
function customApp(app) {
866874
return handleCustomApp(app).then(() => {
867-
showToast(app.name+" Uploaded!", "success");
875+
showToast(formatAppName()+" Uploaded!", "success");
868876
refreshMyApps();
869877
refreshLibrary();
870878
}).catch(err => {
@@ -952,13 +960,13 @@ function updateApp(app, options) {
952960
remove.data = AppInfo.makeDataString(data)
953961
return Comms.removeApp(remove, {containsFileList:true, noReset:options.noReset, noFinish:options.noFinish});
954962
}).then(()=>{
955-
showToast("Updating "+app.name +" ("+app.id+")...");
963+
showToast("Updating "+formatAppName(app)+"...");
956964
device.appsInstalled = device.appsInstalled.filter(a=>a.id!=app.id);
957965
return checkDependencies(app,{checkForClashes:false});
958966
}).then(()=>Comms.uploadApp(app,{device:device,language:LANGUAGE,noReset:options.noReset, noFinish:options.noFinish})
959967
).then((appJSON) => {
960968
if (appJSON) device.appsInstalled.push(appJSON);
961-
showToast(app.name +" ("+app.id+")"+" Updated!", "success");
969+
showToast(formatAppName(app)+" Updated!", "success");
962970
}));
963971
}
964972

0 commit comments

Comments
 (0)