Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(sync): only save on close if changes were made
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Jul 12, 2023
commit 0fe2f30696fdd09754d3ac5f2774d4ada9591647
6 changes: 5 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,17 @@ export default {
this.$syncService = null
this.$attachmentResolver = null
},
beforeDestroy() {
async beforeDestroy() {
if (!this.richWorkspace) {
window.removeEventListener('beforeprint', this.preparePrinting)
window.removeEventListener('afterprint', this.preparePrinting)
}
unsubscribe('text:image-node:add', this.onAddImageNode)
unsubscribe('text:image-node:delete', this.onDeleteImageNode)
if (this.dirty) {
const timeout = new Promise((resolve) => setTimeout(resolve, 2000))
await Promise.any([timeout, this.$syncService.save()])
Copy link
Member

@juliusknorr juliusknorr Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something but wouldn't this be called after the text session has been closed already then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The text session is closed afterwards where we destroy all the providers - one of which is the SyncServiceProvider which will close the session on destruction.
Only if the save takes longer than the timeout the provider will be destroyed never the less.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, makes sense. I just got confused by the close/_close methods of the sync service and how they would be triggered as I assumed that the viewer close calls them, but that doesn't seem to be the case. 👍

}
this.$providers.forEach(p => p.destroy())
},
methods: {
Expand Down
2 changes: 0 additions & 2 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ class SyncService {

async close() {
this.backend?.disconnect()
const timeout = new Promise((resolve) => setTimeout(resolve, 2000))
await Promise.any([timeout, this.save()])
return this._close()
}

Expand Down