Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Loading default addon prefs on startup (workaround for bug 564675)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvold committed Nov 18, 2011
1 parent fd07f2b commit 85511f1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions python-lib/cuddlefish/app-extension/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Contributor(s):
* Irakli Gozalishvili <gozala@mozilla.com> (Original Author)
* Matteo Ferretti <zer0@mozilla.com>
* Erik Vold <erikvvold@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
Expand Down Expand Up @@ -48,13 +49,49 @@ const resourceHandler = ioService.getProtocolHandler('resource')
.QueryInterface(Ci.nsIResProtocolHandler);
const XMLHttpRequest = CC('@mozilla.org/xmlextras/xmlhttprequest;1',
'nsIXMLHttpRequest');
const prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
QueryInterface(Ci.nsIPrefBranch2);
const mozIJSSubScriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);

const REASON = [ 'unknown', 'startup', 'shutdown', 'enable', 'disable',
'install', 'uninstall', 'upgrade', 'downgrade' ];

let loader = null;


// Initializes default preferences
function setDefaultPrefs() {
let branch = prefs.getDefaultBranch("");
let prefLoaderScope = {
pref: function(key, val) {
switch (typeof val) {
case "boolean":
branch.setBoolPref(key, val);
break;
case "number":
branch.setIntPref(key, val);
break;
case "string":
branch.setCharPref(key, val);
break;
}
}
};

let uri = ioService.newURI(
"defaults/preferences/prefs.js",
null,
ioService.newURI(__SCRIPT_URI_SPEC__, null, null));

// if there is a prefs.js file, then import the default prefs
if (uri.QueryInterface(Ci.nsIFileURL).file.exists()) {
// setup default prefs
mozIJSSubScriptLoader.loadSubScript(uri.spec, prefLoaderScope);
}
}

// Gets the topic that fit best as application startup event, in according with
// the current application (e.g. Firefox, Fennec, Thunderbird...)
function getAppStartupTopic() {
Expand Down Expand Up @@ -143,6 +180,11 @@ function uninstall(data, reason) {}

function startup(data, reason) {
let uri = (data.resourceURI || resourceURI(data.installPath)).spec;

// TODO: When bug 564675 is implemented this will no longer be needed
// Always set the default prefs, because they disappear on restart
setDefaultPrefs();

// TODO: Maybe we should perform read harness-options.json asynchronously,
// since we can't do anything until 'sessionstore-windows-restored' anyway.
let options = JSON.parse(readURI(uri + './harness-options.json'));
Expand Down

0 comments on commit 85511f1

Please sign in to comment.