Skip to content

Commit 36ed2a7

Browse files
committed
fixup! newwin: focus and blur event support
1 parent 9543046 commit 36ed2a7

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/resources/api_nw_newwin.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ var nwWrapEventsMap = {
7171
'navigation': 'onNavigation'
7272
};
7373

74+
var wrapEventsMapNewWin = {
75+
'focus': 'onFocusChanged',
76+
'blur': 'onFocusChanged'
77+
};
78+
7479
nw_internal.registerCustomHook(function(bindingsAPI) {
7580
var apiFunctions = bindingsAPI.apiFunctions;
7681
apiFunctions.setHandleRequest('getCurrent', function() {
@@ -283,11 +288,13 @@ NWWindow.prototype.removeListener = function (event, callback) {
283288
}
284289
}
285290
}
286-
switch (event) {
287-
case 'focus':
288-
case 'blur':
289-
chrome.windows.onFocusChanged.removeListener(callback.__nw_cb);
290-
break;
291+
if (wrapEventsMapNewWin.hasOwnProperty(event)) {
292+
for (let l of chrome.windows[wrapEventsMapNewWin[event]].getListeners()) {
293+
if (l.callback.listener && l.callback.listener === callback) {
294+
this[nwWrapEventsMap[event]].removeListener(l.callback);
295+
return this;
296+
}
297+
}
291298
}
292299
return this;
293300
};
@@ -320,13 +327,11 @@ NWWindow.prototype.removeAllListeners = function (event) {
320327
}
321328
return this;
322329
}
323-
switch (event) {
324-
case 'focus':
325-
this.appWindow.contentWindow.onfocus = null;
326-
break;
327-
case 'blur':
328-
this.appWindow.contentWindow.onblur = null;
329-
break;
330+
if (wrapEventsMapNewWin.hasOwnProperty(event)) {
331+
for (let l of chrome.windows[wrapEventsMapNewWin[event]].getListeners()) {
332+
chrome.windows[wrapEventsMapNewWin[event]].removeListener(l.callback);
333+
}
334+
return this;
330335
}
331336
return this;
332337
};

0 commit comments

Comments
 (0)