From 0cd7a52dc020b29bb4981719ccc15548640f4600 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:18:49 +0800 Subject: [PATCH] Fix attachment preview retry and error catch --- chrome/content/zotero/elements/attachmentPreview.js | 6 +++++- chrome/content/zotero/xpcom/reader.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/elements/attachmentPreview.js b/chrome/content/zotero/elements/attachmentPreview.js index 71a8360d2e..ec0e044863 100644 --- a/chrome/content/zotero/elements/attachmentPreview.js +++ b/chrome/content/zotero/elements/attachmentPreview.js @@ -50,6 +50,7 @@ this._isDiscardPlanned = false; this._isDiscarding = false; + this._failedCount = 0; this._intersectionOb = new IntersectionObserver(this._handleIntersection.bind(this)); this._resizeOb = new ResizeObserver(this._handleResize.bind(this)); @@ -293,8 +294,10 @@ await this.discard(true); this._reader = await Zotero.Reader.openPreview(this._item.id, this._id("preview")); success = await this._reader._open({}); - if (!success) { + // Retry 3 times if failed + if (!success && this._failedCount < 3) { this._nextPreviewInitializePromise.resolve(); + this._failedCount++; // If failed on half-way of initialization, discard it this.discard(true); setTimeout(() => { @@ -306,6 +309,7 @@ else { success = true; } + if (success) this._failedCount = 0; prev && (prev.disabled = true); next && (next.disabled = false); return success; diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index ba93218a7f..d465a94d49 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -1347,7 +1347,7 @@ class ReaderPreview extends ReaderInstance { return success; } catch (e) { - Zotero.warn(`Failed to load preview for attachment ${await this._item.getFilePathAsync()}: ${String(e)}`); + Zotero.warn(`Failed to load preview for attachment ${this._item?.libraryID}/${this._item?.key}: ${String(e)}`); this._item = null; return false; }