Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect a first-run in Firefox a addon?

I would like to know the simplest way to detect a first-run in a Firefox addon. I prefer not to use the (SQLite) Storage API as this seems way overkill for this simple usecase.

I guess my question could also be: what is the simplest way to store a flag?

like image 655
Robert Massa Avatar asked Feb 12 '11 13:02

Robert Massa


People also ask

How do I view the code of an extension in Firefox?

Extension Metadata menu that appears when you right-click on the extension button. It also adds a context menu item on Firefox and Chrome extension links. The "View source" option opens a new tab with a simple viewer, with the following features: - Download-as-zip and download-as-crx at the upper-right corner.

Where are Firefox extensions stored?

Most add-on data is stored in a folder in the Firefox user profile. However, some information is stored in the profile folder also. It's possible that there is a problem with the file(s) that store the extensions registry. Type about:support in the address bar and press enter.


1 Answers

There you go: http://mike.kaply.com/2011/02/02/running-add-on-code-at-first-run-and-upgrade/

var firstrun = Services.prefs.getBoolPref("extensions.YOUREXT.firstrun");

var curVersion = "0.0.0";

if (firstrun) {
  Services.prefs.setBoolPref("extensions.YOUREXT.firstrun", false);
  Services.prefs.setCharPref("extensions.YOUREXT.installedVersion", curVersion);
  /* Code related to firstrun */
} else {
  try {
    var installedVersion = Services.prefs.getCharPref("extensions.YOUREXT.installedVersion");
    if (curVersion > installedVersion) {
      Services.prefs.setCharPref("extensions.YOUREXT.installedVersion", curVersion);
      /* Code related to upgrade */
    }
  } catch (ex) {
    /* Code related to a reinstall */
  }
}
like image 127
CAFxX Avatar answered Oct 15 '22 07:10

CAFxX