import React from 'react'
import ReactDOM from 'react-dom'
import { App } from './App'

const { ipcRenderer } = require('electron')
let start: boolean = false

ipcRenderer.on('preload', (_event: any, data: VixonicData) => {
  render(data)
})

ipcRenderer.on('start', (_event: any, data: VixonicData) => {
  start = true
  render(data)
})

ipcRenderer.on('update', (_event: any, data: VixonicData) => {
  render(data)
})

ipcRenderer.on('finish', (_event: VixonicData) => {
  console.log('finish')
})

function render(data: VixonicData) {
  ReactDOM.render(React.createElement(App, { data, start }), document.getElementById('root'))
}
