 
 primaryDisplay = null
 windows = null
+counter = 0
+
+cacheDirPromise = Promise.promise (resolve, reject) ->
+  dirName = path.resolve __dirname, '../cache'
+  mkdirp dirName, (err) ->
+    return reject err if err
+    resolve dirName
+
+getCacheImagePath = (url, width, height) ->
+  cacheDirPromise
+  .then (cacheDir) ->
+    hash = crypto
+      .createHash 'md5'
+      .update String(width) + String(height) + url
+      .digest 'hex'
+    path.join cacheDir, "#{hash}.png"
 
 closeWindows = ->
   return unless windows?.length > 0

      height: bounds.height
      enableLargerThanScreen: true
      frame: false
    window.setBounds(bounds, false);

    # window.loadURL('http://mucholol.com/');
    # https://www.youtube.com/watch?v=NeQ0_e7aa8o

    # window.loadURL('http://www.youtube.com/embed/NeQ0_e7aa8o?autoplay=1&loop=1&controls=0&showinfo=0&rel=0&autohide=1&playlist=NeQ0_e7aa8o');
    # window.loadURL('http://www.youtube.com/embed/O4UV_SVGSUU?autoplay=1&loop=1&controls=0&showinfo=0&rel=0&autohide=1&playlist=O4UV_SVGSUU');
    # window.loadURL "file://#{path.resolve __dirname, '..'}/index.html#bounds=#{boundsStr}"
    window.loadURL display.url

    # window.webContents.openDevTools();

    window.on 'closed', ->
      closeWindows()
      # app.quit()
      Launcher.show primaryDisplay

    windows.push window

  # and load the index.html of the app.

  # Open the DevTools.
  # mainWindow.webContents.openDevTools();

  # Emitted when the window is closed.
  # mainWindow.on('closed', function() {
  #   # Dereference the window object, usually you would store windows
  #   # in an array if your app supports multi windows, this is the time
  #   # when you should delete the corresponding element.
  #   mainWindow = null;
  # });

ipcMain.on 'launch', (event, data) ->
  createWindows data.displays

# This method will be called when Electron has finished
# initialization and is ready to create browser windows.
app.on 'ready', ->
  electronScreen = electron.screen
  primaryDisplay = electronScreen.getPrimaryDisplay()
  Launcher.show primaryDisplay

# # Quit when all windows are closed.
# app.on 'window-all-closed', ->
#   # On OS X it is common for applications and their menu bar
#   # to stay active until the user quits explicitly with Cmd + Q
#   if process.platform != 'darwin'
#     app.quit()

# app.on 'activate', ->
#   # On OS X it's common to re-create a window in the app when the
#   # dock icon is clicked and there are no other windows open.
#   # if (mainWindow === null) {
#   #   createWindows();
#   # }

fs = require 'fs'
path = require 'path'
crypto = require 'crypto'

_ = require 'lodash'
electron = require 'electron'
mkdirp = require 'mkdirp'
Promise = require 'when'

Launcher = require './launcher'

