From 0ee54b4a7e3fec60874dd67d183cc9f9a1570dfe Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 5 Jul 2023 12:54:18 -0400 Subject: [PATCH] Use IOUtils instead of OS.File --- .eslintrc | 3 ++- chrome/content/zotero/xpcom/reader.js | 20 ++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.eslintrc b/.eslintrc index faab80293b..e6ee7bef02 100644 --- a/.eslintrc +++ b/.eslintrc @@ -27,7 +27,8 @@ "L10nFileSource": false, "L10nRegistry": false, "ZoteroPane_Local": false, - "ZoteroPane": false + "ZoteroPane": false, + "IOUtils": false }, "extends": [ "@zotero", diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index d7b1207251..ae716cd0e4 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -672,19 +672,9 @@ class ReaderInstance { // Write the new state to disk let path = file.path; - let contents = JSON.stringify(state); - // If this is a PDF, state updates should be infrequent and we can write immediately - if (this._type == 'pdf') { - // Using `writeAtomic` instead of `putContentsAsync` to avoid - // using temp file that causes conflicts on simultaneous writes (on slow systems) - await OS.File.writeAtomic(path, contents); - return; - } - - // If this is an EPUB or snapshot, state updates are frequent (every scroll) and we need to debounce - // actually writing them to disk. We flush the debounced write operation when Zotero shuts down or the - // window/tab is closed. + // State updates can be frequent (every scroll) and we need to debounce actually writing them to disk. + // We flush the debounced write operation when Zotero shuts down or the window/tab is closed. if (this._pendingWriteStateTimeout) { clearTimeout(this._pendingWriteStateTimeout); } @@ -695,8 +685,10 @@ class ReaderInstance { this._pendingWriteStateFunction = null; this._pendingWriteStateTimeout = null; - // See above note about `writeAtomic` - await OS.File.writeAtomic(path, contents); + Zotero.debug('Writing reader state to ' + path); + // Using atomic `writeJSON` instead of `putContentsAsync` to avoid using temp file that causes conflicts + // on simultaneous writes (on slow systems) + await IOUtils.writeJSON(path, state); }; this._pendingWriteStateTimeout = setTimeout(this._pendingWriteStateFunction, 5000); }