Skip to content

Commit 2827525

Browse files
committed
newwin: support closed event and fix issue in removing listeners
1 parent 515901b commit 2827525

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/resources/api_nw_newwin.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ function getPlatform() {
5050
}
5151

5252
var canSetVisibleOnAllWorkspaces = /(mac|linux)/.exec(getPlatform());
53-
var appWinEventsMap = {
54-
'closed': 'onClosed'
55-
};
5653

5754
var nwWinEventsMap = {
5855
'minimize': 'onMinimized',
@@ -73,7 +70,8 @@ var nwWrapEventsMap = {
7370
var wrapEventsMapNewWin = {
7471
'move': 'onMove',
7572
'focus': 'onFocusChanged',
76-
'blur': 'onFocusChanged'
73+
'blur': 'onFocusChanged',
74+
'closed': 'onRemoved'
7775
};
7876

7977
nw_internal.registerCustomHook(function(bindingsAPI) {
@@ -223,6 +221,14 @@ NWWindow.prototype.on = function (event, callback, record) {
223221
});
224222
chrome.windows.onFocusChanged.addListener(cbf);
225223
break;
224+
case 'closed':
225+
var cbr = wrap(function(windowId) {
226+
if (self.cWindow.id === windowId)
227+
return;
228+
callback.call(self);
229+
});
230+
chrome.windows.onRemoved.addListener(cbr);
231+
break;
226232
case 'loaded':
227233
var g = wrap(function(tabId, changeInfo, tab) {
228234
if (tab.windowId !== self.cWindow.id)
@@ -305,7 +311,7 @@ NWWindow.prototype.removeListener = function (event, callback) {
305311
if (wrapEventsMapNewWin.hasOwnProperty(event)) {
306312
for (let l of chrome.windows[wrapEventsMapNewWin[event]].getListeners()) {
307313
if (l.callback.listener && l.callback.listener === callback) {
308-
this[nwWrapEventsMap[event]].removeListener(l.callback);
314+
chrome.windows[wrapEventsMapNewWin[event]].removeListener(l.callback);
309315
return this;
310316
}
311317
}

0 commit comments

Comments
 (0)