Convert all source files to JavaScript

This commit is contained in:
Kevin Sawicki 2016-01-11 18:40:23 -08:00
parent 403870a27e
commit 1f9691ae13
144 changed files with 11211 additions and 7301 deletions

View file

@ -1,6 +0,0 @@
{EventEmitter} = require 'events'
{autoUpdater} = process.atomBinding 'auto_updater'
autoUpdater.__proto__ = EventEmitter.prototype
module.exports = autoUpdater

View file

@ -0,0 +1,9 @@
var EventEmitter, autoUpdater;
EventEmitter = require('events').EventEmitter;
autoUpdater = process.atomBinding('auto_updater').autoUpdater;
autoUpdater.__proto__ = EventEmitter.prototype;
module.exports = autoUpdater;

View file

@ -1,44 +0,0 @@
{app} = require 'electron'
{EventEmitter} = require 'events'
url = require 'url'
squirrelUpdate = require './squirrel-update-win'
class AutoUpdater extends EventEmitter
quitAndInstall: ->
squirrelUpdate.processStart()
app.quit()
setFeedURL: (updateURL) ->
@updateURL = updateURL
checkForUpdates: ->
return @emitError 'Update URL is not set' unless @updateURL
return @emitError 'Can not find Squirrel' unless squirrelUpdate.supported()
@emit 'checking-for-update'
squirrelUpdate.download @updateURL, (error, update) =>
return @emitError error if error?
return @emit 'update-not-available' unless update?
@emit 'update-available'
squirrelUpdate.update @updateURL, (error) =>
return @emitError error if error?
{releaseNotes, version} = update
### Following information is not available on Windows, so fake them. ###
date = new Date
url = @updateURL
@emit 'update-downloaded', {}, releaseNotes, version, date, url, => @quitAndInstall()
###
Private: Emit both error object and message, this is to keep compatibility
with Old APIs.
###
emitError: (message) ->
@emit 'error', new Error(message), message
module.exports = new AutoUpdater

View file

@ -0,0 +1,78 @@
var AutoUpdater, EventEmitter, app, squirrelUpdate, url,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
app = require('electron').app;
EventEmitter = require('events').EventEmitter;
url = require('url');
squirrelUpdate = require('./squirrel-update-win');
AutoUpdater = (function(superClass) {
extend(AutoUpdater, superClass);
function AutoUpdater() {
return AutoUpdater.__super__.constructor.apply(this, arguments);
}
AutoUpdater.prototype.quitAndInstall = function() {
squirrelUpdate.processStart();
return app.quit();
};
AutoUpdater.prototype.setFeedURL = function(updateURL) {
return this.updateURL = updateURL;
};
AutoUpdater.prototype.checkForUpdates = function() {
if (!this.updateURL) {
return this.emitError('Update URL is not set');
}
if (!squirrelUpdate.supported()) {
return this.emitError('Can not find Squirrel');
}
this.emit('checking-for-update');
return squirrelUpdate.download(this.updateURL, (function(_this) {
return function(error, update) {
if (error != null) {
return _this.emitError(error);
}
if (update == null) {
return _this.emit('update-not-available');
}
_this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(error) {
var date, releaseNotes, version;
if (error != null) {
return _this.emitError(error);
}
releaseNotes = update.releaseNotes, version = update.version;
/* Following information is not available on Windows, so fake them. */
date = new Date;
url = _this.updateURL;
return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, function() {
return _this.quitAndInstall();
});
});
};
})(this));
};
/*
Private: Emit both error object and message, this is to keep compatibility
with Old APIs.
*/
AutoUpdater.prototype.emitError = function(message) {
return this.emit('error', new Error(message), message);
};
return AutoUpdater;
})(EventEmitter);
module.exports = new AutoUpdater;

View file

