import { useCallback } from 'react' ; import { ClientMessage , ElectronMessage } from '../../../../../shared/types' ; const electron = window . require ( 'electron' ) ; type SendMessage = < T > ( msgId : ClientMessage , payload ? : T ) => void ; type OnMessage = < T > ( msgId : ElectronMessage , callback : ( _ : unknown , data : T ) => void ) => void ; type UseElectron = ( ) => { sendMessage : SendMessage ; onMessage : OnMessage ; } ; export const useElectron = ( ) => { const sendMessage = useCallback ( ( msgId , payload ) => { electron . ipcRenderer . send ( msgId , payload ) ; } , [ ] ) ; const onMessage = useCallback ( ( msgId , cb ) => { electron . ipcRenderer . on ( msgId , cb ) ; } , [ ] ) ; return { sendMessage , onMessage , } ; } ;