Tagging BrowserWindow with meta-data

Say I have a multi-window app, and there are a number of different types of windows (eg an “editor” and a “preview” etc).

I want to be able to call BrowserWindow.getAllWindows() and filter down on just a certain type of window.

What’s the correct way to distinguish which window is of which type. I can’t see an obvious place in the API to dump meta-data tags about a certain window, but I assume it must be possible to determine what-is-what, somehow.

Rather than hack this, is there a correct way to go about this kind of thing. Or am I thinking about this wrong?


You should be able to build an object that stores each new BrowserWindow as soon as it’s created along with metadata.

Thanks. And attach the object to the window? Or manage that separately?

You would want to attach the window to the object, not the other way around. The object would be your canonical directory so that you don’t have to use getAllWindows() to find the list. It would just be sitting in the top-level scope of your main process, so that whenever any of your main process functions need to open a window or see what windows you have open, they can check that object.

You’ll also need a cleanup function to run when any window closes, so that you don’t have old entries sitting around being dead links.

1 Like

Awesome - thanks for pointing me in the right direction! Thanks.

Let us know how it goes. :slight_smile:

1 Like