How to determine the first launch in Firefox addon?

I would like to find out the easiest way to detect the first launch in the Firefox addon. I prefer not to use the (SQLite) storage API, as this seems redundant for this simple utility.

I think my question might also be: what is the easiest way to save the flag?

+7
source share
2 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 */ } } 
+5
source

Perhaps the best solution would be:

 /** * Check if this is the first run of the addon */ function checkFirstRun(){ if(ss.storage.firstRun == undefined){ ss.storage.firstRun = false; return true; } else{ return false; } } 
0
source

All Articles