commit 8d0dc359b428e16468c5cd0363ab7317cd5331f8
parent 7f81e62bc893a3032aa07f37db7099497b963264
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 1 Apr 2018 13:44:10 -0400
Move prefs.js parsing to Zotero.Profile.readPrefsFromFile(prefsFile)
Diffstat:
2 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js
@@ -255,35 +255,7 @@ Zotero.DataDirectory = {
// Read in prefs
let prefsFile = OS.Path.join(profileDir, "prefs.js");
if (yield OS.File.exists(prefsFile)) {
- // build sandbox
- var sandbox = new Components.utils.Sandbox("http://www.example.com/");
- Components.utils.evalInSandbox(
- "var prefs = {};"+
- "function user_pref(key, val) {"+
- "prefs[key] = val;"+
- "}"
- , sandbox);
-
- (yield Zotero.File.getContentsAsync(prefsFile))
- .split(/\n/)
- .filter((line) => {
- // Strip comments
- return !line.startsWith('#')
- // Only process lines in our pref branch
- && line.includes(ZOTERO_CONFIG.PREF_BRANCH);
- })
- // Process each line individually
- .forEach((line) => {
- try {
- Zotero.debug("Processing " + line);
- Components.utils.evalInSandbox(line, sandbox);
- }
- catch (e) {
- Zotero.logError("Error processing prefs line: " + line);
- }
- });
-
- var prefs = sandbox.prefs;
+ let prefs = yield Zotero.Profile.readPrefsFromFile(prefsFile);
// Check for data dir pref
if (prefs['extensions.zotero.dataDir'] && prefs['extensions.zotero.useDataDir']) {
diff --git a/chrome/content/zotero/xpcom/profile.js b/chrome/content/zotero/xpcom/profile.js
@@ -240,6 +240,38 @@ Zotero.Profile = {
},
+ readPrefsFromFile: async function (prefsFile) {
+ var sandbox = new Components.utils.Sandbox("http://www.example.com/");
+ Components.utils.evalInSandbox(
+ "var prefs = {};"+
+ "function user_pref(key, val) {"+
+ "prefs[key] = val;"+
+ "}"
+ , sandbox);
+
+ (await Zotero.File.getContentsAsync(prefsFile))
+ .split(/\n/)
+ .filter((line) => {
+ // Strip comments
+ return !line.startsWith('#')
+ // Only process lines in our pref branch
+ && line.includes(ZOTERO_CONFIG.PREF_BRANCH);
+ })
+ // Process each line individually
+ .forEach((line) => {
+ try {
+ Zotero.debug("Processing " + line);
+ Components.utils.evalInSandbox(line, sandbox);
+ }
+ catch (e) {
+ Zotero.logError("Error processing prefs line: " + line);
+ }
+ });
+
+ return sandbox.prefs;
+ },
+
+
//
// Private methods
//