From d39c422da95bd60f3f4ff5f575705f06be4280e4 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 7 Apr 2014 09:37:44 -0700 Subject: [PATCH] Add content to AutoUpdater --- src/browser/auto-updater.coffee | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/browser/auto-updater.coffee b/src/browser/auto-updater.coffee index 62aa36624..a0f7356b1 100644 --- a/src/browser/auto-updater.coffee +++ b/src/browser/auto-updater.coffee @@ -1,2 +1,55 @@ +autoUpdater = require 'auto-updater' +dialog = require 'dialog' + module.exports = class AutoUpdater + constructor: (@applicationMenu) -> + + # Only released versions should check for updates. + return if /\w{7}/.test(@getVersion()) + + autoUpdater.setFeedUrl "https://atom.io/api/updates?version=#{@getVersion()}" + + autoUpdater.on 'checking-for-update', => + @applicationMenu.showDownloadingUpdateItem(false) + @applicationMenu.showInstallUpdateItem(false) + @applicationMenu.showCheckForUpdateItem(false) + + autoUpdater.on 'update-not-available', => + @applicationMenu.showCheckForUpdateItem(true) + + autoUpdater.on 'update-available', => + @applicationMenu.showDownloadingUpdateItem(true) + + autoUpdater.on 'update-downloaded', (event, releaseNotes, releaseVersion, releaseDate, releaseURL) => + for atomWindow in @getWindows() + atomWindow.sendCommand('window:update-available', [releaseVersion, releaseNotes]) + @applicationMenu.showInstallUpdateItem(true) + + autoUpdater.on 'error', (event, message) => + @applicationMenu.showCheckForUpdateItem(true) + + # Check for update after Atom has fully started and the menus are created + setTimeout((-> autoUpdater.checkForUpdates()), 5000) + + checkForUpdate: -> + autoUpdater.once 'update-not-available', @onUpdateNotAvailable + autoUpdater.once 'error', @onUpdateError + autoUpdater.checkForUpdates() + + installUpdate: -> + autoUpdater.quitAndInstall() + + onUpdateNotAvailable: => + autoUpdater.removeListener 'error', @onUpdateError + dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'No update available.', detail: "Version #{@version} is the latest version." + + onUpdateError: (event, message) => + autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable + dialog.showMessageBox type: 'warning', buttons: ['OK'], message: 'There was an error checking for updates.', detail: message + + getVersion: -> + global.atomApplication.version + + getWindows: -> + global.atomApplication.windows