Fix beforeClose on main window