Rename windows updater files

This commit is contained in:
Evan Morikawa 2016-02-09 15:47:52 -08:00
parent c22cf7ef1b
commit 42854bac23
5 changed files with 53 additions and 38 deletions

View file

@ -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')

View file

@ -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')

View file

@ -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) {

View file

@ -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()

View file

@ -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'