我已经做了一个小的(引导的)扩展来通知我网站上的一些变化。除了显示通知之外,一切都已完成。
据我所知,HTML5通知是无法从扩展中访问的。
然后我找到了另一种使用PopupNotifications.jsm的方法。但是常用的使用示例不起作用,因为"gBrowser没有定义“。此变量用于创建通知。
我不想使用任何外部扩展来处理通知(我至少找到了两个)。我需要一个独立的分机。
还有另一种方法--使用sdk。但我还没有准备好仅仅用于通知。我想尽可能简单地做我的扩展。
我在这里找到的例子:notifications
好的,现在的问题是:向我的扩展添加通知的最佳方法是什么?继续使用PopupNotifications.jsm吗?或者尝试使用createInstanse of nsIDOMDesktopNotification (但我不知道合适的类名,比如@mozilla.org/.)。你能给我什么建议?
发布于 2016-01-04 08:33:13
您可以使用警报服务,也可以从chrome://global/content/alerts/alert.xul手动创建它。
function notify(title, msg, url, img, name, isClickable) {
var listener = {
observe: function(subject, topic, data) { // jshint ignore:line
// if (topic === 'alertclickcallback') {
// }
// if (topic === 'alertfinished') {
// }
},
};
try {
var alertWin = Cc['@mozilla.org/alerts-service;1'].getService(Ci.nsIAlertsService);
alertWin.showAlertNotification(img, title, msg, isClickable, url, listener, name);
}
catch (e) {
// fix for when alerts-service is not available (e.g. SUSE)
var ALERT_XUL = 'chrome://global/content/alerts/alert.xul';
var FF_WIN_OPTS = 'chrome,dialog=yes,titlebar=no,popup=yes';
// arguments[0] --> the image src url
// arguments[1] --> the alert title
// arguments[2] --> the alert text
// arguments[3] --> is the text clickable?
// arguments[4] --> the alert cookie to be passed back to the listener
// arguments[5] --> the alert origin reported by the look and feel
// 0: bottom right.
// 2: bottom left
// 4: top right
// 6: top left
// arguments[6] --> bidi
// arguments[7] --> lang
// arguments[8] --> replaced alert window (nsIDOMWindow)
// // i. e. previous alert
// arguments[9] --> an optional callback listener (nsIObserver)
// arguments[10] -> the nsIURI.hostPort of the origin, optional
var winArgs = [img, title, msg, isClickable, url, 2, null, null, null, listener, name];
// aParentwindow, aUrl, aWindowName, aWindowFeatures, aWindowArguments (nsISupports)
var win = Services.ww.openWindow(null, ALERT_XUL, '_blank', FF_WIN_OPTS, null);
win.arguments = winArgs;
}
}https://stackoverflow.com/questions/32065234
复制相似问题