diff --git a/chrome/content/zotero/xpcom/prefs.js b/chrome/content/zotero/xpcom/prefs.js index 536d8a1005..f27781e61e 100644 --- a/chrome/content/zotero/xpcom/prefs.js +++ b/chrome/content/zotero/xpcom/prefs.js @@ -41,6 +41,8 @@ Zotero.Prefs = new function() { if (Zotero.addShutdownListener) { Zotero.addShutdownListener(this.unregister.bind(this)); } + + this._checkUserJS(); // Process pref version updates var fromVersion = this.get('prefVersion'); @@ -510,4 +512,53 @@ Zotero.Prefs = new function() { return `{{ ${[field, truncate, prefix, suffix].filter(f => f !== null).join(' ')} }}`; }); }; + + /** + * Preferences set in /user.js override prefs.js, so they can't + * be changed via the UI and may be hard to locate and remove. Warn if + * user.js contains user_pref() directives. + */ + this._checkUserJS = async function () { + let userJSPath = PathUtils.join(Zotero.Profile.dir, 'user.js'); + let userJS; + try { + userJS = await Zotero.File.getContentsAsync(userJSPath); + } + catch { + return; + } + + const DISALLOWED_PREF_RE = /^\s*user_pref\s*\(\s*['"]extensions\.zotero\.fileHandler\..+$/g; + + let updatedUserJS = userJS + .split('\n') + .filter((prefLine) => { + if (DISALLOWED_PREF_RE.test(prefLine)) { + Zotero.debug('user.js contains disallowed pref: ' + prefLine); + return false; + } + return true; + }) + .join('\n'); + + if (updatedUserJS === userJS) { + return; + } + + try { + await Zotero.File.putContentsAsync(userJSPath, updatedUserJS); + + Zotero.alert(null, + Zotero.getString('general-error'), + Zotero.getString('userjs-pref-warning') + ); + Services.startup.quit( + Components.interfaces.nsIAppStartup.eAttemptQuit + | Components.interfaces.nsIAppStartup.eRestart + ); + } + catch (e) { + Zotero.logError(e); + } + }; }; diff --git a/chrome/locale/en-US/zotero/zotero.ftl b/chrome/locale/en-US/zotero/zotero.ftl index b2430f460e..c99dd16133 100644 --- a/chrome/locale/en-US/zotero/zotero.ftl +++ b/chrome/locale/en-US/zotero/zotero.ftl @@ -767,3 +767,5 @@ mac-word-plugin-install-remind-later-button = .label = { general-remind-me-later } mac-word-plugin-install-dont-ask-again-button = .label = { general-dont-ask-again } + +userjs-pref-warning = Some { -app-name } settings have been overridden using an unsupported method. { -app-name } will revert them and restart.