This is a totally subjective style change. I just prefer keeping code
that is rarely changed tight and dense. Another option would be to
move the menu templates into a separate file.
Ideally both window closing and reloading should use 'beforeunload' to
control whether the unloading should continue, however since the save as
dialog is asynchronous, we have to prevent unloading first and then
continue after user's confirmation. And since we can not distinguish
whether the window is reloading or closing in the 'beforeunload'
handler, we do not know what to continue after user's confirmation. So I
have to rely on BrowserWindow's 'close' event to let user decide whether
window should be closed.
When user wants to close the window, the 'beforeunload' event would be
called, then the closing would be cancelled and the 'window:close'
command would be triggered. In the 'window:close' handler, a confirm
dialog could be showed if there are unsaved contents, and if the window
is really meant to be closed, the window would be tried to be closed
again and this time 'beforeunload' handler wont't prevent it.
In Atom, the 'beforeunload' event never prevents window from closing so
it in fact has the same effect with 'unload' event, I guess using
'beforeunload' instead of 'unload' is because the 'beforeunload' is
guarrenteed to happen when window is closing or application is quiting.
However in Atom Shell the 'unload' event is guarrenteed to happen on
both conditions, just like the 'beforeunload' in Atom, so it's safe to
replace the 'beforeunload' with 'unload' here.
And in Atom Shell, the 'beforeunload' event is mainly used for
preventing window from closing, just like the 'window:close' command in
Atom.
Currently the toggleDevTools of atom-shell is simulated by keeping state
of devtools, because there is no way to know the state of devtools in
brightray, so it could not behave correctly sometimes.
This problem will be solved when brightray is patched and atom-shel gets
updated.