Skip to content

Commit

Permalink
Replace toaster style with PopupNotifications.
Browse files Browse the repository at this point in the history
Fixes #1563
  • Loading branch information
arantius committed Sep 27, 2012
1 parent 488ada4 commit d957130
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 129 deletions.
1 change: 0 additions & 1 deletion chrome.manifest
Expand Up @@ -12,7 +12,6 @@ content greasemonkey content/
skin greasemonkey classic/1.0 skin/

overlay chrome://browser/content/browser.xul chrome://greasemonkey/content/browser.xul
style chrome://global/content/alerts/alert.xul chrome://greasemonkey/skin/third-party/alert.css os=Darwin
style chrome://global/content/customizeToolbar.xul chrome://greasemonkey/skin/browser.css

resource greasemonkey modules/
Expand Down
4 changes: 2 additions & 2 deletions locale/en-US/gm-browser.properties
Expand Up @@ -4,8 +4,8 @@ menuitem.install=Install This User Script...
tooltip.disabled=Greasemonkey is disabled.
tooltip.enabled=Greasemonkey is enabled.
tooltip.loading=Loading...
script.installed=installed successfully
script.updated=updated successfully
script.installed=installed successfully.
script.updated=updated successfully.
install.msg=You are about to install the following Greasemonkey user script:
greeting.msg=This is a Greasemonkey user script. Click install to start using it.
greeting.btn=Install
Expand Down
4 changes: 4 additions & 0 deletions locale/en-US/greasemonkey.properties
Expand Up @@ -8,6 +8,10 @@ error.parsingScript=Could not parse script:
error.scriptCharset=Error reading script: All Greasemonkey scripts MUST be encoded with UTF-8.
error.serverReturned=Server returned
error.unknown=Unknown error.
notification.neveragain.label=Never show this again
notification.neveragain.accesskey=N
notification.ok.label=Ok
notification.ok.accesskey=O
return-not-in-func-deprecated=Warning: use of return outside of functions is deprecated and may cause failures in future versions of Greasemonkey.
warning.scripts-should-grant=Warning: All scripts should specify @grant metadata.
warning.scripts-should-grant.read-docs=Read documentation
Expand Down
55 changes: 30 additions & 25 deletions modules/GM_notification.js
@@ -1,33 +1,38 @@
Components.utils.import("resource://gre/modules/PopupNotifications.jsm");
Components.utils.import("resource://greasemonkey/prefmanager.js");
Components.utils.import('resource://greasemonkey/util.js');

var EXPORTED_SYMBOLS = ["GM_notification"];

var Cc = Components.classes;
var Ci = Components.interfaces;

// The first time this runs, we check if nsIAlertsService is installed and
// works. If it fails, we re-define notify to use a chrome window.
// We check to see if nsIAlertsService works because of the case where Growl
// is not installed. See also https://bugzilla.mozilla.org/show_bug.cgi?id=597165
function notify() {
try {
Cc["@mozilla.org/alerts-service;1"]
.getService(Ci.nsIAlertsService)
.showAlertNotification.apply(null, arguments);
} catch (e) {
notify = function() {
Cc['@mozilla.org/embedcomp/window-watcher;1']
.getService(Ci.nsIWindowWatcher)
.openWindow(null, 'chrome://global/content/alerts/alert.xul',
'_blank', 'chrome,titlebar=no,popup=yes', null)
.arguments = arguments;
};
notify.apply(null, arguments);
}
var gStringBundle = Components
.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/greasemonkey.properties");

function mute(aTopic) {
GM_prefRoot.setValue('notification.muted.' + aTopic, true);
}

function GM_notification(aMsg, aTitle) {
var title = aTitle ? "" + aTitle : "Greasemonkey";
var message = aMsg ? "" + aMsg : "";
notify(
"chrome://greasemonkey/skin/icon32.png",
title, message, false, "", null);
function GM_notification(
aMsg, aTopic) {
var muted = GM_prefRoot.getValue('notification.muted.' + aTopic, false);
if (muted) return;

var action = {
'label': gStringBundle.GetStringFromName('notification.ok.label'),
'accessKey': gStringBundle.GetStringFromName('notification.ok.accesskey'),
'callback': function() { },
}
var muteAction = {
'label': gStringBundle.GetStringFromName('notification.neveragain.label'),
'accessKey': gStringBundle.GetStringFromName('notification.neveragain.accesskey'),
'callback': function() { mute(aTopic); },
};
var win = GM_util.getBrowserWindow();
win.PopupNotifications.show(
win.gBrowser.selectedBrowser, 'greasemonkey-notification',
aMsg, null, action, [muteAction]);
};
3 changes: 2 additions & 1 deletion modules/remoteScript.js
Expand Up @@ -339,7 +339,8 @@ RemoteScript.prototype.install = function(aOldScript, aOnlyDependencies) {
// Let the user know we're all done.
GM_notification(
"'" + this.script.name + "' "
+ stringBundleBrowser.GetStringFromName(this.messageName));
+ stringBundleBrowser.GetStringFromName(this.messageName),
this.messageName);
}
};

Expand Down
4 changes: 3 additions & 1 deletion skin/browser.css
Expand Up @@ -20,6 +20,8 @@ toolbar[iconsize="small"] #greasemonkey-tbb {
-moz-binding: url('chrome://greasemonkey/content/bindings.xml#greasemonkey-tbb')/**/
}

.popup-notification-icon[popupid="greasemonkey-grants"] {
.popup-notification-icon[popupid="greasemonkey-grants"],
.popup-notification-icon[popupid="greasemonkey-notification"]
{
list-style-image: url("chrome://greasemonkey/skin/icon32.png");
}
99 changes: 0 additions & 99 deletions skin/third-party/alert.css

This file was deleted.

0 comments on commit d957130

Please sign in to comment.