diff --git a/main/auto-updater.js b/main/auto-updater.js index 1fcb5b17..f161d9b2 100644 --- a/main/auto-updater.js +++ b/main/auto-updater.js @@ -5,13 +5,13 @@ module.exports = { var electron = require('electron') var config = require('../config') +var log = require('./log') -// var app = electron.app var autoUpdater = electron.autoUpdater function init () { autoUpdater.on('error', function (err) { - console.error('error downloading app update', err.message || err) + log.error('Auto update error', err.message || err) }) autoUpdater.setFeedURL(config.AUTO_UPDATE_URL) @@ -32,10 +32,10 @@ function init () { */ setInterval(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_INTERVAL) - autoUpdater.on('checking-for-update', () => console.log('checking for app update')) - autoUpdater.on('update-available', () => console.log('app update available')) - autoUpdater.on('update-not-available', () => console.log('app update not available')) + autoUpdater.on('checking-for-update', () => log('Checking for app update')) + autoUpdater.on('update-available', () => log('App update available')) + autoUpdater.on('update-not-available', () => log('App update not available')) autoUpdater.on('update-downloaded', function (e) { - console.log('app update downloaded', e) + log('App update downloaded', e) }) } diff --git a/main/index.js b/main/index.js index 0e4d07e7..34ab4729 100644 --- a/main/index.js +++ b/main/index.js @@ -5,6 +5,7 @@ var app = electron.app var autoUpdater = require('./auto-updater') var config = require('../config') var ipc = require('./ipc') +var log = require('./log') var menu = require('./menu') var registerProtocolHandler = require('./register-handlers') var shortcuts = require('./shortcuts') @@ -16,7 +17,7 @@ var shouldQuit = app.makeSingleInstance(function (newArgv) { newArgv = sliceArgv(newArgv) if (app.ipcReady) { - windows.main.send('log', 'Second app instance attempted to open but was prevented') + log('Second app instance attempted to open but was prevented') newArgv.forEach(function (torrentId) { windows.main.send('dispatch', 'onOpen', torrentId) @@ -55,9 +56,9 @@ app.on('ready', function () { }) app.on('ipcReady', function () { - windows.main.send('log', 'IS_PRODUCTION:', config.IS_PRODUCTION) + log('IS_PRODUCTION:', config.IS_PRODUCTION) if (argv.length) { - windows.main.send('log', 'command line args:', process.argv) + log('command line args:', process.argv) } argv.forEach(function (torrentId) { windows.main.send('dispatch', 'onOpen', torrentId) diff --git a/main/ipc.js b/main/ipc.js index e610cad5..ffbdad46 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -9,6 +9,7 @@ var app = electron.app var ipcMain = electron.ipcMain var powerSaveBlocker = electron.powerSaveBlocker +var log = require('./log') var menu = require('./menu') var windows = require('./windows') @@ -51,7 +52,7 @@ function init () { }) ipcMain.on('openItem', function (e, path) { - console.log('opening file or folder: ' + path) + log('opening file or folder: ' + path) electron.shell.openItem(path) }) diff --git a/main/log.js b/main/log.js new file mode 100644 index 00000000..bc064135 --- /dev/null +++ b/main/log.js @@ -0,0 +1,31 @@ +module.exports = log +module.exports.error = error + +/** + * In the main electron process, we do not use console.log() statements because they do + * not show up in a convenient location when running the packaged (i.e. production) + * version of the app. Instead use this module, which sends the logs to the main window + * where they can be viewed in Developer Tools. + */ + +var electron = require('electron') + +var windows = require('./windows') + +var app = electron.app + +function log (...args) { + if (app.ipcReady) { + windows.main.send('log', ...args) + } else { + app.on('ipcReady', () => windows.main.send('log', ...args)) + } +} + +function error (...args) { + if (app.ipcReady) { + windows.main.send('error', ...args) + } else { + app.on('ipcReady', () => windows.main.send('error', ...args)) + } +} diff --git a/main/register-handlers.js b/main/register-handlers.js index a9a21902..95e46c42 100644 --- a/main/register-handlers.js +++ b/main/register-handlers.js @@ -1,3 +1,5 @@ +var log = require('./log') + module.exports = function () { if (process.platform === 'win32') { var path = require('path') @@ -86,7 +88,7 @@ function registerProtocolHandlerWin32 (protocol, name, icon, command) { commandKey.set('', Registry.REG_SZ, '"' + command + '" "%1"', callback) function callback (err) { - if (err) console.error(err.message || err) + if (err) log.error(err.message || err) } } @@ -118,6 +120,6 @@ function registerFileHandlerWin32 (ext, id, name, icon, command) { commandKey.set('', Registry.REG_SZ, '"' + command + '" "%1"', callback) function callback (err) { - if (err) console.error(err.message || err) + if (err) log.error(err.message || err) } } diff --git a/renderer/index.js b/renderer/index.js index 810ace96..b8412149 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -283,6 +283,7 @@ function setupIpc () { ipcRenderer.send('ipcReady') ipcRenderer.on('log', (e, ...args) => console.log(...args)) + ipcRenderer.on('error', (e, ...args) => console.error(...args)) ipcRenderer.on('dispatch', (e, ...args) => dispatch(...args))