From c6cb46907e566cd6c28b0c509e52c8a47f1b0dea Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 16 Jun 2017 04:49:08 -0400 Subject: [PATCH] Disable full-text content processor during sync and on pref off Turning off full-text content syncing now stops the background processor --- chrome/content/zotero/xpcom/fulltext.js | 37 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index 23abb9033..efeb0aa2c 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -99,8 +99,36 @@ Zotero.Fulltext = Zotero.FullText = new function(){ yield this.registerPDFTool('converter'); yield this.registerPDFTool('info'); - Zotero.uiReadyPromise.delay(30000).then(() => this.startContentProcessor()); - Zotero.addShutdownListener(this.stopContentProcessor.bind(this)); + Zotero.uiReadyPromise.delay(30000).then(() => { + this.startContentProcessor(); + Zotero.addShutdownListener(this.stopContentProcessor.bind(this)); + + // Start/stop content processor with full-text content syncing pref + Zotero.Prefs.registerObserver('sync.fulltext.enabled', (enabled) => { + if (enabled) { + this.startContentProcessor(); + } + else { + this.stopContentProcessor(); + } + }); + + // Stop content processor during syncs + Zotero.Notifier.registerObserver( + { + notify: Zotero.Promise.method(function (event, type, ids, extraData) { + if (event == 'start') { + this.stopContentProcessor(); + } + else if (event == 'stop') { + this.startContentProcessor(); + } + }.bind(this)) + }, + ['sync'], + 'fulltext' + ); + }); }); @@ -1014,8 +1042,10 @@ Zotero.Fulltext = Zotero.FullText = new function(){ * Start the idle observer for the background content processor */ this.startContentProcessor = function () { + if (!Zotero.Prefs.get('sync.fulltext.enabled')) return; + if (!_idleObserverIsRegistered) { - Zotero.debug("Initializing full-text content ingester idle observer"); + Zotero.debug("Starting full-text content processor"); var idleService = Components.classes["@mozilla.org/widget/idleservice;1"] .getService(Components.interfaces.nsIIdleService); idleService.addIdleObserver(this.idleObserver, _idleObserverDelay); @@ -1028,6 +1058,7 @@ Zotero.Fulltext = Zotero.FullText = new function(){ */ this.stopContentProcessor = function () { if (_idleObserverIsRegistered) { + Zotero.debug("Stopping full-text content processor"); var idleService = Components.classes["@mozilla.org/widget/idleservice;1"] .getService(Components.interfaces.nsIIdleService); idleService.removeIdleObserver(this.idleObserver, _idleObserverDelay);