From 2b3d3d9cf56bf41bf65efb4fc10757fccdb03b02 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Jun 2013 22:21:45 +0800 Subject: [PATCH] Make auto updater work. --- src/atom-application.coffee | 16 ++++++++++++++-- src/main.coffee | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/atom-application.coffee b/src/atom-application.coffee index b0b2ff50b..160de8ef5 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -1,6 +1,7 @@ AtomWindow = require './atom-window' BrowserWindow = require 'browser-window' Menu = require 'menu' +autoUpdater = require 'auto-updater' crashReporter = require 'crash-reporter' app = require 'app' ipc = require 'ipc' @@ -106,13 +107,12 @@ class AtomApplication setupJavaScriptArguments: -> app.commandLine.appendSwitch 'js-flags', '--harmony_collections' - buildApplicationMenu: -> + buildApplicationMenu: (version, continueUpdate) -> menus = [] menus.push label: 'Atom' submenu: [ { label: 'About Atom', selector: 'orderFrontStandardAboutPanel:' } - { label: "Version #{@version}", enabled: false } { type: 'separator' } { label: 'Preferences...', accelerator: 'Command+,', click: => @openConfig() } { type: 'separator' } @@ -125,6 +125,14 @@ class AtomApplication { label: 'Quit', accelerator: 'Command+Q', click: -> app.quit() } ] + menus[0].submenu.splice 1, 0, + if version + label: "Update to #{version}" + click: continueUpdate + else + label: "Version #{@version}" + enabled: false + if @dev menus.push label: '\uD83D\uDC80' @@ -176,6 +184,10 @@ class AtomApplication event.preventDefault() @openPath filePath + autoUpdater.on 'ready-for-update-on-quit', (event, version, quitAndUpdate) => + event.preventDefault() + @buildApplicationMenu version, quitAndUpdate + ipc.on 'close-without-confirm', (processId, routingId) -> window = BrowserWindow.fromProcessIdAndRoutingId processId, routingId window.removeAllListeners 'close' diff --git a/src/main.coffee b/src/main.coffee index 9b0bc0ddb..8ee00fae3 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -1,10 +1,11 @@ +AtomApplication = require './atom-application' +autoUpdater = require 'auto-updater' delegate = require 'atom-delegate' app = require 'app' fs = require 'fs' path = require 'path' optimist = require 'optimist' nslog = require 'nslog' -AtomApplication = require './atom-application' _ = require 'underscore' console.log = (args...) -> @@ -20,6 +21,13 @@ delegate.browserMainParts.preMainMessageLoopRun = -> args.pathsToOpen.push(filePath) app.on 'open-file', addPathToOpen + + app.on 'will-finish-launching', -> + autoUpdater.setFeedUrl 'https://speakeasy.githubapp.com/apps/27/appcast.xml' + autoUpdater.setAutomaticallyChecksForUpdates true + autoUpdater.setAutomaticallyDownloadsUpdates true + autoUpdater.checkForUpdatesInBackground() + app.on 'finish-launching', -> app.removeListener 'open-file', addPathToOpen