-
-
Save kmaglione/63f39616238430268ba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- bootstrap.js.orig 2013-02-07 15:31:47.845497943 -0800 | |
+++ bootstrap.js 2013-02-11 12:42:52.324114233 -0800 | |
@@ -70,6 +70,11 @@ | |
if (engine == null) | |
return; | |
+ // Core code unfortunately depends on this being a | |
+ // nsIPrefLocalizedString | |
+ setPref(PREF_ENGINENAME, 'data:text/plain,' + encodeURIComponent( | |
+ PREF_ENGINENAME + ' = ' + engineName.replace(/ /g, "\\u0020"))); | |
+ | |
// Move it to the desired position | |
Services.search.moveEngine(engine, SEARCH_POSITION); | |
@@ -82,9 +87,33 @@ | |
} | |
// Customize the default prefs | |
+let changedPrefs = {}; | |
+let originalPrefs = {}; | |
function setPref(pref, value) { | |
- let branch = Services.prefs.getBranch(""); | |
+ let branch = Services.prefs.getDefaultBranch(""); | |
+ let userBranch = Services.prefs.getBranch(""); | |
+ | |
+ if (branch.getPrefType(pref) == branch.PREF_STRING) | |
+ originalPrefs[pref] = branch.getCharPref(pref); | |
+ changedPrefs[pref] = value; | |
+ | |
branch.setCharPref(pref, value); | |
+ if (justInstalled) | |
+ userBranch.clearUserPref(pref); | |
+ else if (userBranch.prefHasUserValue(pref) | |
+ && userBranch.getPrefType(pref) == branch.PREF_STRING | |
+ && userBranch.getCharPref(pref) == value) | |
+ // Clear the user value if it's the same, so prefHasUserValue | |
+ // returns false. | |
+ userBranch.clearUserPref(pref); | |
+} | |
+function restorePrefs() { | |
+ let branch = Services.prefs.getDefaultBranch(""); | |
+ for (let [pref, value] in Iterator(originalPrefs)) { | |
+ if (branch.getPrefType(pref) == branch.PREF_STRING | |
+ && branch.getCharPref(pref) == changedPrefs[pref]) | |
+ branch.setCharPref(pref, value); | |
+ } | |
} | |
// Open a new tab for the landing page and select it | |
@@ -120,7 +149,7 @@ | |
else { | |
let {BrowserUI} = window; | |
let tab = BrowserUI.newTab(LANDING_PAGE); | |
- unload(function() BrowserUI.closeTab(tab)); | |
+ unload(function() BrowserUI.closeTab(tab), window); | |
} | |
// Only show the landing page once | |
@@ -141,11 +170,10 @@ | |
addSearchEngine(); | |
// Change some prefs to custom search on install | |
- if (justInstalled) { | |
- setPref(PREF_KEYWORD, SEARCH_KEYWORD_URL); | |
- setPref(PREF_HOME, SEARCH_HOME_URL); | |
- setPref(PREF_HOME_RESET, SEARCH_HOME_URL); | |
- } | |
+ unload(restorePrefs); | |
+ setPref(PREF_KEYWORD, SEARCH_KEYWORD_URL); | |
+ setPref(PREF_HOME, SEARCH_HOME_URL); | |
+ setPref(PREF_HOME_RESET, SEARCH_HOME_URL); | |
// Open the landing page | |
watchWindows(showLandingPage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment