Skip to content

Commit

Permalink
Fix #7593: nw2 Window removing listeners on 'loaded' event
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Oct 16, 2020
1 parent 663cde0 commit a6496dd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/resources/api_nw_newwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var nwWinEventsMap = {
};

var nwWrapEventsMap = {
'loaded': 'LoadingStateChanged',
'new-win-policy': 'onNewWinPolicy',
'navigation': 'onNavigation'
};
Expand Down Expand Up @@ -265,6 +264,14 @@ NWWindow.prototype.on = function (event, callback, record) {
return this;
};
NWWindow.prototype.removeListener = function (event, callback) {
if (event === 'loaded') {
for (let l of chrome.tabs.onUpdated.getListeners()) {
if (l.listener && l.listener === callback) {
chrome.tabs.onUpdated.removeListener(l);
return this;
}
}
}
if (nwWinEventsMap.hasOwnProperty(event)) {
for (let l of this[nwWinEventsMap[event]].getListeners()) {
if (l.listener && l.listener === callback) {
Expand Down Expand Up @@ -320,6 +327,12 @@ NWWindow.prototype.removeAllListeners = function (event) {
}
return this;
}
if (event === 'loaded') {
for (let l of chrome.tabs.onUpdated.getListeners()) {
chrome.tabs.onUpdated.removeListener(l);
}
return this;
}
return this;
};

Expand Down

0 comments on commit a6496dd

Please sign in to comment.