         when 0 then setImmediate => @browserWindow.destroy()
         when 1 then @browserWindow.restart()
 
-    if @isSpec
+    if isSpec
       # Spec window's web view should always have focus
       @browserWindow.on 'blur', =>
         @browserWindow.focusOnWebView()

    else
      false

  handleEvents: ->
    @browserWindow.on 'destroyed', =>
      global.atomApplication.removeWindow(this)


ipc = require 'ipc'
path = require 'path'
fs = require 'fs'
_ = require 'underscore'

module.exports =
class AtomWindow
  browserWindow: null

  constructor: (settings={}) ->
    {resourcePath, pathToOpen, isSpec} = settings
    global.atomApplication.addWindow(this)

    @setupNodePath(resourcePath)
    @browserWindow = new BrowserWindow show: false, title: 'Atom'
    @handleEvents(isSpec)

    loadSettings = _.extend({}, settings)
    loadSettings.windowState ?= ''
    loadSettings.initialPath = pathToOpen
    try
      if fs.statSync(pathToOpen).isFile()
        loadSettings.initialPath = path.dirname(pathToOpen)

    @browserWindow.loadSettings = loadSettings
    @browserWindow.once 'window:loaded', => @loaded = true
    @browserWindow.loadUrl "file://#{resourcePath}/static/index.html"

