瀏覽代碼

Fix testing issues (#1552)

Vishnu Mohandas 1 年之前
父節點
當前提交
2a209b7590
共有 2 個文件被更改,包括 29 次插入0 次删除
  1. 10 0
      apps/photos/src/services/clipService.ts
  2. 19 0
      apps/photos/src/services/download/index.ts

+ 10 - 0
apps/photos/src/services/clipService.ts

@@ -45,12 +45,22 @@ class ClipServiceImpl {
         this.liveEmbeddingExtractionQueue = new PQueue({
         this.liveEmbeddingExtractionQueue = new PQueue({
             concurrency: 1,
             concurrency: 1,
         });
         });
+        eventBus.on(Events.LOGOUT, this.logoutHandler, this);
     }
     }
 
 
     isPlatformSupported = () => {
     isPlatformSupported = () => {
         return isElectron() && !this.unsupportedPlatform;
         return isElectron() && !this.unsupportedPlatform;
     };
     };
 
 
+    private logoutHandler = async () => {
+        if (this.embeddingExtractionInProgress) {
+            this.embeddingExtractionInProgress.abort();
+        }
+        if (this.onFileUploadedHandler) {
+            await this.removeOnFileUploadListener();
+        }
+    };
+
     setupOnFileUploadListener = async () => {
     setupOnFileUploadListener = async () => {
         try {
         try {
             if (this.unsupportedPlatform) {
             if (this.unsupportedPlatform) {

+ 19 - 0
apps/photos/src/services/download/index.ts

@@ -19,6 +19,7 @@ import { PhotosDownloadClient } from './clients/photos';
 import { PublicAlbumsDownloadClient } from './clients/publicAlbums';
 import { PublicAlbumsDownloadClient } from './clients/publicAlbums';
 import isElectron from 'is-electron';
 import isElectron from 'is-electron';
 import { isInternalUser } from 'utils/user';
 import { isInternalUser } from 'utils/user';
+import { Events, eventBus } from '@ente/shared/events';
 
 
 export type LivePhotoSourceURL = {
 export type LivePhotoSourceURL = {
     image: () => Promise<string>;
     image: () => Promise<string>;
@@ -89,12 +90,30 @@ class DownloadManagerImpl {
             this.diskFileCache = isElectron() && (await openDiskFileCache());
             this.diskFileCache = isElectron() && (await openDiskFileCache());
             this.cryptoWorker = await ComlinkCryptoWorker.getInstance();
             this.cryptoWorker = await ComlinkCryptoWorker.getInstance();
             this.ready = true;
             this.ready = true;
+            eventBus.on(Events.LOGOUT, this.logoutHandler.bind(this), this);
         } catch (e) {
         } catch (e) {
             logError(e, 'DownloadManager init failed');
             logError(e, 'DownloadManager init failed');
             throw e;
             throw e;
         }
         }
     }
     }
 
 
+    private async logoutHandler() {
+        try {
+            addLogLine('downloadManger logoutHandler started');
+            this.ready = false;
+            this.cryptoWorker = null;
+            this.downloadClient = null;
+            this.fileObjectURLPromises.clear();
+            this.fileConversionPromises.clear();
+            this.thumbnailObjectURLPromises.clear();
+            this.fileDownloadProgress.clear();
+            this.progressUpdater = () => {};
+            addLogLine('downloadManager logoutHandler completed');
+        } catch (e) {
+            logError(e, 'downloadManager logoutHandler failed');
+        }
+    }
+
     updateToken(token: string, passwordToken?: string) {
     updateToken(token: string, passwordToken?: string) {
         this.downloadClient.updateTokens(token, passwordToken);
         this.downloadClient.updateTokens(token, passwordToken);
     }
     }