From 8d0dc359b428e16468c5cd0363ab7317cd5331f8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 1 Apr 2018 13:44:10 -0400 Subject: [PATCH] Move prefs.js parsing to Zotero.Profile.readPrefsFromFile(prefsFile) --- chrome/content/zotero/xpcom/dataDirectory.js | 30 +----------------- chrome/content/zotero/xpcom/profile.js | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js index c2dcd17de0..136adc19b4 100644 --- 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 index f1b825ae99..4a06a71f7d 100644 --- 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 //