add log.js module for renderer logging
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
31
main/log.js
Normal file
31
main/log.js
Normal file
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user