I was testing notifications API of the sdk, and found that notification isn’t displayed the first time when I specify an icon to be used with it.
Here’s my sample index.js file:
var notifications = require("sdk/notifications"); var data = require("sdk/self").data; var myiconURL = "./success.png"; notifications.notify({ title: "Done!", text: "It worked.", iconURL: myiconURL });
The icon success.png is placed in data folder, and has dimensions 128x128.
No notification is displayed after I do jpm -b /usr/bin/firefox run. If I remove the iconURL line, it works.
What am I doing wrong here?
EDIT: Dimensions of the icon are irrelevant, since the same thing happens for a 32x32 icon.
Also, note that if I remove the icon specifier, it works as expected.
I hit Shift + F4 then set “Environment” to Browser from the menu toolbar then ran this code:
// Import SDK Stuff
var COMMONJS_URI = 'resource://gre/modules/commonjs';
var {require} = Cu.import(COMMONJS_URI + '/toolkit/require.js', {});
var notifications = require("sdk/notifications");
var data = require("sdk/self").data;
var myiconURL = "./success.png";
notifications.notify({
title: "Done!",
text: "It worked.",
iconURL: myiconURL
});
This API is flaky, especially on Linux’s and OS X. Try changing the text, add a Math.random() to the end and it will probably work. It’s real quirky, I don’t like it. I avoid it. The other draw back is it only last 4 seconds, if the user is at the computer or not, so its likely the user will miss the notification.
Native notifications are flaky on Linux even with the low-level API. libnotify support was dropped, they were implemented in-browser (UGLY!!!), then libnotify support was reintroduced, but it doesn’t always work. I think it is more reliable than the SDK API though, especially on other systems.
Not actually “native” though. This is essentially the solution that Firefox had for Linux (and some Macs) from about version 24 until 35, although with some extra features.
Thanks Amit. I haven’t actually used it yet in my addons, but I plan to soon. I haven’t turned it into a standalone module yet that i can drop in, but as soon as I do that I’ll let you know so including it is a no brainer
But if you want the non-dynamic/non-transient bar you can go ahead with the regular moz method -