Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(frontend:files): unlock text editors on page unload
johaven4f9025e3bcc2
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.tsindex e7a1a4af..42d02e5b 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts@@ -1,5 +1,5 @@import { HttpClient, HttpErrorResponse } from '@angular/common/http'-import { Directive, effect, inject, input, model, OnDestroy, signal, untracked } from '@angular/core'+import { Directive, effect, HostListener, inject, input, model, OnDestroy, signal, untracked } from '@angular/core'import type { FileLockProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'import { L10N_LOCALE, L10nLocale } from 'angular-l10n'import { firstValueFrom } from 'rxjs'@@ -56,6 +56,13 @@ export abstract class FilesViewerEditableBase implements OnDestroy {}}+ @HostListener('window:pagehide', ['$event'])+ protected onPageHide(event: PageTransitionEvent) {+ if (!event.persisted) {+ this.unlockFileOnPageUnload()+ }+ }+protected abstract currentFileContent(): stringprotected abstract onContentLoaded(content: string): void@@ -156,6 +163,13 @@ export abstract class FilesViewerEditableBase implements OnDestroy {}}+ private unlockFileOnPageUnload() {+ // Firefox may cancel this request when closing the tab before it reaches the backend.+ if (this.unlockRequested || this.isReadonly() || !this.file().lock || !this.isSupported() || !this.isWriteable()) return+ this.unlockRequested = true+ this.filesServices.unlock(this.file()).subscribe({ error: () => undefined })+ }+private lockError(e: HttpErrorResponse) {this.isReadonly.set(true)this.isSupported.set(false)