Skip to content

Commit 44d2c91

Browse files
committed
nw2: add nw.Window.getAll
Fix nwjs#7227
1 parent 0b836a5 commit 44d2c91

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

docs/References/Window.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ nw.Window.open('https://github.com/nwjs/nw.js', {}, function(new_win) {
6262
// do something with the newly created window
6363
});
6464
```
65+
## Window.getAll(callback)
66+
67+
Get all windows with a callback function whose parameter is an array of nw.Window object. This function is supported since 0.42.6.
6568

6669
## Window.open(url, [options], [callback])
6770

src/api/nw_window.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace nw.Window {
77
callback CreateWindowCallback =
88
void ([instanceOf=NWWindow] object createdWindow);
99
callback EventCallback = void();
10+
callback GetAllWinCallback = void (object[] windows);
1011

1112
callback CapturePageCallback = void (DOMString dataUrl);
1213
[noinline_doc] dictionary CapturePageOptions {
@@ -94,6 +95,7 @@ namespace nw.Window {
9495
interface Functions {
9596
// get the current window
9697
[nocompile] static NWWindow get(optional object domWindow);
98+
[nocompile] static void getAll(GetAllWinCallback callback);
9799
[nocompile] static void open(DOMString url,
98100
optional CreateWindowOptions options,
99101
optional CreateWindowCallback callback);

src/resources/api_nw_newwin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
624624
return currentNWWindow;
625625
});
626626

627+
apiFunctions.setHandleRequest('getAll', function(callback) {
628+
chrome.windows.getAll({populate: true}, function (cwindows) {
629+
let create_nw_win = cwin => new NWWindow(cwin);
630+
callback(cwindows.map(create_nw_win));
631+
});
632+
});
633+
627634
apiFunctions.setHandleRequest('open', function(url, params, callback) {
628635
var options = {'url': url, 'setSelfAsOpener': true, 'type': 'popup'};
629636
//FIXME: unify this conversion code with nwjs/default.js

0 commit comments

Comments
 (0)