Bug 991766 - Webapp uninstallation on Mac through mozapps uninstall function. r=myk, r=smichaud

This commit is contained in:
Marco Castelluccio 2014-04-17 16:54:50 -04:00
parent 1629623676
commit ff252738ad
3 changed files with 58 additions and 10 deletions

View File

@ -2,10 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
const CC = Components.Constructor;
const Cu = Components.utils;
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu, Constructor: CC } = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
@ -119,8 +116,8 @@ this.WebappOSUtils = {
#elifdef XP_MACOSX
let uniqueName = this.getUniqueName(aApp);
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]
.createInstance(Ci.nsIMacWebAppUtils);
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"].
createInstance(Ci.nsIMacWebAppUtils);
try {
let path;
@ -265,8 +262,8 @@ this.WebappOSUtils = {
return false;
}
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]
.createInstance(Ci.nsIMacWebAppUtils);
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"].
createInstance(Ci.nsIMacWebAppUtils);
try {
mwaUtils.launchAppWithIdentifier(launchIdentifier);
@ -331,7 +328,25 @@ this.WebappOSUtils = {
return deferred.promise;
#elifdef XP_MACOSX
return Promise.reject("Uninstallation not yet implemented");
let [ , path ] = this.getLaunchTarget(aApp);
if (!path) {
return Promise.reject("App not found");
}
let deferred = Promise.defer();
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"].
createInstance(Ci.nsIMacWebAppUtils);
mwaUtils.trashApp(path, (aResult) => {
if (aResult == Cr.NS_OK) {
deferred.resolve(true);
} else {
deferred.resolve("Error moving the app to the Trash: " + aResult);
}
});
return deferred.promise;
#elifdef XP_UNIX
let exeFile = this.getLaunchTarget(aApp);
if (!exeFile) {

View File

@ -57,3 +57,26 @@ NS_IMETHODIMP nsMacWebAppUtils::LaunchAppWithIdentifier(const nsAString& bundleI
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsMacWebAppUtils::TrashApp(const nsAString& path, nsITrashAppCallback* aCallback) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if (NS_WARN_IF(!aCallback)) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsITrashAppCallback> callback = aCallback;
NSString* tempString = [NSString stringWithCharacters:reinterpret_cast<const unichar*>(((nsString)path).get())
length:path.Length()];
[[NSWorkspace sharedWorkspace] recycleURLs: [NSArray arrayWithObject:[NSURL fileURLWithPath:tempString]]
completionHandler: ^(NSDictionary *newURLs, NSError *error) {
nsresult rv = (error == nil) ? NS_OK : NS_ERROR_FAILURE;
callback->TrashAppFinished(rv);
}];
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

View File

@ -6,11 +6,17 @@
interface nsIMacWebAppUtils;
[scriptable, function, uuid(8c899c4f-58c1-4b74-9034-3bb64e484b68)]
interface nsITrashAppCallback : nsISupports
{
void trashAppFinished(in nsresult rv);
};
/**
* Allow MozApps API to locate and manipulate natively installed apps
*/
[scriptable, uuid(e9096367-ddd9-45e4-b762-49c0c18b7119)]
[scriptable, uuid(c69cf343-ea41-428b-b161-4655fd54d8e7)]
interface nsIMacWebAppUtils : nsISupports {
/**
* Find the path for an app with the given signature.
@ -22,4 +28,8 @@ interface nsIMacWebAppUtils : nsISupports {
*/
void launchAppWithIdentifier(in AString bundleIdentifier);
/**
* Move the app from the given directory to the Trash.
*/
void trashApp(in AString path, in nsITrashAppCallback callback);
};