Move console.warn inside the helper method.

This commit is contained in:
Charlie Hess 2017-01-18 16:09:46 -08:00 committed by Kevin Sawicki
parent f6410d3b77
commit ddedcf22d1

View file

@ -150,22 +150,21 @@ const removeRemoteListenersAndLogWarning = (meta, args, callIntoRenderer) => {
let message = `Attempting to call a function in a renderer window that has been closed or released.` + let message = `Attempting to call a function in a renderer window that has been closed or released.` +
`\nFunction provided here: ${meta.location}` `\nFunction provided here: ${meta.location}`
if (args.length === 0) return message if (args.length > 0 && args[0].sender && args[0].sender.eventNames) {
if (!args[0].sender || !args[0].sender.eventNames) return message const sender = args[0].sender
const remoteEvents = sender.eventNames().filter((eventName) => {
const sender = args[0].sender return sender.listeners(eventName).includes(callIntoRenderer)
const remoteEvents = sender.eventNames().filter((eventName) => {
return sender.listeners(eventName).includes(callIntoRenderer)
})
if (remoteEvents.length > 0) {
message += `\nRemote event names: ${remoteEvents.join(', ')}`
remoteEvents.forEach((eventName) => {
sender.removeListener(eventName, callIntoRenderer)
}) })
if (remoteEvents.length > 0) {
message += `\nRemote event names: ${remoteEvents.join(', ')}`
remoteEvents.forEach((eventName) => {
sender.removeListener(eventName, callIntoRenderer)
})
}
} }
return message console.warn(message)
} }
// Convert array of meta data from renderer into array of real values. // Convert array of meta data from renderer into array of real values.
@ -218,7 +217,7 @@ const unwrapArgs = function (sender, args) {
if (!sender.isDestroyed() && webContentsId === sender.getId()) { if (!sender.isDestroyed() && webContentsId === sender.getId()) {
sender.send('ELECTRON_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args)) sender.send('ELECTRON_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args))
} else { } else {
console.warn(removeRemoteListenersAndLogWarning(meta, args, callIntoRenderer)) removeRemoteListenersAndLogWarning(meta, args, callIntoRenderer)
} }
} }