* UI: improved connects and disconnects processing:

* fixed app freeze on broken server;
 * fixed app freeze on cancel button clicks;
 * fixed wrong still connected dialogs on app close or connect;
 * fixed missing wrong versions message;
 * improved error logs and messages.
This commit is contained in:
Oleg Agafonov 2019-04-11 12:14:18 +04:00
parent 718bfb0a52
commit 5a0f01c14a
6 changed files with 150 additions and 97 deletions

View file

@ -580,8 +580,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
container.repaint();
}
} catch (InterruptedException e) {
LOGGER.fatal("MageFrame error", e);
Thread.currentThread().interrupt();
}
// Nothing to do
if (activeFrame == frame) {
return;
@ -1403,22 +1405,24 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
@Override
public void disconnected(final boolean errorCall) {
public void disconnected(final boolean askToReconnect) {
if (SwingUtilities.isEventDispatchThread()) { // Returns true if the current thread is an AWT event dispatching thread.
LOGGER.info("DISCONNECTED (Event Dispatch Thread)");
// REMOTE task, e.g. connecting
LOGGER.info("Disconnected from remote task");
setConnectButtonText(NOT_CONNECTED_TEXT);
disableButtons();
hideGames();
hideTables();
} else {
LOGGER.info("DISCONNECTED (NO Event Dispatch Thread)");
// USER mode, e.g. user plays and got disconnect
LOGGER.info("Disconnected from user mode");
SwingUtilities.invokeLater(() -> {
setConnectButtonText(NOT_CONNECTED_TEXT);
disableButtons();
hideGames();
hideTables();
SessionHandler.disconnect(false);
if (errorCall) {
if (askToReconnect) {
UserRequestMessage message = new UserRequestMessage("Connection lost", "The connection to server was lost. Reconnect?");
message.setButton1("No", null);
message.setButton2("Yes", PlayerAction.CLIENT_RECONNECT);