When closing the window, disconnect instead of asking the user to do it

* Disconnect before closing the window
* Asks for confirmation if there is unsent input