Use IOUtils instead of OS.File

This commit is contained in:
Abe Jellinek 2023-07-05 12:54:18 -04:00 committed by Dan Stillman
parent bdb444371f
commit 0ee54b4a7e
2 changed files with 8 additions and 15 deletions

View file

@ -27,7 +27,8 @@
"L10nFileSource": false,
"L10nRegistry": false,
"ZoteroPane_Local": false,
"ZoteroPane": false
"ZoteroPane": false,
"IOUtils": false
},
"extends": [
"@zotero",

View file

@ -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);
}