Changes

Jump to: navigation, search

PWCore

1,140 bytes added, 16:03, 24 April 2008
Registration
===Registration===
To register for PW notification notifications with the Observer service you must create a class with an 'observe' method which receives 3 parameters (subject, topic and data) as well as a 'register function ' method that contains the following code:
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "experimental-notify-plugin-call", false);
 
===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:
 
observe: function(subject, topic, data) {
if (topic == "experimental-notify-plugin-call" ) {
alert("Runtime is:" + data);
}
}
 
NOTE: This example 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.
 
===Clean Up===
 
To unregister with the Observer service when you no longer want to be listening to PW's notifications, you must include the 'unregister'
1
edit

Navigation menu