I basically need to build a hashlist of name => window
pairs.
Since Electron doesn't expose the window name, I'm getting it anyway by running some JS and keeping the result. The problem I have is that this is asychronous whereas the downstream usage cannot allow differing execution (hypothetically, the last two lines in the example below).
So far I have the following code:
function findWindowsByName () {
var result = {};
var promises = Promise.all(
BrowserWindow
.getAllWindows()
.map(function (win) {
return win
.webContents
.executeJavaScript('window.name')
.then(function (name) {
result[name] = win;
});
})
);
// TODO wait for all promises to finish
return result;
};
var windows = findWindowsByName();
// ... use windows ...
I've been looking around for ways to "break out" of the promise vicious circle all questions on SO tend to get the same answer of "deal with it, convert everything to promises". I cannot do this for technical limitations.
via Christian
No comments:
Post a Comment