From d3c780e079288abe6d2b47631561f755fb847dc2 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Tue, 3 Jan 2023 20:13:54 +0100 Subject: [PATCH] Revert "Use Multi-Messaging Service (#4304)" (#4374) This reverts commit b1ee65dca80c625a506beb11537d74ec6c95f58f. --- .../browser/src/background/main.background.ts | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index d906d2d42f..4ef078bde5 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -214,25 +214,9 @@ export default class MainBackground { const logoutCallback = async (expired: boolean, userId?: string) => await this.logout(expired, userId); - const messagingServices: MessagingServiceAbstraction[] = []; - if (!isPrivateMode) { - // Sent to detached background - messagingServices.push(new BrowserMessagingService()); - } - - if (this.popupOnlyContext) { - // Sent to popup - messagingServices.push(new BrowserMessagingPrivateModeBackgroundService()); - } - - this.messagingService = new (class extends MessagingServiceAbstraction { - // AuthService should send the messages to the background not popup. - send = (subscriber: string, arg: any = {}) => { - for (const messagingService of messagingServices) { - messagingService.send(subscriber, arg); - } - }; - })(); + this.messagingService = this.popupOnlyContext + ? new BrowserMessagingPrivateModeBackgroundService() + : new BrowserMessagingService(); this.logService = new ConsoleLogService(false); this.cryptoFunctionService = new WebCryptoFunctionService(window); this.storageService = new BrowserLocalStorageService(); @@ -368,13 +352,22 @@ export default class MainBackground { this.twoFactorService = new TwoFactorService(this.i18nService, this.platformUtilsService); + // eslint-disable-next-line + const that = this; + const backgroundMessagingService = new (class extends MessagingServiceAbstraction { + // AuthService should send the messages to the background not popup. + send = (subscriber: string, arg: any = {}) => { + const message = Object.assign({}, { command: subscriber }, arg); + that.runtimeBackground.processMessage(message, that, null); + }; + })(); this.authService = new AuthService( this.cryptoService, this.apiService, this.tokenService, this.appIdService, this.platformUtilsService, - this.messagingService, + backgroundMessagingService, this.logService, this.keyConnectorService, this.environmentService,