Skip to content

Commit

Permalink
fix(app): fix removing events on render process
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 8, 2018
1 parent 0abd516 commit f1bfd41
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ const { ipcRenderer, remote } = require('electron');
//window.torrentSocket = io(document.location.protocol + '//' + document.location.hostname + (process.env.NODE_ENV === 'production' ? '/' : ':8095/'));
window.torrentSocket = {}
window.torrentSocket.callbacks = {}
window.torrentSocket.listeners = {}
window.torrentSocket.on = (name, func) => {
ipcRenderer.on(name, (event, ...data) => {
const newListener = (event, ...data) => {
func(...data)
});
}
window.torrentSocket.listeners[func] = newListener
ipcRenderer.on(name, newListener);
}
window.torrentSocket.off = (name, func) => {
if(!func)
ipcRenderer.removeListener(name);
else
ipcRenderer.removeListener(name, func);
ipcRenderer.removeAllListeners(name);
else
{
const realListener = window.torrentSocket.listeners[func]
if(realListener)
{
ipcRenderer.removeListener(name, realListener);
delete window.torrentSocket.listeners[func]
}
}
}
window.torrentSocket.emit = (name, ...data) => {
if(typeof data[data.length - 1] === 'function')
Expand Down

0 comments on commit f1bfd41

Please sign in to comment.