Skip to content

Commit

Permalink
Bug 780530 - Notification after webapp uninstallation. r=mhommey
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Castelluccio committed Aug 18, 2012
1 parent 50d2075 commit c5ea4dc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions browser/locales/en-US/chrome/browser/browser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ webapps.install.accesskey = I
#LOCALIZATION NOTE (webapps.requestInstall) %1$S is the web app name, %2$S is the site from which the web app is installed
webapps.requestInstall = Do you want to install "%1$S" from this site (%2$S)?
webapps.install.success = Application Installed
# LOCALIZATION NOTE (webapps.uninstall.notification): %S will be replaced with the name of the uninstalled web app
webapps.uninstall.notification = %S has been uninstalled from your computer.

# Telemetry opt-out prompt for Aurora and Nightly
# LOCALIZATION NOTE (telemetryOptOutPrompt): %1$S and %3$S will be replaced by
Expand Down
3 changes: 3 additions & 0 deletions toolkit/webapps/WebappsInstaller.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,13 @@ LinuxNativeApp.prototype = {
let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
.getService(Ci.nsIINIParserFactory);

let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");

// ${InstallDir}/webapp.ini
let writer = factory.createINIParser(this.webappINI).QueryInterface(Ci.nsIINIParserWriter);
writer.setString("Webapp", "Name", this.appName);
writer.setString("Webapp", "Profile", this.uniqueName);
writer.setString("Webapp", "UninstallMsg", browserBundle.formatStringFromName("webapps.uninstall.notification", [this.appName], 1));
writer.setString("WebappRT", "InstallDir", this.runtimeFolder.path);
writer.writeFile();

Expand Down
46 changes: 44 additions & 2 deletions webapprt/gtk2/webapprt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Linux headers
#include <fcntl.h>
#include <unistd.h>
#include <dlfcn.h>

// Mozilla headers
#include "nsIFile.h"
Expand Down Expand Up @@ -224,7 +225,7 @@ void CopyAndRelaunch(const char* firefoxDir, const char* curExePath)
ErrorDialog("Couldn't execute the new webapprt-stub executable");
}

void RemoveApplication(const char* curExeDir, const char* profile) {
void RemoveApplication(nsINIParser& parser, const char* curExeDir, const char* profile) {
if (!isProfileOverridden) {
// Remove the desktop entry file.
char desktopEntryFilePath[MAXPATHLEN];
Expand Down Expand Up @@ -257,6 +258,47 @@ void RemoveApplication(const char* curExeDir, const char* profile) {
char iconPath[MAXPATHLEN];
snprintf(iconPath, MAXPATHLEN, "%s/icon.png", curExeDir);
unlink(iconPath);

char appName[MAXPATHLEN];
if (NS_FAILED(parser.GetString("Webapp", "Name", appName, MAXPATHLEN))) {
strcpy(appName, profile);
}

char uninstallMsg[MAXPATHLEN];
if (NS_SUCCEEDED(parser.GetString("Webapp", "UninstallMsg", uninstallMsg, MAXPATHLEN))) {
/**
* The only difference between libnotify.so.4 and libnotify.so.1 for these symbols
* is that notify_notification_new takes three arguments in libnotify.so.4 and
* four in libnotify.so.1.
* Passing the fourth argument as NULL is binary compatible.
*/
typedef void (*notify_init_t)(char*);
typedef void* (*notify_notification_new_t)(char*, char*, char*, char*);
typedef void (*notify_notification_show_t)(void*, char*);

void *handle = dlopen("libnotify.so.4", RTLD_LAZY);
if (!handle) {
handle = dlopen("libnotify.so.1", RTLD_LAZY);
if (!handle)
return;
}

notify_init_t nn_init = (notify_init_t)dlsym(handle, "notify_init");
notify_notification_new_t nn_new = (notify_notification_new_t)dlsym(handle, "notify_notification_new");
notify_notification_show_t nn_show = (notify_notification_show_t)dlsym(handle, "notify_notification_show");
if (!nn_init || !nn_new || !nn_show) {
dlclose(handle);
return;
}

nn_init(appName);

void* n = nn_new(uninstallMsg, NULL, "dialog-information", NULL);

nn_show(n, NULL);

dlclose(handle);
}
}

int main(int argc, char *argv[])
Expand Down Expand Up @@ -319,7 +361,7 @@ int main(int argc, char *argv[])
}

if (removeApp) {
RemoveApplication(curExeDir, profile);
RemoveApplication(parser, curExeDir, profile);
return 0;
}

Expand Down

0 comments on commit c5ea4dc

Please sign in to comment.