diff --git a/lib/profile.js b/lib/profile.js index 5f36386..042a223 100644 --- a/lib/profile.js +++ b/lib/profile.js @@ -2,15 +2,41 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; - +var fs = require("fs"); var FirefoxProfile = require("firefox-profile"); var FirefoxProfileFinder = require("firefox-profile/lib/profile_finder"); var getPrefs = require("./preferences").getPrefs; var when = require("when"); var console = require("./utils").console; +// revised from firefox_profile, b/c node fs module required encoding +function readExistingUserjs(profile) { + var self = profile; + var regExp = /user_pref\('(.*)',\s(.*)\)/; + var contentLines = fs.readFileSync(self.userPrefs, {encoding: "utf8"}). + split("\n"); + contentLines.forEach(function(line) { + var found = line.match(regExp); + if (found && found[1]) { + self.defaultPreferences[found[1]] = found[2]; + } + }); +} + +function setAppPrefs(profile) { + // Set default preferences + var prefs = getPrefs("firefox"); + Object.keys(prefs).forEach(function(pref) { + profile.setPreference(pref, prefs[pref]); + }); + profile.updatePreferences(); +} + function copyProfile(profile) { - return when.resolve(new FirefoxProfile(profile)); + profile = new FirefoxProfile(profile); + readExistingUserjs(profile); + setAppPrefs(profile); + return when.resolve(profile); } exports.copyProfile = copyProfile; @@ -24,12 +50,7 @@ exports.reuseProfile = reuseProfile; function makeProfile() { var profile = new FirefoxProfile(); - // Set default preferences - var prefs = getPrefs("firefox"); - Object.keys(prefs).forEach(function(pref) { - profile.setPreference(pref, prefs[pref]); - }); - profile.updatePreferences(); + setAppPrefs(profile); return when.resolve(profile); }