1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-28 04:08:47 +02:00

[PM-3684] Remove ipcRenderer from electron.renderer.messaging (#6480)

This commit is contained in:
Daniel García 2023-10-17 13:41:19 +02:00 committed by GitHub
parent d79ef473c6
commit 1f26f6579d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -17,6 +17,16 @@ export default {
onSystemThemeUpdated: (callback: (theme: ThemeType) => void) => {
ipcRenderer.on("systemThemeUpdated", (_event, theme: ThemeType) => callback(theme));
},
sendMessage: (message: { command: string } & any) =>
ipcRenderer.send("messagingService", message),
onMessage: (callback: (message: { command: string } & any) => void) => {
ipcRenderer.on("messagingService", (_event, message: any) => {
if (message.command) {
callback(message);
}
});
},
};
function deviceType(): DeviceType {

View File

@ -1,15 +1,9 @@
import { ipcRenderer } from "electron";
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
export class ElectronRendererMessagingService implements MessagingService {
constructor(private broadcasterService: BroadcasterService) {
ipcRenderer.on("messagingService", async (event: any, message: any) => {
if (message.command) {
this.sendMessage(message.command, message, false);
}
});
ipc.platform.onMessage((message) => this.sendMessage(message.command, message, false));
}
send(subscriber: string, arg: any = {}) {
@ -20,7 +14,7 @@ export class ElectronRendererMessagingService implements MessagingService {
const message = Object.assign({}, { command: subscriber }, arg);
this.broadcasterService.send(message);
if (toMain) {
ipcRenderer.send("messagingService", message);
ipc.platform.sendMessage(message);
}
}
}