Skip to content
This repository was archived by the owner on Nov 27, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down