import React from 'react' ; import ReactDOM from 'react-dom' ; import { EventEmitter } from 'events' ; import { RepoFrontend } from 'hypermerge' ; import { ToFrontendRepoMsg } from 'hypermerge/dist/RepoMsg' ; import { ipcRenderer } from 'electron' ; import ipc from '../ipc' ; import Root from './components/Root' ; import './app.css' ; import './react-toggle-override.css' ; import 'react-simple-dropdown/dropdown.css' ; import './ibm-plex.css' ; import 'line-awesome/css/line-awesome.min.css' ; import System , { FromSystemMsg } from './System' ; window . _debug = { } ; localStorage . removeItem ( 'debug' ) ; EventEmitter . defaultMaxListeners = 500 ; ipc . config . id = 'renderer' ; function initHypermerge ( cb ) { const front = new RepoFrontend ( ) ; window . _debug . repo = front ; ipc . connectTo ( 'background' , ( ) => { ipc . of . background . on ( 'repo.msg' , ( msg ) => { front . receive ( msg ) ; } ) ; front . subscribe ( ( msg ) => ipc . of . background . emit ( 'repo.msg' , msg ) ) ; } ) ; window . repo = front ; cb ( front ) ; } function initWorkspace ( repo ) { const system = initSystem ( ) ; const workspace = < Root repo = { repo } system = { system } / > ; const element = document . createElement ( 'div' ) ; element . id = 'app' ; document . body . appendChild ( element ) ; ReactDOM . render ( workspace , element ) ; if ( module . hot ) { module . hot . accept ( './components/Root.tsx' , ( ) => { const NextRoot = require ( './components/Root' ) . default ; ReactDOM . render ( < NextRoot repo = { repo } system = { system } / > , element ) ; } ) ; } } function initSystem ( ) { const system = new System ( ) ; ipcRenderer . on ( 'system.msg' , ( _event , msg ) => system . fromSystemQ . push ( msg ) ) ; ipc . of . background . on ( 'system.msg' , system . fromSystemQ . push ) ; system . toSystemQ . subscribe ( ( msg ) => { ipc . of . background . emit ( 'system.msg' , msg ) ; ipcRenderer . send ( 'system.msg' , msg ) ; } ) ; return system ; } initHypermerge ( ( repo ) => { initWorkspace ( repo ) ; } ) ;