mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* 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:
parent
718bfb0a52
commit
5a0f01c14a
6 changed files with 150 additions and 97 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -517,7 +517,6 @@ public class ConnectDialog extends MageDialog {
|
|||
|
||||
char[] input = new char[0];
|
||||
try {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
connection = new Connection();
|
||||
connection.setHost(this.txtServer.getText().trim());
|
||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||
|
|
@ -545,6 +544,12 @@ public class ConnectDialog extends MageDialog {
|
|||
|
||||
}//GEN-LAST:event_btnConnectActionPerformed
|
||||
|
||||
private void setConnectButtonsState(boolean enable) {
|
||||
btnConnect.setEnabled(enable);
|
||||
btnRegister.setEnabled(enable);
|
||||
btnForgotPassword.setEnabled(enable);
|
||||
}
|
||||
|
||||
private class ConnectTask extends SwingWorker<Boolean, Void> {
|
||||
|
||||
private boolean result = false;
|
||||
|
|
@ -555,7 +560,7 @@ public class ConnectDialog extends MageDialog {
|
|||
@Override
|
||||
protected Boolean doInBackground() throws Exception {
|
||||
lblStatus.setText("Connecting...");
|
||||
btnConnect.setEnabled(false);
|
||||
setConnectButtonsState(false);
|
||||
result = MageFrame.connect(connection);
|
||||
lastConnectError = SessionHandler.getLastConnectError();
|
||||
return result;
|
||||
|
|
@ -565,7 +570,6 @@ public class ConnectDialog extends MageDialog {
|
|||
protected void done() {
|
||||
try {
|
||||
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
if (result) {
|
||||
lblStatus.setText("");
|
||||
connected();
|
||||
|
|
@ -578,13 +582,13 @@ public class ConnectDialog extends MageDialog {
|
|||
} catch (ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (CancellationException ex) {
|
||||
logger.info("Connect was canceled");
|
||||
logger.info("Connect: canceled");
|
||||
lblStatus.setText("Connect was canceled");
|
||||
} catch (TimeoutException ex) {
|
||||
logger.fatal("Connection timeout: ", ex);
|
||||
} finally {
|
||||
MageFrame.stopConnecting();
|
||||
btnConnect.setEnabled(true);
|
||||
setConnectButtonsState(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ public class MageDialog extends javax.swing.JInternalFrame {
|
|||
SwingUtilities.invokeAndWait(() -> stopModal());
|
||||
} catch (InterruptedException ex) {
|
||||
LOGGER.fatal("MageDialog error", ex);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (InvocationTargetException ex) {
|
||||
LOGGER.fatal("MageDialog error", ex);
|
||||
}
|
||||
|
|
@ -184,9 +185,10 @@ public class MageDialog extends javax.swing.JInternalFrame {
|
|||
wait();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.fatal("MageDialog error", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private synchronized void stopModal() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue