diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index 948645778..269bc42c5 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -44,7 +44,7 @@ class AutoUpdateManager setupAutoUpdater: -> if process.platform is 'win32' - autoUpdater = require './auto-updater-win32' + autoUpdater = require './windows-updater-squirrel-adapter' else autoUpdater = require('electron').autoUpdater @@ -98,10 +98,23 @@ class AutoUpdateManager unless hidePopups autoUpdater.once 'update-not-available', @onUpdateNotAvailable autoUpdater.once 'error', @onUpdateError - autoUpdater.checkForUpdates() + + if process.platform is "win32" + # There's no separate "checking" stage on Windows. It also + # "installs" as soon as it downloads. You just need to restart to + # launch the updated app. + autoUpdater.downloadAndInstallUpdate() + else + autoUpdater.checkForUpdates() install: -> - autoUpdater.quitAndInstall() + if process.platform is "win32" + # On windows the update has already been "installed" and shortcuts + # already updated. You just need to restart the app to load the new + # version. + autoUpdater.restartN1() + else + autoUpdater.quitAndInstall() iconURL: -> url = path.join(process.resourcesPath, 'app', 'nylas.png') diff --git a/src/browser/main.coffee b/src/browser/main.coffee index bad37bb00..9d6341200 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -49,9 +49,9 @@ setupConfigDir = (args) -> handleStartupEventWithSquirrel = -> return false unless process.platform is 'win32' - SquirrelUpdate = require './squirrel-update' + WindowsUpdater = require './windows-updater' squirrelCommand = process.argv[1] - SquirrelUpdate.handleStartupEvent(app, squirrelCommand) + WindowsUpdater.handleStartupEvent(app, squirrelCommand) setupCompileCache = (configDirPath) -> compileCache = require('../compile-cache') diff --git a/src/browser/main.js b/src/browser/main.js index 266ef44f5..d7ceaa85b 100644 --- a/src/browser/main.js +++ b/src/browser/main.js @@ -4,18 +4,6 @@ global.shellStartTime = Date.now(); - process.on('uncaughtException', function(error) { - if (error == null) { - error = {}; - } - if (error.message != null) { - console.log(error.message); - } - if (error.stack != null) { - return console.log(error.stack); - } - }); - app = require('electron').app; fs = require('fs-plus'); @@ -65,13 +53,13 @@ }; handleStartupEventWithSquirrel = function() { - var SquirrelUpdate, squirrelCommand; + var WindowsUpdater, squirrelCommand; if (process.platform !== 'win32') { return false; } - SquirrelUpdate = require('./squirrel-update'); + WindowsUpdater = require('./windows-updater'); squirrelCommand = process.argv[1]; - return SquirrelUpdate.handleStartupEvent(app, squirrelCommand); + return WindowsUpdater.handleStartupEvent(app, squirrelCommand); }; setupCompileCache = function(configDirPath) { @@ -81,16 +69,19 @@ }; setupErrorLogger = function(args) { - var ErrorLogger; + var ErrorLogger, errorLogger; if (args == null) { args = {}; } ErrorLogger = require('../error-logger'); - return new ErrorLogger({ + errorLogger = new ErrorLogger({ inSpecMode: args.specMode, inDevMode: args.devMode, resourcePath: args.resourcePath }); + process.on('uncaughtException', errorLogger.reportError); + process.on('unhandledRejection', errorLogger.reportError); + return errorLogger; }; declareOptions = function(argv) { diff --git a/src/browser/auto-updater-win32.coffee b/src/browser/windows-updater-squirrel-adapter.coffee similarity index 54% rename from src/browser/auto-updater-win32.coffee rename to src/browser/windows-updater-squirrel-adapter.coffee index 08b1f35b1..f0dd4f87e 100644 --- a/src/browser/auto-updater-win32.coffee +++ b/src/browser/windows-updater-squirrel-adapter.coffee @@ -1,20 +1,20 @@ {EventEmitter} = require 'events' _ = require 'underscore' -SquirrelUpdate = require './squirrel-update' +WindowsUpdater = require './windows-updater' -class AutoUpdater +class WindowsUpdaterSquirrelAdapter _.extend @prototype, EventEmitter.prototype setFeedURL: (@updateUrl) -> - quitAndInstall: -> - if SquirrelUpdate.existsSync() - SquirrelUpdate.restartN1(require('app')) + restartN1: -> + if WindowsUpdater.existsSync() + WindowsUpdater.restartN1(require('app')) else - require('auto-updater').quitAndInstall() + NylasEnv.reportError(new Error("SquirrellUpdate does not exist")) downloadUpdate: (callback) -> - SquirrelUpdate.spawn ['--download', @updateUrl], (error, stdout) -> + WindowsUpdater.spawn ['--download', @updateUrl], (error, stdout) -> return callback(error) if error? try @@ -28,17 +28,17 @@ class AutoUpdater callback(null, update) installUpdate: (callback) -> - SquirrelUpdate.spawn(['--update', @updateUrl], callback) + WindowsUpdater.spawn(['--update', @updateUrl], callback) supportsUpdates: -> - SquirrelUpdate.existsSync() + WindowsUpdater.existsSync() - checkForUpdates: -> + downloadAndInstallUpdate: -> throw new Error('Update URL is not set') unless @updateUrl @emit 'checking-for-update' - unless SquirrelUpdate.existsSync() + unless WindowsUpdater.existsSync() @emit 'update-not-available' return @@ -54,8 +54,16 @@ class AutoUpdater @emit 'update-available' @installUpdate (error) => if error? - @emit 'update-not-available' + @emit 'error', error return + + # During this time, Windows Squirrel will invoke the Nylas.exe + # with a variety of flags as event hooks. + # + # See https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/custom-squirrel-events-non-cs.md + # + # See `handleStartupEventsWithSquirrel` in `src/browser/main.js` + @emit 'update-downloaded', {}, update.releaseNotes, update.version -module.exports = new AutoUpdater() +module.exports = new WindowsUpdaterSquirrelAdapter() diff --git a/src/browser/squirrel-update.coffee b/src/browser/windows-updater.coffee similarity index 96% rename from src/browser/squirrel-update.coffee rename to src/browser/windows-updater.coffee index e6986619a..a1aaa815e 100644 --- a/src/browser/squirrel-update.coffee +++ b/src/browser/windows-updater.coffee @@ -190,17 +190,20 @@ exports.handleStartupEvent = (app, squirrelCommand) -> switch squirrelCommand when '--squirrel-install' createShortcuts -> - addCommandsToPath -> + addCommandsToPath (error) -> + console.error(error) if error app.quit() true when '--squirrel-updated' updateShortcuts -> - addCommandsToPath -> + addCommandsToPath (error) -> + console.error(error) if error app.quit() true when '--squirrel-uninstall' removeShortcuts -> - removeCommandsFromPath -> + removeCommandsFromPath (error) -> + console.error(error) if error app.quit() true when '--squirrel-obsolete'