首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >火狐扩展:关于PopupNotifications.jsm在

火狐扩展:关于PopupNotifications.jsm在
EN

Stack Overflow用户
提问于 2015-08-18 06:38:49
回答 1查看 144关注 0票数 2

我已经做了一个小的(引导的)扩展来通知我网站上的一些变化。除了显示通知之外,一切都已完成。

据我所知,HTML5通知是无法从扩展中访问的。

然后我找到了另一种使用PopupNotifications.jsm的方法。但是常用的使用示例不起作用,因为"gBrowser没有定义“。此变量用于创建通知。

我不想使用任何外部扩展来处理通知(我至少找到了两个)。我需要一个独立的分机。

还有另一种方法--使用sdk。但我还没有准备好仅仅用于通知。我想尽可能简单地做我的扩展。

我在这里找到的例子:notifications

好的,现在的问题是:向我的扩展添加通知的最佳方法是什么?继续使用PopupNotifications.jsm吗?或者尝试使用createInstanse of nsIDOMDesktopNotification (但我不知道合适的类名,比如@mozilla.org/.)。你能给我什么建议?

EN

回答 1

Stack Overflow用户

发布于 2016-01-04 08:33:13

您可以使用警报服务,也可以从chrome://global/content/alerts/alert.xul手动创建它。

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32065234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档