import { BrowserWindow , ipcMain , IpcMainEvent } from 'electron' ; import { withHomeWindow } from 'root/app/main_window' ; import { withOverlayWindow } from 'root/app/overlay_window' ; import { Message , MessageCallback , Messages , onBridgeMessageGeneric , onMessageGeneric } from 'root/lib/messages' ; export function sendMessageToHomeWindow < M extends Message > ( message , data ) { withHomeWindow ( ( _ ) => sendMessageToBrowserWindow ( _ , message , data ) ) ; } export function sendMessageToOverlayWindow < M extends Message > ( message , data ) { withOverlayWindow ( ( _ ) => sendMessageToBrowserWindow ( _ , message , data ) ) ; } function sendMessageToBrowserWindow < M extends Message > ( browserWindow , message , data ) { browserWindow . webContents . send ( 'bridge-message' , { message , data } ) ; } const allCallbacks = new Map < Message , MessageCallback < Message > [ ] > ( ) ; ipcMain . on ( 'bridge-message' , function < M extends Message > ( _ , data ) : void { onBridgeMessageGeneric ( allCallbacks , data ) ; } ) ; export function onMessageFromBrowserWindow < M extends Message > ( message , cb ) { onMessageGeneric ( allCallbacks , message , cb ) ; }