import { ipcRenderer , contextBridge , IpcRendererEvent } from 'electron' ; import * as Sentry from '@sentry/electron/dist/renderer' ; import { Handler , Broadcast } from './backend/backend.interface' ; import { connectSocket , sendBackIpc , listenBackIpc , unlistenBackIpc } from './client-ipc' ; import { version } from './package.json' ; const isProd = process . env . NODE_ENV === 'production' ; const isStudio = process . env . STUDIO === 'true' ; const isDarwin = process . platform === 'darwin' ; Sentry . init ( { dsn : process . env . SENTRYDNS } ) ; Sentry . setContext ( 'character' , { runtime : 'renderer' , isProd , isDarwin , isStudio , version , } ) ; let ISMAXIMIZED = false ; contextBridge . exposeInMainWorld ( 'env' , { isProd , isDarwin , isStudio , version , port : process . env . PORT || 1212 , sentryDns : process . env . SENTRYDNS , isMaximized : ( ) => ISMAXIMIZED , } ) ; ipcRenderer . on ( 'isMaximized' , ( event , isMaximized ) => { ISMAXIMIZED = isMaximized ; if ( isMaximized ) { document . body . classList . add ( 'maximized' ) ; } else { document . body . classList . remove ( 'maximized' ) ; } } ) ; contextBridge . exposeInMainWorld ( 'derealize' , { sendBackIpc , listenBackIpc , unlistenBackIpc , listenMainIpc : ( key , listener ) => { ipcRenderer . on ( key , listener ) ; } , unlistenMainIpc : ( key ) => { ipcRenderer . removeAllListeners ( key ) ; } , sendMainIpc : ( key , ... args ) => { ipcRenderer . send ( key , ... args ) ; } , sendMainIpcSync : ( key , ... args ) : any => { return ipcRenderer . sendSync ( key , ... args ) ; } , } ) ; ipcRenderer . on ( 'setParams' , ( event , socketId ) => { connectSocket ( socketId ) ; } ) ; export interface PreloadWindow extends Window { env : { isProd : boolean ; isDarwin : boolean ; isStudio : boolean ; version : string ; port : boolean ; sentryDns : string ; isMaximized : ( ) => boolean ; } ; derealize : { sendBackIpc : ( handler : Handler , payload : Record < string , unknown > ) => Promise < unknown > ; listenBackIpc : ( broadcast : Broadcast , cb : ( payload : any ) => void ) => ( ) => void ; unlistenBackIpc : ( broadcast : Broadcast ) => void ; listenMainIpc : ( key : string , listener : ( event : IpcRendererEvent , ... args : any [ ] ) => void ) => void ; unlistenMainIpc : ( key : string ) => void ; sendMainIpc : ( key : string , ... args : any [ ] ) => void ; sendMainIpcSync : ( key : string , ... args : any [ ] ) => any ; } ; }