Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Jan 13, 2025
1 parent 59d61b3 commit e9773c7
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/main/java/mpo/dayon/assisted/gui/Assisted.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,7 @@ private void applyConnectionSettings(ConnectionSettingsDialog connectionSettings
String tokenString = connectionSettingsDialog.getToken().trim();
if (!tokenString.isEmpty() && !tokenString.equals(this.token)) {
this.token = tokenString;
final Cursor cursor = frame.getCursor();
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
String connectionParams = null;
try {
Log.debug("Resolving token using: " + tokenServerUrl);
connectionParams = resolveToken(tokenServerUrl, token);
} catch (IOException | InterruptedException ex) {
Log.warn("Could not resolve token " + token);
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
}
Log.debug("Connection params " + connectionParams);
newConfiguration = extractConfiguration(connectionParams);
if (newConfiguration == null) {
// expired or wrong token server
Log.warn("Invalid token " + token);
JOptionPane.showMessageDialog(frame, translate("connection.settings.invalidToken"), translate("connection.settings.token"), JOptionPane.ERROR_MESSAGE);
this.token = null;
}
frame.setCursor(cursor);
newConfiguration = resolveNetworkConfigurationFromToken();
} else {
newConfiguration = new NetworkAssistedEngineConfiguration(connectionSettingsDialog.getIpAddress().trim(),
Integer.parseInt(connectionSettingsDialog.getPortNumber().trim()));
Expand All @@ -236,6 +216,33 @@ private void applyConnectionSettings(ConnectionSettingsDialog connectionSettings
});
}

private NetworkAssistedEngineConfiguration resolveNetworkConfigurationFromToken() {
final Cursor cursor = frame.getCursor();
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
final NetworkAssistedEngineConfiguration newConfiguration;
String connectionParams = null;
try {
Log.debug("Resolving token using: " + tokenServerUrl);
connectionParams = resolveToken(tokenServerUrl, token);
} catch (IOException | InterruptedException ex) {
Log.warn("Could not resolve token " + token);
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} finally {
frame.setCursor(cursor);
}
if (connectionParams == null || connectionParams.trim().isEmpty()) {
// expired or wrong token server
Log.warn("Invalid token " + token);
JOptionPane.showMessageDialog(frame, translate("connection.settings.invalidToken"), translate("connection.settings.token"), JOptionPane.ERROR_MESSAGE);
this.token = null;
}
newConfiguration = extractConfiguration(connectionParams);
Log.debug("Connection params " + connectionParams);
return newConfiguration;
}

private Action createToggleMultiScreenAction() {
final Action multiScreen = new AbstractAction() {
@Override
Expand Down

0 comments on commit e9773c7

Please sign in to comment.