From be8db4fc50d3895ce12a55ed032ab8853da43323 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 8 Oct 2018 02:46:13 -0400 Subject: [PATCH] Don't show progress window for PDF recognition if only one file --- .../zotero/xpcom/progressQueueDialog.js | 4 ++++ chrome/content/zotero/xpcom/recognizePDF.js | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/progressQueueDialog.js b/chrome/content/zotero/xpcom/progressQueueDialog.js index 78f63685f5..7130795b40 100644 --- a/chrome/content/zotero/xpcom/progressQueueDialog.js +++ b/chrome/content/zotero/xpcom/progressQueueDialog.js @@ -69,6 +69,10 @@ Zotero.ProgressQueueDialog = function (progressQueue) { _showMinimize = show; }; + this.isOpen = function () { + return !!_progressWindow; + }; + this.close = function () { // In case close() is called before open() if (!_progressWindow) { diff --git a/chrome/content/zotero/xpcom/recognizePDF.js b/chrome/content/zotero/xpcom/recognizePDF.js index 7abf748fc3..a7fd400780 100644 --- a/chrome/content/zotero/xpcom/recognizePDF.js +++ b/chrome/content/zotero/xpcom/recognizePDF.js @@ -105,7 +105,7 @@ Zotero.RecognizePDF = new function () { * Adds items to the queue and triggers processing * @param {Zotero.Item[]} items */ - this.recognizeItems = function (items) { + this.recognizeItems = async function (items) { for (let item of items) { if( _processingItemID === item.id || @@ -117,7 +117,7 @@ Zotero.RecognizePDF = new function () { _queue.unshift(item.id); _progressQueue.addRow(item); } - _processQueue(); + await _processQueue(); }; @@ -133,7 +133,7 @@ Zotero.RecognizePDF = new function () { }; - this.autoRecognizeItems = function (items) { + this.autoRecognizeItems = async function (items) { if (!Zotero.Prefs.get('autoRecognizeFiles')) return; var pdfs = items.filter((item) => { @@ -144,8 +144,21 @@ Zotero.RecognizePDF = new function () { if (!pdfs.length) { return; } - this.recognizeItems(pdfs); - Zotero.ProgressQueues.get('recognize').getDialog().open(); + var queue = Zotero.ProgressQueues.get('recognize'); + var dialog = queue.getDialog(); + var numInQueue = queue.getTotal(); + var promise = this.recognizeItems(pdfs); + // If the queue wasn't empty or more than one file is being saved, show the dialog + if (numInQueue > 0 || pdfs.length > 1) { + dialog.open(); + return promise; + } + await promise; + // If dialog wasn't opened automatically and wasn't opened manually, clear it after + // recognizing files + if (!dialog.isOpen()) { + queue.cancel(); + } };