Wait until annotation saving is finished before triggering another save

This commit is contained in:
Martynas Bagdonas 2024-04-10 11:38:18 +01:00
parent fcc366abe2
commit 1951c95e6b
2 changed files with 13 additions and 2 deletions

View file

@ -231,7 +231,15 @@ class ReaderInstance {
onAddToNote: (annotations) => { onAddToNote: (annotations) => {
this._addToNote(annotations); this._addToNote(annotations);
}, },
onSaveAnnotations: async (annotations) => { onSaveAnnotations: async (annotations, callback) => {
// Reader iframe will wait for this function to finish to make sure there
// aren't simultaneous transaction waiting to modify the same annotation item.
// Although simultaneous changes are still possible from different reader instances,
// but unlikely to be a problem.
// It's best to test that by running the code below in Run JavaScript tool:
// await Zotero.DB.executeTransaction(async function () {
// await Zotero.Promise.delay(15000);
// });
let attachment = Zotero.Items.get(this.itemID); let attachment = Zotero.Items.get(this.itemID);
let notifierQueue = new Zotero.Notifier.Queue(); let notifierQueue = new Zotero.Notifier.Queue();
try { try {
@ -274,6 +282,9 @@ class ReaderInstance {
throw e; throw e;
} }
finally { finally {
// Reader iframe doesn't have permissions to wait for onSaveAnnotations
// promise, therefore using callback to inform when saving finishes
callback();
await Zotero.Notifier.commit(notifierQueue); await Zotero.Notifier.commit(notifierQueue);
} }
}, },

2
reader

@ -1 +1 @@
Subproject commit c4256af7fee521cd540a2c625bd41a0a41e113f5 Subproject commit 1e124aa2886fd64c28f5153789d1ffaf95aafdfb