显示来自Firefox附加组件的超过1个桌面通知 [英] Showing more than 1 desktop notification from firefox add-ons

查看:128
本文介绍了显示来自Firefox附加组件的超过1个桌面通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示一些由我的Firefox附加组件触发的桌面通知,但似乎从我的测试中一次只能显示一个。
我不知道是否有任何官方的方式来做到这一点,因为我没有在通知文档中找到任何提及
https://developer.mozilla.org/zh-CN/Add-ons/SDK/High-Level_APIs/notifications ,但是我也会采取一种怪异的方式。

解决方案

您是否认为hacky?

  var timers = require(sdk / timers); 
var {notify} = require(sdk / notifications);

var i = 0;
var timerId = timers.setInterval(function(){
notify({
title:'+(++ i)+'00',
text)如果(i> 4)timers.clearInterval(timerId);
},5000);

它们不会堆叠(至少在OSX上),您可能想要检查默认值OS的通知时间是在将延迟设置为5秒之前,但是考虑到通知模块的限制,这是最好的。

我只是在我的插件中显示不同的通知,取决于它是一个还是几个;
$ b $ pre $ function showNotif(notifs){// notifs是一个数组
var len = notifs.length;
var notifOptions;
if(len> 1){
notifOptions = {
title:len +'notifications',
text:addonName
}
} else {
notifOptions = {
title:notifs [0] .title,
text:notifs [0] .text
}
}
notify(notifOptions);

然后,您需要添加一个 onClick notifOptions 根据是否为一个或多个做了不同的处理。


I'd like to show a few desktop notifications triggered from my firefox add-on but it seems like you can only show one at a time, from my testing. I am not sure if there is any official way to do this, since I did not find any mentions in the notifications docs https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/notifications, but I'll take a hacky way, too.

解决方案

Did you say hacky?

var timers = require("sdk/timers");
var {notify} = require("sdk/notifications");

var i=0;
var timerId = timers.setInterval(function() {
  notify({
    title: 'Famous tities for '+(++i)+'00',
    text: "That's famous titles, Mr Connery"
  });
  if (i>4) timers.clearInterval(timerId);
}, 5000);

They won't stack (at least on OSX), and you might want to check what the default notification time by OS is before setting the delay to 5 seconds, but it's the best I can think of given the limitations of the notification module.

Not that you care, but I just show different notifications in my add-on depending on whether it's one or several; I feel like it's less intrusive.

function showNotif(notifs) {//notifs is an array
  var len = notifs.length;
  var notifOptions;
  if(len>1) {
    notifOptions = {
      title: len + 'notifications',
      text: addonName
    }
  } else {
    notifOptions = {
      title: notifs[0].title,
      text: notifs[0].text
    }
  }
  notify(notifOptions);

Then you need to add an onClick to notifOptions that does something different depending on whether it's for one or many.

这篇关于显示来自Firefox附加组件的超过1个桌面通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