import { ipcMain , IpcMainInvokeEvent } from 'electron' ; import { IPCKey } from '../common/Constants' ; import { createNewWindow , getWindowIds , sendMessage } from './WindowManager' ; param ev const onCreateNewWindow = ( ev ) => { createNewWindow ( ) ; } ; param ev param targetWindowId param message const onSendMessage = ( ev , targetWindowId , message ) => { ev . sender . send ( IPCKey . SendMessage , sendMessage ( targetWindowId , message ) ) ; } ; param ev const onGetWindowIds = ( ev ) => { return getWindowIds ( ) ; } ; /**
 * A value indicating that an IPC events has been initialized.
 */ let initialized = false ; /**
 * Initialize IPC events.
 */ export const initializeIpcEvents = ( ) => { if ( initialized ) { return ; } initialized = true ; ipcMain . handle ( IPCKey . CreateNewWindow , onCreateNewWindow ) ; ipcMain . handle ( IPCKey . SendMessage , onSendMessage ) ; ipcMain . handle ( IPCKey . GetWindowIds , onGetWindowIds ) ; } ; /**
 * Release IPC events.
 */ export const releaseIpcEvents = ( ) => { if ( initialized ) { ipcMain . removeAllListeners ( IPCKey . CreateNewWindow ) ; ipcMain . removeAllListeners ( IPCKey . SendMessage ) ; ipcMain . removeAllListeners ( IPCKey . GetWindowIds ) ; } initialized = false ; } ;