zaraki
zaraki

Reputation: 73

Modifying the timeout of notifications in a firefox extension

I am using the notification function of the firefox SDK to create a firefox extensions. the problem is that after showing the notification it fades away too quickly , is there a way to modify the timeout of the notification ? this is the code i'm using :

notifications.notify({
                      title: "notification title",
                      text: " notification text ",
                      data: List[i] ,
                      onClick: function (data) {
                        tabs.open(data);

                      }
            });

Upvotes: 7

Views: 2664

Answers (2)

nmaier
nmaier

Reputation: 33162

There is no way to control the animation. @canuckistani is half-right: Both the SDK notifications and the HTML5 notifications use the same underlying service, the nsIAlertsService. This service does not allow you to control the duration.

Desktop Firefox does not use system-level services, except for the Metro implementation (yet to be officially released and does not support add-ons anyway IIRC). Instead they use the XUL alert service implementation, which is just some XUL with some Javascript and some additional CSS.And some code to open the window.

Depending on some pref, either a hardcoded 4000ms timeout via setTimeout will be used, or a 4s CSS animation.

While not convenient, in particular not in an SDK add-on where you do not get a chrome package to open your own XUL windows from, you could copy/paste implement your own fork of the XUL window with controls for the duration, or even override the Firefox default one. I cannot recall the name right now, but I know there is or was at least one add-on doing exactly that, overriding the built-in implementation and letting the user choose a custom timeout, among other things.

Upvotes: 1

therealjeffg
therealjeffg

Reputation: 5830

The high-level SDK api has not way to control how quickly the notifications go away:

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/notifications.html

This implementation in Firefox 22+ relies on the underlying HTML5 notifications api, and in Firefox and Safari specifically the implementations seem to hard-close the amount of time that passes before the notification is closed:

https://developer.mozilla.org/en-US/docs/WebAPI/Using_Web_Notifications#Creating_a_notification

Upvotes: 0

Related Questions