@ -1,71 +0,0 @@
fs = require 'fs'
path = require 'path'
{spawn} = require 'child_process'
### i.e. my-app/app-0.1.13/ ###
appFolder = path.dirname process.execPath
### i.e. my-app/Update.exe ###
updateExe = path.resolve appFolder, '..', 'Update.exe'
exeName = path.basename process.execPath
###
Spawn a command and invoke the callback when it completes with an error
and the output from standard out.
###
spawnUpdate = (args, detached, callback) ->
try
spawnedProcess = spawn updateExe, args, {detached}
catch error
### Shouldn't happen, but still guard it. ###
process.nextTick -> callback error
return
stdout = ''
stderr = ''
spawnedProcess.stdout.on 'data', (data) -> stdout += data
spawnedProcess.stderr.on 'data', (data) -> stderr += data
errorEmitted = false
spawnedProcess.on 'error', (error) ->
errorEmitted = true
callback error
spawnedProcess.on 'exit', (code, signal) ->
### We may have already emitted an error. ###
return if errorEmitted
### Process terminated with error. ###
if code isnt 0
return callback "Command failed: #{signal ? code}\n#{stderr}"
### Success. ###
callback null, stdout
### Start an instance of the installed app. ###
exports.processStart = (callback) ->
spawnUpdate ['--processStart', exeName], true, ->
### Download the releases specified by the URL and write new results to stdout. ###
exports.download = (updateURL, callback) ->
spawnUpdate ['--download', updateURL], false, (error, stdout) ->
return callback(error) if error?
try
### Last line of output is the JSON details about the releases ###
json = stdout.trim().split('\n').pop()
update = JSON.parse(json)?.releasesToApply?.pop?()
catch
return callback "Invalid result:\n#{stdout}"
callback null, update
### Update the application to the latest remote version specified by URL. ###
exports.update = (updateURL, callback) ->
spawnUpdate ['--update', updateURL], false, callback
### Is the Update.exe installed with the current application? ###
exports.supported = ->
try
fs.accessSync updateExe, fs.R_OK
return true
catch
return false

View file

@ -0,0 +1,118 @@
var appFolder, exeName, fs, path, spawn, spawnUpdate, updateExe;
fs = require('fs');
path = require('path');
spawn = require('child_process').spawn;
/* i.e. my-app/app-0.1.13/ */
appFolder = path.dirname(process.execPath);
/* i.e. my-app/Update.exe */
updateExe = path.resolve(appFolder, '..', 'Update.exe');
exeName = path.basename(process.execPath);
/*
Spawn a command and invoke the callback when it completes with an error
and the output from standard out.
*/
spawnUpdate = function(args, detached, callback) {
var error, error1, errorEmitted, spawnedProcess, stderr, stdout;
try {
spawnedProcess = spawn(updateExe, args, {
detached: detached
});
} catch (error1) {
error = error1;
/* Shouldn't happen, but still guard it. */
process.nextTick(function() {
return callback(error);
});
return;
}
stdout = '';
stderr = '';
spawnedProcess.stdout.on('data', function(data) {
return stdout += data;
});
spawnedProcess.stderr.on('data', function(data) {
return stderr += data;
});
errorEmitted = false;
spawnedProcess.on('error', function(error) {
errorEmitted = true;
return callback(error);
});
return spawnedProcess.on('exit', function(code, signal) {
/* We may have already emitted an error. */
if (errorEmitted) {
return;
}
/* Process terminated with error. */
if (code !== 0) {
return callback("Command failed: " + (signal != null ? signal : code) + "\n" + stderr);
}
/* Success. */
return callback(null, stdout);
});
};
/* Start an instance of the installed app. */
exports.processStart = function(callback) {
return spawnUpdate(['--processStart', exeName], true, function() {});
};
/* Download the releases specified by the URL and write new results to stdout. */
exports.download = function(updateURL, callback) {
return spawnUpdate(['--download', updateURL], false, function(error, stdout) {
var error1, json, ref, ref1, update;
if (error != null) {
return callback(error);
}
try {
/* Last line of output is the JSON details about the releases */
json = stdout.trim().split('\n').pop();
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === "function" ? ref1.pop() : void 0 : void 0 : void 0;
} catch (error1) {
return callback("Invalid result:\n" + stdout);
}
return callback(null, update);
});
};
/* Update the application to the latest remote version specified by URL. */
exports.update = function(updateURL, callback) {
return spawnUpdate(['--update', updateURL], false, callback);
};
/* Is the Update.exe installed with the current application? */
exports.supported = function() {
var error1;
try {
fs.accessSync(updateExe, fs.R_OK);
return true;
} catch (error1) {
return false;
}
};