Move prefs.js parsing to Zotero.Profile.readPrefsFromFile(prefsFile)
This commit is contained in:
parent
7f81e62bc8
commit
8d0dc359b4
2 changed files with 33 additions and 29 deletions
|
@ -255,35 +255,7 @@ Zotero.DataDirectory = {
|
||||||
// Read in prefs
|
// Read in prefs
|
||||||
let prefsFile = OS.Path.join(profileDir, "prefs.js");
|
let prefsFile = OS.Path.join(profileDir, "prefs.js");
|
||||||
if (yield OS.File.exists(prefsFile)) {
|
if (yield OS.File.exists(prefsFile)) {
|
||||||
// build sandbox
|
let prefs = yield Zotero.Profile.readPrefsFromFile(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);
|
|
||||||
|
|
||||||
(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;
|
|
||||||
|
|
||||||
// Check for data dir pref
|
// Check for data dir pref
|
||||||
if (prefs['extensions.zotero.dataDir'] && prefs['extensions.zotero.useDataDir']) {
|
if (prefs['extensions.zotero.dataDir'] && prefs['extensions.zotero.useDataDir']) {
|
||||||
|
|
|
@ -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
|
// Private methods
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue