From 91675ea99c5770845b38cac71ccc818af8a61570 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 22 Nov 2025 20:35:36 +0000 Subject: [PATCH] Add remove event listener methods --- frontend/sync-client/src/persistence/settings.ts | 9 +++++++++ frontend/sync-client/src/services/websocket-manager.ts | 9 +++++++++ .../src/sync-operations/file-change-notifier.ts | 9 +++++++++ frontend/sync-client/src/sync-operations/syncer.ts | 9 +++++++++ frontend/sync-client/src/tracing/logger.ts | 9 +++++++++ frontend/sync-client/src/tracing/sync-history.ts | 9 +++++++++ 6 files changed, 54 insertions(+) diff --git a/frontend/sync-client/src/persistence/settings.ts b/frontend/sync-client/src/persistence/settings.ts index 462c591f..98c5c523 100644 --- a/frontend/sync-client/src/persistence/settings.ts +++ b/frontend/sync-client/src/persistence/settings.ts @@ -59,6 +59,15 @@ export class Settings { this.onSettingsChangeHandlers.push(listener); } + public removeOnSettingsChangeListener( + listener: (settings: SyncSettings, oldSettings: SyncSettings) => unknown + ): void { + const index = this.onSettingsChangeHandlers.indexOf(listener); + if (index !== -1) { + this.onSettingsChangeHandlers.splice(index, 1); + } + } + public async setSetting( key: T, value: SyncSettings[T] diff --git a/frontend/sync-client/src/services/websocket-manager.ts b/frontend/sync-client/src/services/websocket-manager.ts index a30774f4..8de399e3 100644 --- a/frontend/sync-client/src/services/websocket-manager.ts +++ b/frontend/sync-client/src/services/websocket-manager.ts @@ -74,6 +74,15 @@ export class WebSocketManager { this.remoteCursorsUpdateListeners.push(listener); } + public removeRemoteCursorsUpdateListener( + listener: (cursors: ClientCursors[]) => unknown + ): void { + const index = this.remoteCursorsUpdateListeners.indexOf(listener); + if (index !== -1) { + this.remoteCursorsUpdateListeners.splice(index, 1); + } + } + public start(): void { this.isStopped = false; this._isFirstSyncCompleted = false; diff --git a/frontend/sync-client/src/sync-operations/file-change-notifier.ts b/frontend/sync-client/src/sync-operations/file-change-notifier.ts index 8a7af66c..2c099b6f 100644 --- a/frontend/sync-client/src/sync-operations/file-change-notifier.ts +++ b/frontend/sync-client/src/sync-operations/file-change-notifier.ts @@ -9,6 +9,15 @@ export class FileChangeNotifier { this.listeners.push(listener); } + public removeFileChangeListener( + listener: (filePath: RelativePath) => unknown + ): void { + const index = this.listeners.indexOf(listener); + if (index !== -1) { + this.listeners.splice(index, 1); + } + } + public notifyOfFileChange(filePath: RelativePath): void { this.listeners.forEach((listener) => listener(filePath)); } diff --git a/frontend/sync-client/src/sync-operations/syncer.ts b/frontend/sync-client/src/sync-operations/syncer.ts index 920a6423..d1aa5faf 100644 --- a/frontend/sync-client/src/sync-operations/syncer.ts +++ b/frontend/sync-client/src/sync-operations/syncer.ts @@ -61,6 +61,15 @@ export class Syncer { this.remainingOperationsListeners.push(listener); } + public removeRemainingOperationsListener( + listener: (remainingOperations: number) => unknown + ): void { + const index = this.remainingOperationsListeners.indexOf(listener); + if (index !== -1) { + this.remainingOperationsListeners.splice(index, 1); + } + } + public async syncLocallyCreatedFile( relativePath: RelativePath ): Promise { diff --git a/frontend/sync-client/src/tracing/logger.ts b/frontend/sync-client/src/tracing/logger.ts index ca32bbce..96b93b0d 100644 --- a/frontend/sync-client/src/tracing/logger.ts +++ b/frontend/sync-client/src/tracing/logger.ts @@ -60,6 +60,15 @@ export class Logger { this.onMessageListeners.push(listener); } + public removeOnMessageListener( + listener: (message: LogLine) => unknown + ): void { + const index = this.onMessageListeners.indexOf(listener); + if (index !== -1) { + this.onMessageListeners.splice(index, 1); + } + } + public reset(): void { this.messages.length = 0; this.debug("Logger has been reset"); diff --git a/frontend/sync-client/src/tracing/sync-history.ts b/frontend/sync-client/src/tracing/sync-history.ts index 915c78b7..0d2009f7 100644 --- a/frontend/sync-client/src/tracing/sync-history.ts +++ b/frontend/sync-client/src/tracing/sync-history.ts @@ -119,6 +119,15 @@ export class SyncHistory { listener({ ...this.status }); } + public removeSyncHistoryUpdateListener( + listener: (stats: HistoryStats) => unknown + ): void { + const index = this.syncHistoryUpdateListeners.indexOf(listener); + if (index !== -1) { + this.syncHistoryUpdateListeners.splice(index, 1); + } + } + public reset(): void { this._entries.length = 0; this.status = {