From 63d9edcc402d740466b404703a15ec930ed694ac Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 15 Oct 2014 10:54:02 -0700 Subject: [PATCH] First hack at a Win32 auto-updater --- src/browser/auto-updater-win32.coffee | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/browser/auto-updater-win32.coffee b/src/browser/auto-updater-win32.coffee index 7de64f21e..4959125b8 100644 --- a/src/browser/auto-updater-win32.coffee +++ b/src/browser/auto-updater-win32.coffee @@ -1,6 +1,7 @@ _ = require 'underscore-plus' path = require 'path' fs = require 'fs' +shellAutoUpdater = require 'auto-updater' {EventEmitter} = require 'events' {BufferedProcess} = require 'atom' @@ -13,7 +14,26 @@ class AutoUpdater @updateUrl = url quitAndInstall: -> - console.log 'quitAndInstall' + updateDotExe = path.join(path.dirName(process.execPath), '..', 'update.exe') + unless fs.existsSync(updateDotExe) + console.log 'Running developer or Chocolatey version of Atom, skipping' + return + + updateOutput = "" + ps = new BufferedProcess + command: updateDotExe, + args: ['--update', @updateUrl] + stdout: (o) -> updateOutput += o + exit: (exitCode) -> + unless exitCode is 0 + console.log 'Failed to update: ' + exitCode + ' - ' + updateOutput + return + + dontcare = new BufferedProcess + command: updateDotExe, + args: ['--processStart', 'atom.exe'] + + shellAutoUpdater.quitAndInstall() checkForUpdates: -> throw new Error("Update URL is not set") unless @updateUrl @@ -35,7 +55,7 @@ class AutoUpdater stdout: (output) -> updateOutput += output exit: (exitCode) -> unless exitCode is 0 - console.log 'Failed to update: ' + exitCode + ' - ' + updateJson + console.log 'Failed to update: ' + exitCode + ' - ' + updateOutput emit 'update-not-available' return @@ -57,7 +77,14 @@ class AutoUpdater emit 'update-not-available' return + latest = updateInfo.releasesToApply[updateInfo.ReleasesToApply.length-1] + # We don't have separate "check for update" and "download" in Squirrel, # we always just download emit 'update-available' - emit 'update-downloaded', {} + emit 'update-downloaded', + releaseNotes: latest.releaseNotes, + releaseName: "Atom " + latest.version, + releaseDate: "", # NB: Squirrel doesn't provide this :( + updateUrl: "https://atom.io", + quitAndUpdate: @quitAndInstall