Print log to file as well

This commit is contained in:
Atlante45 2016-10-21 17:04:37 -07:00
parent b5881146df
commit b2e68a1075
6 changed files with 78 additions and 71 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "hf-console", "name": "HighFidelitySandbox",
"description": "High Fidelity Console", "description": "High Fidelity Sandbox",
"author": "High Fidelity", "author": "High Fidelity",
"license": "Apache-2.0", "license": "Apache-2.0",
"version": "1.0.0", "version": "1.0.0",
@ -33,6 +33,7 @@
"request": "^2.67.0", "request": "^2.67.0",
"request-progress": "1.0.2", "request-progress": "1.0.2",
"tar-fs": "^1.12.0", "tar-fs": "^1.12.0",
"yargs": "^3.30.0" "yargs": "^3.30.0",
"electron-log": "1.1.1"
} }
} }

View file

@ -5,6 +5,8 @@ const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; const BrowserWindow = electron.BrowserWindow;
const nativeImage = electron.nativeImage; const nativeImage = electron.nativeImage;
const log = require('electron-log');
const notifier = require('node-notifier'); const notifier = require('node-notifier');
const util = require('util'); const util = require('util');
const dialog = electron.dialog; const dialog = electron.dialog;
@ -64,7 +66,7 @@ function getBuildInfo() {
var buildInfo = DEFAULT_BUILD_INFO; var buildInfo = DEFAULT_BUILD_INFO;
if (buildInfoPath) { if (buildInfoPath) {
console.log('Build info path:', buildInfoPath); log.debug('Build info path:', buildInfoPath);
try { try {
buildInfo = JSON.parse(fs.readFileSync(buildInfoPath)); buildInfo = JSON.parse(fs.readFileSync(buildInfoPath));
} catch (e) { } catch (e) {
@ -77,7 +79,7 @@ function getBuildInfo() {
const buildInfo = getBuildInfo(); const buildInfo = getBuildInfo();
console.log("build info", buildInfo); log.debug("build info", buildInfo);
function getRootHifiDataDirectory() { function getRootHifiDataDirectory() {
var organization = "High Fidelity"; var organization = "High Fidelity";
@ -105,7 +107,7 @@ function getApplicationDataDirectory() {
return path.join(getRootHifiDataDirectory(), '/Server Console'); return path.join(getRootHifiDataDirectory(), '/Server Console');
} }
console.log("Root hifi directory is: ", getRootHifiDataDirectory()); log.debug("Root hifi directory is: ", getRootHifiDataDirectory());
const ipcMain = electron.ipcMain; const ipcMain = electron.ipcMain;
@ -167,36 +169,36 @@ function shutdownCallback(idx) {
} }
function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) { function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) {
console.log("Deleting old log files in " + directoryPath); log.debug("Deleting old log files in " + directoryPath);
var filenames = []; var filenames = [];
try { try {
filenames = fs.readdirSync(directoryPath); filenames = fs.readdirSync(directoryPath);
} catch (e) { } catch (e) {
console.warn("Error reading contents of log file directory", e); log.warn("Error reading contents of log file directory", e);
return; return;
} }
for (const filename of filenames) { for (const filename of filenames) {
console.log("Checking", filename); log.debug("Checking", filename);
const absolutePath = path.join(directoryPath, filename); const absolutePath = path.join(directoryPath, filename);
var stat = null; var stat = null;
try { try {
stat = fs.statSync(absolutePath); stat = fs.statSync(absolutePath);
} catch (e) { } catch (e) {
console.log("Error stat'ing file", absolutePath, e); log.debug("Error stat'ing file", absolutePath, e);
continue; continue;
} }
const curTime = Date.now(); const curTime = Date.now();
if (stat.isFile() && filename.search(filenameRegex) >= 0) { if (stat.isFile() && filename.search(filenameRegex) >= 0) {
const ageInSeconds = (curTime - stat.mtime.getTime()) / 1000.0; const ageInSeconds = (curTime - stat.mtime.getTime()) / 1000.0;
if (ageInSeconds >= maxAgeInSeconds) { if (ageInSeconds >= maxAgeInSeconds) {
console.log("\tDeleting:", filename, ageInSeconds); log.debug("\tDeleting:", filename, ageInSeconds);
try { try {
fs.unlinkSync(absolutePath); fs.unlinkSync(absolutePath);
} catch (e) { } catch (e) {
if (e.code != 'EBUSY') { if (e.code != 'EBUSY') {
console.warn("\tError deleting:", e); log.warn("\tError deleting:", e);
} }
} }
} }
@ -206,8 +208,8 @@ function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) {
var logPath = path.join(getApplicationDataDirectory(), '/logs'); var logPath = path.join(getApplicationDataDirectory(), '/logs');
console.log("Log directory:", logPath); log.debug("Log directory:", logPath);
console.log("Data directory:", getRootHifiDataDirectory()); log.debug("Data directory:", getRootHifiDataDirectory());
const configPath = path.join(getApplicationDataDirectory(), 'config.json'); const configPath = path.join(getApplicationDataDirectory(), 'config.json');
var userConfig = new Config(); var userConfig = new Config();
@ -215,8 +217,8 @@ userConfig.load(configPath);
// print out uncaught exceptions in the console // print out uncaught exceptions in the console
process.on('uncaughtException', function(err) { process.on('uncaughtException', function(err) {
console.error(err); log.error(err);
console.error(err.stack); log.error(err.stack);
}); });
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
@ -225,7 +227,7 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
}); });
if (shouldQuit) { if (shouldQuit) {
console.warn("Another instance of the Sandbox is already running - this instance will quit."); log.warn("Another instance of the Sandbox is already running - this instance will quit.");
app.quit(); app.quit();
return; return;
} }
@ -506,7 +508,7 @@ const httpStatusPort = 60332;
function backupResourceDirectories(folder) { function backupResourceDirectories(folder) {
try { try {
fs.mkdirSync(folder); fs.mkdirSync(folder);
console.log("Created directory " + folder); log.debug("Created directory " + folder);
var dsBackup = path.join(folder, '/domain-server'); var dsBackup = path.join(folder, '/domain-server');
var acBackup = path.join(folder, '/assignment-client'); var acBackup = path.join(folder, '/assignment-client');
@ -519,7 +521,7 @@ function backupResourceDirectories(folder) {
return true; return true;
} catch (e) { } catch (e) {
console.log(e); log.debug(e);
return false; return false;
} }
} }
@ -541,7 +543,7 @@ function openBackupInstructions(folder) {
window.setSize(obj.width, obj.height); window.setSize(obj.width, obj.height);
}); });
electron.ipcMain.on('ready', function() { electron.ipcMain.on('ready', function() {
console.log("got ready"); log.debug("got ready");
window.webContents.send('update', folder); window.webContents.send('update', folder);
}); });
} }
@ -575,9 +577,9 @@ function checkNewContent() {
var wantDebug = false; var wantDebug = false;
if (wantDebug) { if (wantDebug) {
console.log('Last Modified: ' + response.headers['last-modified']); log.debug('Last Modified: ' + response.headers['last-modified']);
console.log(localContent + " " + remoteContent + " " + shouldUpdate + " " + new Date()); log.debug(localContent + " " + remoteContent + " " + shouldUpdate + " " + new Date());
console.log("Remote content is " + (shouldUpdate ? "newer" : "older") + " that local content."); log.debug("Remote content is " + (shouldUpdate ? "newer" : "older") + " that local content.");
} }
if (shouldUpdate) { if (shouldUpdate) {
@ -619,46 +621,46 @@ function maybeInstallDefaultContentSet(onComplete) {
// Check for existing data // Check for existing data
const acResourceDirectory = getAssignmentClientResourcesDirectory(); const acResourceDirectory = getAssignmentClientResourcesDirectory();
console.log("Checking for existence of " + acResourceDirectory); log.debug("Checking for existence of " + acResourceDirectory);
var userHasExistingACData = true; var userHasExistingACData = true;
try { try {
fs.accessSync(acResourceDirectory); fs.accessSync(acResourceDirectory);
console.log("Found directory " + acResourceDirectory); log.debug("Found directory " + acResourceDirectory);
} catch (e) { } catch (e) {
console.log(e); log.debug(e);
userHasExistingACData = false; userHasExistingACData = false;
} }
const dsResourceDirectory = getDomainServerClientResourcesDirectory(); const dsResourceDirectory = getDomainServerClientResourcesDirectory();
console.log("checking for existence of " + dsResourceDirectory); log.debug("checking for existence of " + dsResourceDirectory);
var userHasExistingDSData = true; var userHasExistingDSData = true;
try { try {
fs.accessSync(dsResourceDirectory); fs.accessSync(dsResourceDirectory);
console.log("Found directory " + dsResourceDirectory); log.debug("Found directory " + dsResourceDirectory);
} catch (e) { } catch (e) {
console.log(e); log.debug(e);
userHasExistingDSData = false; userHasExistingDSData = false;
} }
if (userHasExistingACData || userHasExistingDSData) { if (userHasExistingACData || userHasExistingDSData) {
console.log("User has existing data, suppressing downloader"); log.debug("User has existing data, suppressing downloader");
onComplete(); onComplete();
checkNewContent(); checkNewContent();
return; return;
} }
console.log("Found contentPath:" + argv.contentPath); log.debug("Found contentPath:" + argv.contentPath);
if (argv.contentPath) { if (argv.contentPath) {
fs.copy(argv.contentPath, getRootHifiDataDirectory(), function (err) { fs.copy(argv.contentPath, getRootHifiDataDirectory(), function (err) {
if (err) { if (err) {
console.log('Could not copy home content: ' + err); log.debug('Could not copy home content: ' + err);
return console.error(err) return log.error(err)
} }
console.log('Copied home content over to: ' + getRootHifiDataDirectory()); log.debug('Copied home content over to: ' + getRootHifiDataDirectory());
userConfig.set('homeContentLastModified', new Date()); userConfig.set('homeContentLastModified', new Date());
onComplete(); onComplete();
}); });
@ -685,11 +687,11 @@ function maybeInstallDefaultContentSet(onComplete) {
window.on('closed', onComplete); window.on('closed', onComplete);
electron.ipcMain.on('ready', function() { electron.ipcMain.on('ready', function() {
console.log("got ready"); log.debug("got ready");
var currentState = ''; var currentState = '';
function sendStateUpdate(state, args) { function sendStateUpdate(state, args) {
// console.log(state, window, args); // log.debug(state, window, args);
window.webContents.send('update', { state: state, args: args }); window.webContents.send('update', { state: state, args: args });
currentState = state; currentState = state;
} }
@ -723,10 +725,10 @@ function maybeInstallDefaultContentSet(onComplete) {
}); });
function extractError(err) { function extractError(err) {
console.log("Aborting request because gunzip/untar failed"); log.debug("Aborting request because gunzip/untar failed");
aborted = true; aborted = true;
req.abort(); req.abort();
console.log("ERROR" + err); log.debug("ERROR" + err);
sendStateUpdate('error', { sendStateUpdate('error', {
message: "Error installing resources." message: "Error installing resources."
@ -738,7 +740,7 @@ function maybeInstallDefaultContentSet(onComplete) {
req.pipe(gunzip).pipe(tar.extract(getRootHifiDataDirectory())).on('error', extractError).on('finish', function(){ req.pipe(gunzip).pipe(tar.extract(getRootHifiDataDirectory())).on('error', extractError).on('finish', function(){
// response and decompression complete, return // response and decompression complete, return
console.log("Finished unarchiving home content set"); log.debug("Finished unarchiving home content set");
userConfig.set('homeContentLastModified', new Date()); userConfig.set('homeContentLastModified', new Date());
sendStateUpdate('complete'); sendStateUpdate('complete');
}); });
@ -824,7 +826,7 @@ function onContentLoaded() {
} }
}); });
notifier.on('click', function(notifierObject, options) { notifier.on('click', function(notifierObject, options) {
console.log("Got click", options.url); log.debug("Got click", options.url);
shell.openExternal(options.url); shell.openExternal(options.url);
}); });
} }
@ -855,7 +857,7 @@ function onContentLoaded() {
// shutting down. The interface app will regularly update a running state file which we will check. // shutting down. The interface app will regularly update a running state file which we will check.
// If the file doesn't exist or stops updating for a significant amount of time, we will shut down. // If the file doesn't exist or stops updating for a significant amount of time, we will shut down.
if (argv.shutdownWatcher) { if (argv.shutdownWatcher) {
console.log("Shutdown watcher requested... argv.shutdownWatcher:", argv.shutdownWatcher); log.debug("Shutdown watcher requested... argv.shutdownWatcher:", argv.shutdownWatcher);
var MAX_TIME_SINCE_EDIT = 5000; // 5 seconds between updates var MAX_TIME_SINCE_EDIT = 5000; // 5 seconds between updates
var firstAttemptToCheck = new Date().getTime(); var firstAttemptToCheck = new Date().getTime();
var shutdownWatchInterval = setInterval(function(){ var shutdownWatchInterval = setInterval(function(){
@ -863,14 +865,14 @@ function onContentLoaded() {
if (err) { if (err) {
var sinceFirstCheck = new Date().getTime() - firstAttemptToCheck; var sinceFirstCheck = new Date().getTime() - firstAttemptToCheck;
if (sinceFirstCheck > MAX_TIME_SINCE_EDIT) { if (sinceFirstCheck > MAX_TIME_SINCE_EDIT) {
console.log("Running state file is missing, assume interface has shutdown... shutting down snadbox."); log.debug("Running state file is missing, assume interface has shutdown... shutting down snadbox.");
forcedShutdown(); forcedShutdown();
clearTimeout(shutdownWatchInterval); clearTimeout(shutdownWatchInterval);
} }
} else { } else {
var sinceEdit = new Date().getTime() - stats.mtime.getTime(); var sinceEdit = new Date().getTime() - stats.mtime.getTime();
if (sinceEdit > MAX_TIME_SINCE_EDIT) { if (sinceEdit > MAX_TIME_SINCE_EDIT) {
console.log("Running state of interface hasn't updated in MAX time... shutting down."); log.debug("Running state of interface hasn't updated in MAX time... shutting down.");
forcedShutdown(); forcedShutdown();
clearTimeout(shutdownWatchInterval); clearTimeout(shutdownWatchInterval);
} }

View file

@ -1,5 +1,6 @@
var fs = require('fs'); var fs = require('fs');
var extend = require('extend'); var extend = require('extend');
var log = require('electron-log');
function Config() { function Config() {
this.data = {}; this.data = {};
@ -10,7 +11,7 @@ Config.prototype = {
try { try {
rawData = fs.readFileSync(filePath); rawData = fs.readFileSync(filePath);
} catch(e) { } catch(e) {
console.log("Config file not found"); log.debug("Config file not found");
} }
var configData = {}; var configData = {};
@ -21,7 +22,7 @@ Config.prototype = {
configData = {}; configData = {};
} }
} catch(e) { } catch(e) {
console.error("Error parsing config file", filePath) log.error("Error parsing config file", filePath)
} }
this.data = {}; this.data = {};
@ -37,7 +38,7 @@ Config.prototype = {
return defaultValue; return defaultValue;
}, },
set: function(key, value) { set: function(key, value) {
console.log("Setting", key, "to", value); log.debug("Setting", key, "to", value);
this.data[key] = value; this.data[key] = value;
} }
}; };

View file

@ -8,6 +8,7 @@ const childProcess = require('child_process');
const fs = require('fs-extra'); const fs = require('fs-extra');
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
const log = require('electron-log');
const ProcessGroupStates = { const ProcessGroupStates = {
STOPPED: 'stopped', STOPPED: 'stopped',
@ -43,7 +44,7 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
}, },
start: function() { start: function() {
if (this.state != ProcessGroupStates.STOPPED) { if (this.state != ProcessGroupStates.STOPPED) {
console.warn("Can't start process group that is not stopped."); log.warn("Can't start process group that is not stopped.");
return; return;
} }
@ -56,7 +57,7 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
}, },
stop: function() { stop: function() {
if (this.state != ProcessGroupStates.STARTED) { if (this.state != ProcessGroupStates.STARTED) {
console.warn("Can't stop process group that is not started."); log.warn("Can't stop process group that is not started.");
return; return;
} }
for (let process of this.processes) { for (let process of this.processes) {
@ -120,10 +121,10 @@ util.inherits(Process, events.EventEmitter);
Process.prototype = extend(Process.prototype, { Process.prototype = extend(Process.prototype, {
start: function() { start: function() {
if (this.state != ProcessStates.STOPPED) { if (this.state != ProcessStates.STOPPED) {
console.warn("Can't start process that is not stopped."); log.warn("Can't start process that is not stopped.");
return; return;
} }
console.log("Starting " + this.command + " " + this.commandArgs.join(' ')); log.debug("Starting " + this.command + " " + this.commandArgs.join(' '));
var logStdout = 'ignore', var logStdout = 'ignore',
logStderr = 'ignore'; logStderr = 'ignore';
@ -138,7 +139,7 @@ Process.prototype = extend(Process.prototype, {
if (e.code == 'EEXIST') { if (e.code == 'EEXIST') {
logDirectoryCreated = true; logDirectoryCreated = true;
} else { } else {
console.error("Error creating log directory"); log.error("Error creating log directory");
} }
} }
@ -151,13 +152,13 @@ Process.prototype = extend(Process.prototype, {
try { try {
logStdout = fs.openSync(tmpLogStdout, 'ax'); logStdout = fs.openSync(tmpLogStdout, 'ax');
} catch(e) { } catch(e) {
console.log("Error creating stdout log file", e); log.debug("Error creating stdout log file", e);
logStdout = 'ignore'; logStdout = 'ignore';
} }
try { try {
logStderr = fs.openSync(tmpLogStderr, 'ax'); logStderr = fs.openSync(tmpLogStderr, 'ax');
} catch(e) { } catch(e) {
console.log("Error creating stderr log file", e); log.debug("Error creating stderr log file", e);
logStderr = 'ignore'; logStderr = 'ignore';
} }
} }
@ -169,7 +170,7 @@ Process.prototype = extend(Process.prototype, {
stdio: ['ignore', logStdout, logStderr] stdio: ['ignore', logStdout, logStderr]
}); });
} catch (e) { } catch (e) {
console.log("Got error starting child process for " + this.name, e); log.debug("Got error starting child process for " + this.name, e);
this.child = null; this.child = null;
this.updateState(ProcessStates.STOPPED); this.updateState(ProcessStates.STOPPED);
return; return;
@ -179,7 +180,7 @@ Process.prototype = extend(Process.prototype, {
var pidLogStdout = path.resolve(this.logDirectory + '/' + this.name + "-" + this.child.pid + "-" + time + "-stdout.txt"); var pidLogStdout = path.resolve(this.logDirectory + '/' + this.name + "-" + this.child.pid + "-" + time + "-stdout.txt");
fs.rename(tmpLogStdout, pidLogStdout, function(e) { fs.rename(tmpLogStdout, pidLogStdout, function(e) {
if (e !== null) { if (e !== null) {
console.log("Error renaming log file from " + tmpLogStdout + " to " + pidLogStdout, e); log.debug("Error renaming log file from " + tmpLogStdout + " to " + pidLogStdout, e);
} }
}); });
this.logStdout = pidLogStdout; this.logStdout = pidLogStdout;
@ -190,7 +191,7 @@ Process.prototype = extend(Process.prototype, {
var pidLogStderr = path.resolve(this.logDirectory + '/' + this.name + "-" + this.child.pid + "-" + time + "-stderr.txt"); var pidLogStderr = path.resolve(this.logDirectory + '/' + this.name + "-" + this.child.pid + "-" + time + "-stderr.txt");
fs.rename(tmpLogStderr, pidLogStderr, function(e) { fs.rename(tmpLogStderr, pidLogStderr, function(e) {
if (e !== null) { if (e !== null) {
console.log("Error renaming log file from " + tmpLogStdout + " to " + pidLogStdout, e); log.debug("Error renaming log file from " + tmpLogStdout + " to " + pidLogStdout, e);
} }
}); });
this.logStderr = pidLogStderr; this.logStderr = pidLogStderr;
@ -201,13 +202,13 @@ Process.prototype = extend(Process.prototype, {
this.child.on('error', this.onChildStartError.bind(this)); this.child.on('error', this.onChildStartError.bind(this));
this.child.on('close', this.onChildClose.bind(this)); this.child.on('close', this.onChildClose.bind(this));
console.log("Child process started"); log.debug("Child process started");
this.updateState(ProcessStates.STARTED); this.updateState(ProcessStates.STARTED);
this.emit('logs-updated'); this.emit('logs-updated');
}, },
stop: function(force) { stop: function(force) {
if (this.state == ProcessStates.STOPPED) { if (this.state == ProcessStates.STOPPED) {
console.warn("Can't stop process that is not started or stopping."); log.warn("Can't stop process that is not started or stopping.");
return; return;
} }
if (os.type() == "Windows_NT") { if (os.type() == "Windows_NT") {
@ -217,7 +218,7 @@ Process.prototype = extend(Process.prototype, {
} }
childProcess.exec(command, {}, function(error) { childProcess.exec(command, {}, function(error) {
if (error) { if (error) {
console.error('Error executing taskkill:', error); log.error('Error executing taskkill:', error);
} }
}); });
} else { } else {
@ -225,12 +226,12 @@ Process.prototype = extend(Process.prototype, {
this.child.kill(signal); this.child.kill(signal);
} }
console.log("Stopping child process:", this.child.pid, this.name); log.debug("Stopping child process:", this.child.pid, this.name);
if (!force) { if (!force) {
this.stoppingTimeoutID = setTimeout(function() { this.stoppingTimeoutID = setTimeout(function() {
if (this.state == ProcessStates.STOPPING) { if (this.state == ProcessStates.STOPPING) {
console.log("Force killling", this.name, this.child.pid); log.debug("Force killling", this.name, this.child.pid);
this.stop(true); this.stop(true);
} }
}.bind(this), 2500); }.bind(this), 2500);
@ -257,11 +258,11 @@ Process.prototype = extend(Process.prototype, {
// Events // Events
onChildStartError: function(error) { onChildStartError: function(error) {
console.log("Child process error ", error); log.debug("Child process error ", error);
this.updateState(ProcessStates.STOPPED); this.updateState(ProcessStates.STOPPED);
}, },
onChildClose: function(code) { onChildClose: function(code) {
console.log("Child process closed with code ", code, this.name); log.debug("Child process closed with code ", code, this.name);
if (this.stoppingTimeoutID) { if (this.stoppingTimeoutID) {
clearTimeout(this.stoppingTimeoutID); clearTimeout(this.stoppingTimeoutID);
this.stoppingTimeoutID = null; this.stoppingTimeoutID = null;
@ -332,7 +333,7 @@ ACMonitorProcess.prototype = extend(ACMonitorProcess.prototype, {
this.pendingRequest = null; this.pendingRequest = null;
if (error) { if (error) {
console.error('ERROR Getting AC Monitor status', error); log.error('ERROR Getting AC Monitor status', error);
} else { } else {
this.childServers = body.servers; this.childServers = body.servers;
} }

View file

@ -4,6 +4,7 @@ const util = require('util');
const events = require('events'); const events = require('events');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const os = require('os'); const os = require('os');
const log = require('electron-log');
const platform = os.type() == 'Windows_NT' ? 'windows' : 'mac'; const platform = os.type() == 'Windows_NT' ? 'windows' : 'mac';
@ -11,7 +12,7 @@ const BUILDS_URL = 'https://highfidelity.com/builds.xml';
function UpdateChecker(currentVersion, checkForUpdatesEveryXSeconds) { function UpdateChecker(currentVersion, checkForUpdatesEveryXSeconds) {
this.currentVersion = currentVersion; this.currentVersion = currentVersion;
console.log('cur', currentVersion); log.debug('cur', currentVersion);
setInterval(this.checkForUpdates.bind(this), checkForUpdatesEveryXSeconds * 1000); setInterval(this.checkForUpdates.bind(this), checkForUpdatesEveryXSeconds * 1000);
this.checkForUpdates(); this.checkForUpdates();
@ -19,10 +20,10 @@ function UpdateChecker(currentVersion, checkForUpdatesEveryXSeconds) {
util.inherits(UpdateChecker, events.EventEmitter); util.inherits(UpdateChecker, events.EventEmitter);
UpdateChecker.prototype = extend(UpdateChecker.prototype, { UpdateChecker.prototype = extend(UpdateChecker.prototype, {
checkForUpdates: function() { checkForUpdates: function() {
console.log("Checking for updates"); log.debug("Checking for updates");
request(BUILDS_URL, (error, response, body) => { request(BUILDS_URL, (error, response, body) => {
if (error) { if (error) {
console.log("Error", error); log.debug("Error", error);
return; return;
} }
if (response.statusCode == 200) { if (response.statusCode == 200) {
@ -30,13 +31,13 @@ UpdateChecker.prototype = extend(UpdateChecker.prototype, {
var $ = cheerio.load(body, { xmlMode: true }); var $ = cheerio.load(body, { xmlMode: true });
const latestBuild = $('project[name="interface"] platform[name="' + platform + '"]').children().first(); const latestBuild = $('project[name="interface"] platform[name="' + platform + '"]').children().first();
const latestVersion = parseInt(latestBuild.find('version').text()); const latestVersion = parseInt(latestBuild.find('version').text());
console.log("Latest version is:", latestVersion, this.currentVersion); log.debug("Latest version is:", latestVersion, this.currentVersion);
if (latestVersion > this.currentVersion) { if (latestVersion > this.currentVersion) {
const url = latestBuild.find('url').text(); const url = latestBuild.find('url').text();
this.emit('update-available', latestVersion, url); this.emit('update-available', latestVersion, url);
} }
} catch (e) { } catch (e) {
console.warn("Error when checking for updates", e); log.warn("Error when checking for updates", e);
} }
} }
}); });

View file

@ -1,5 +1,6 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var log = require('electron-log');
function platformExtension(name) { function platformExtension(name) {
if (name == "Interface") { if (name == "Interface") {
@ -72,11 +73,11 @@ exports.discoveredPath = function (name, binaryType, releaseType) {
var extension = platformExtension(name); var extension = platformExtension(name);
if (stats.isFile() || (stats.isDirectory() && extension == ".app")) { if (stats.isFile() || (stats.isDirectory() && extension == ".app")) {
console.log("Found " + name + " at " + testPath); log.debug("Found " + name + " at " + testPath);
return testPath; return testPath;
} }
} catch (e) { } catch (e) {
console.log("Executable with name " + name + " not found at path " + testPath); log.debug("Executable with name " + name + " not found at path " + testPath);
} }
} }