1
edit
Changes
PWCore
,→Usage
===Observing===
As discussed above, to specify what you want done when a notification arrives your class must have an 'observe' method, receiving 3 parameters (subject, topic and data) that gets called with each notification. The topic contains PW's notification topic - 'experimental-notify-plugin-call', the data is the runtime in milliseconds and the subject is always 'null' and should not be used. In the example below an if statement first checks to see that the arriving notification's topic is the on
Here is an example that shows the runtime in an alert box to the user:
}
- NOTE: This is just a simplified example and should never be used as PW sends hundreds of notifications each second and will cause your browser to crash with the excessive number of alert boxes. In the example above an if statement first checks to see that the arriving notification's topic is the correct one. This is useful in cases where your class is registered to receive notifications for more than one topic with the Observer service.
===Clean Up===
To unregister your class with the Observer service - when you no longer want to be listening to PW's notifications, you - your class must include the an 'unregister'method that contains the following code: var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); observerService.removeObserver(this, "experimental-notify-plugin-call");