diff --git a/src/views/app.js b/src/views/app.js index f37bf0c4c..426a97fad 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -673,18 +673,23 @@ angular.module('Application').controller('AppController', ['$scope', '$location' submit: function () { $scope.uninstall.busy = true; - Client.uninstallApp($scope.app.id, function (error) { - if (error && error.statusCode === 402) { // unpurchase failed - Client.error('Relogin to Cloudron App Store'); - } else if (error) { - Client.error(error); - } else { - $('#uninstallModal').modal('hide'); - Client.refreshAppCache($scope.app.id); // reflect the new app state immediately - $location.path('/apps'); - } + var NOOP = function (next) { return next(); }; + var stopAppTask = $scope.app.taskId ? Client.stopTask.bind(null, $scope.app.taskId) : NOOP; - $scope.uninstall.busy = false; + stopAppTask(function () { // ignore error + Client.uninstallApp($scope.app.id, function (error) { + if (error && error.statusCode === 402) { // unpurchase failed + Client.error('Relogin to Cloudron App Store'); + } else if (error) { + Client.error(error); + } else { + $('#uninstallModal').modal('hide'); + Client.refreshAppCache($scope.app.id); // reflect the new app state immediately + $location.path('/apps'); + } + + $scope.uninstall.busy = false; + }); }); } };