Skip to content Skip to sidebar Skip to footer

Showing More Than 1 Desktop Notification From Firefox Add-ons

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 offi

Solution 1:

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 arrayvarlen = 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.

Post a Comment for "Showing More Than 1 Desktop Notification From Firefox Add-ons"