2013-06-03 09:59:34 +00:00
|
|
|
AutoUpdater = process.atomBinding('auto_updater').AutoUpdater
|
|
|
|
EventEmitter = require('events').EventEmitter
|
|
|
|
|
|
|
|
AutoUpdater::__proto__ = EventEmitter.prototype
|
|
|
|
|
2013-06-03 10:21:13 +00:00
|
|
|
autoUpdater = new AutoUpdater
|
2014-01-21 14:13:34 +00:00
|
|
|
autoUpdater.on 'update-downloaded-raw', (args...) ->
|
2014-02-03 20:39:54 +00:00
|
|
|
args[3] = new Date(args[3]) # releaseDate
|
2014-01-21 14:13:34 +00:00
|
|
|
@emit 'update-downloaded', args..., => @quitAndInstall()
|
2013-06-03 10:21:13 +00:00
|
|
|
|
2014-02-17 06:51:22 +00:00
|
|
|
autoUpdater.quitAndInstall = ->
|
2014-02-17 07:05:34 +00:00
|
|
|
# If we don't have any window then quitAndInstall immediately.
|
|
|
|
BrowserWindow = require 'browser-window'
|
|
|
|
windows = BrowserWindow.getAllWindows()
|
|
|
|
if windows.length is 0
|
|
|
|
AutoUpdater::quitAndInstall.call this
|
|
|
|
return
|
|
|
|
|
2014-02-17 06:51:22 +00:00
|
|
|
# Do the restart after all windows have been closed.
|
|
|
|
app = require 'app'
|
|
|
|
app.removeAllListeners 'window-all-closed'
|
|
|
|
app.once 'window-all-closed', AutoUpdater::quitAndInstall.bind(this)
|
|
|
|
|
|
|
|
# Tell all windows to remove beforeunload handler and then close itself.
|
|
|
|
ipc = require 'ipc'
|
2014-02-17 07:24:42 +00:00
|
|
|
ipc.sendChannel win, 'ATOM_SHELL_SILENT_CLOSE' for win in windows
|
2014-02-17 06:51:22 +00:00
|
|
|
|
2013-06-03 10:21:13 +00:00
|
|
|
module.exports = autoUpdater
|