- [Instructor] In addition to being able
to control the windows and cells,
you can control all types of events that happen
as a result of interactions with the windows.
So, let's take a look at how that works
and you can find this in the documentation
under BrowserWindow, and you'll need to scroll quite a bit,
it's almost like in the middle
to the bottom of this page right here.
And you can see that there are all kinds of events.
So for example, you can do something
when the window moves, when the window appears,
when it disappears, when it resizes,
and once you do that you can run
a function that performs some sort of task.
It should be pretty natural, and we're going to do
just a couple of things that are recommended,
and then in another video, I'll show you
how to work with a different window.
So, let's go ahead and take a look at that,
and so what we're going to do is
switch over to our application,
and in here, I'm going to modify my app window,
and I'm going to ask for it to not show when it gets started
so I'll say show false, it seems like a weird thing to do,
but a lot of times when you load things,
especially from websites, you'll notice
that there is a little bit of a process
in which the Electron application actually loads the page
so you can see it drawing the page
as it loads the application.
So, a lot of times what you want to do is,
not show the page until it's finished drawing,
and this is what we're trying to do now.
So, to do that, we're going to need to work
with an event, and that event is called once.
So, we'll say appWindow, and we will say
one time because we only want to check for this
at the beginning of the application one time.
The event that we want to track here
is called ready to show.
So, we want to do this one time,
and when the window is ready to be displayed,
then we want to go ahead and run a function here,
and we'll use appWindow,
and display the window like we did before,
but here, we're specifying
that we're going to show the window only
once the window is ready to be drawn
after it's loaded everything in there.
So, another thing that you want to do,
another event that's pretty useful,
is the on closed events you can say appWindow,
and then on, and in here,
we're going to track the closed event.
We'll also pass along a function here.
So, this is an arrow function, and in here,
we'll say appWindow equals null.
So, this is going to close the window properly.
The application is actually going to do that for you
when you quit, but this is a better way to sort
of get rid of all the memory that is used
to draw a window, and clean things out.
Normally, in an application, you're going to be opening
and closing windows, and sometimes the user,
or the application itself,
will generate windows being opened and closed.
So, it's always a good idea to go ahead
and set this app window variable to null
so that it clears everything out.
So, let's go ahead and save this, and when we run this,
you're not going to notice a lot of difference here.
But if you had a more complicated window,
you would notice that it would not do
that step by step drawing that you would normally see,
and it would just show you the window
when it's loaded in its entirety.
Now, window events are really useful
when you're working with Electron,
and although you can do a lot when you load a framework
like Bootstrap, there's some things that are going
to appear more natural when you work
with Electron's window events.