Skip to content

Commit 3156f61

Browse files
committed
Add a prompt when removing an app if it's required by other apps
1 parent 851cbba commit 3156f61

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

js/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,31 @@ function uploadApp(app, options) {
851851

852852
/** Prompt user and then remove app from the device */
853853
function removeApp(app) {
854-
return showPrompt("Delete", `Are you sure you want to delete ${Utils.formatAppName(app)}?`)
854+
let appsUsing = [];
855+
device.appsInstalled.forEach(ia => {
856+
let installedApp =appJSON.find(a=>a.id==ia.id); // get the real app info with dependencies/etc
857+
if (installedApp && installedApp.dependencies)
858+
Object.keys(installedApp.dependencies).forEach(dep => {
859+
let depType = installedApp.dependencies[dep];
860+
switch (depType) {
861+
case "type":
862+
if (app.type==dep) appsUsing.push(installedApp);
863+
break;
864+
case "app":
865+
if (app.id==dep) appsUsing.push(installedApp);
866+
break;
867+
case "module":
868+
if (app.provides_modules && app.provides_modules.includes(dep))
869+
appsUsing.push(installedApp);
870+
break;
871+
case "widget":
872+
if (app.provides_widgets && app.provides_widgets.includes(dep))
873+
appsUsing.push(installedApp);
874+
break;
875+
}
876+
});
877+
});
878+
return showPrompt("Delete", `Are you sure you want to delete ${Utils.formatAppName(app)}?`+(appsUsing.length?`\n\nIt is currently used by ${appsUsing.length>1?"installed apps":"an installed app"}: ${appsUsing.map(a=>Utils.formatAppName(a)).join(", ")}`:""))
855879
.then(() => startOperation({ name: "Remove App" }, () => getInstalledApps()
856880
.then(()=> Comms.removeApp(device.appsInstalled.find(a => a.id === app.id))) // a = from appid.info, app = from apps.json
857881
.then(()=>{

0 commit comments

Comments
 (0)