从主stream程向所有渲染器处理电子广播事件
我知道如何使用ipcRenderer.send()
和ipcMain.on()
将事件从渲染器进程发送到主进程。 我也可以使用event.sender.send()
将回复发送给渲染器进程,但是我怎么能从主进程向所有渲染进程发送事件,更像广播。
您可以创build对BrowserWindow实例的引用数组,并且在需要全局事件时,可以将其与发送者函数进行映射,例如:
let windows = []; let backgroundComputation = new BrowserWindow(options); let webInteractions = new BrowserWindow(different_options); let imageProcessing = new BrowserWindow(another_options); windows.push(backgroundComputation) windows.push(webInteractions) windows.push(imageProcessing) let sender = (message, windows) => windows.map((ref) => ref.webContents.send('event_name', message))
这可能会很方便,如果你有一大堆他们。 您还可以在选项alwaysOnTop:true
设置标志alwaysOnTop:true
对于窗口顶部的true,以便任何其他窗口将保持在下方。 希望这可以帮助!