views:

202

answers:

2

I noticed some Firefox extensions when installed will open up a page once you restart the browser, for example the StumbleUpon toolbar.

This is useful to show update notes and give the user some tutorial type information.

How do you go about opening a new page in a Firefox add-on the first time the user restarts the browser after install?

A: 

I have not worked directly with firefox extensions, but I would imagine something along the lines of storing a flag(boolean value) in persistent memory (however you store user preferences). When the browser starts the first time after the install, the flag would not be set, so you display the help page and set the flag. Next time firefox restarts, the flag will already have been set, so you don't open the help page.

If you wanted it to show a page every time the extension was updated, then store the version instead of a boolean, and on each startup check if the current version is greater than that of the stored one.

spbogie
+2  A: 

Though there might be a better way, I'm not aware of it... You can use the preferences system to track whether it's a first run/update

Check if the preference exists, if not, open the page, create the pref with current extension version number. If the preference exists, check it against the current extension version number, if they are different, assume it's an update and open the page. (assuming you want the page opened every time it's updated as well)

var prefs = Components.classes["@mozilla.org/preferences-service;1"]
   .getService(Components.interfaces.nsIPrefService);
prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);

if ((prefs.getPrefType("extensions.yourextensionhere.yourprerference") == PREF_INVALID)
    || (prefs.getCharPref("extensions.yourextensionhere.yourprerference") != this.version)) {
    //open page and...
    prefs.setCharPref("extensions.yourextensionhere.yourprerference",this.version)
 }

EDIT.. version check used == instead of != as it should have

Jonathan Fingland