2011-02-12 5 views
7

Firefox Addon에서 처음 실행되는 것을 감지하는 가장 간단한 방법을 알고 싶습니다. 나는이 단순한 유스 케이스에 대해 과장된 것처럼 보이기 때문에 (SQLite) 스토리지 API를 사용하지 않기를 바란다.Firefox에서 첫 번째 실행을 애드온으로 어떻게 감지합니까?

제 질문은 다음과 같을 수도 있습니다. 플래그를 저장하는 가장 간단한 방법은 무엇입니까? 이

답변

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 */ 
    } 
} 
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; 
    } 
} 
관련 문제