Add some check when closing the application window.