1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-26 12:25:20 +01:00

Use Multi-Messaging Service (#4304)

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
This commit is contained in:
Justin Baur 2022-12-22 13:29:02 -05:00 committed by GitHub
parent d6acc77ba7
commit b1ee65dca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,9 +211,25 @@ export default class MainBackground {
const logoutCallback = async (expired: boolean, userId?: string) => const logoutCallback = async (expired: boolean, userId?: string) =>
await this.logout(expired, userId); await this.logout(expired, userId);
this.messagingService = this.popupOnlyContext const messagingServices: MessagingServiceAbstraction[] = [];
? new BrowserMessagingPrivateModeBackgroundService() if (!isPrivateMode) {
: new BrowserMessagingService(); // 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.logService = new ConsoleLogService(false); this.logService = new ConsoleLogService(false);
this.cryptoFunctionService = new WebCryptoFunctionService(window); this.cryptoFunctionService = new WebCryptoFunctionService(window);
this.storageService = new BrowserLocalStorageService(); this.storageService = new BrowserLocalStorageService();
@ -349,22 +365,13 @@ export default class MainBackground {
this.twoFactorService = new TwoFactorService(this.i18nService, this.platformUtilsService); 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.authService = new AuthService(
this.cryptoService, this.cryptoService,
this.apiService, this.apiService,
this.tokenService, this.tokenService,
this.appIdService, this.appIdService,
this.platformUtilsService, this.platformUtilsService,
backgroundMessagingService, this.messagingService,
this.logService, this.logService,
this.keyConnectorService, this.keyConnectorService,
this.environmentService, this.environmentService,