+{remote} = window
 fs = require 'fs'
 glob = require 'glob'
 path = require 'path-extra'
+try ipc = remote.require './lib/ipc'
+catch error then console.log error
 
 {React, ReactDOM, ReactBootstrap} = window
 ModalArea = require './modal-area'


  componentDidMount: ->
    window.addEventListener 'game.response', @handleResponse

    setTimeout =>
      # Read packets from disk.

        battleNonce: battleNonce
        battlePacket: battlePacket

  # API for IPC
  showBattleWithTimestamp: (timestamp, callback) ->
    range = [timestamp - 2000, timestamp + 2000]
    list = glob.sync(path.join(APPDATA, "{#{range[0]}..#{range[1]}}.json"))
    if list.length == 1
      try
        packet = loadPacketSync list[0]
        @updateBattlePacket packet
        remote.getCurrentWindow().focus()
      catch error
        message __ "Unknown error"
        console.error error
    if list.length <= 0
      message = __ "Packet not found."
    if list.length >= 2
      message = __ "Multiple packets found."
    callback(message)

  # API for Component <OptionArea />
  shouldAutoShow: true

