Tagging BrowserWindow with meta-data


#1

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?

Thanks.


#2

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


#3

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


#4

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.


#5

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


#6

Let us know how it goes. :slight_smile: