如何在Firefox中检测首次运行的插件?

时间:2011-02-12 13:01:32

标签: firefox-addon

我想知道在Firefox插件中检测首次运行的最简单方法。我不想使用(SQLite)存储API,因为这对于这个简单的用例来说似乎有些过分。

我想我的问题也可能是:存储标志的最简单方法是什么?

2 个答案:

答案 0 :(得分:5)

你去了: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 */
  }
}

答案 1 :(得分:0)

也许更好的解决方案是:

/**
* 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;
    }
}