1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Fix SerialMonitor and SerialPlotter lifecycles

Fixes #7683

When the selected serial port is busy both monitors now avoid displaying a useless window, cleaning the status area once the open succeeds.
This commit is contained in:
Martino Facchin 2018-06-12 10:39:38 +02:00
parent 0a84ac2138
commit fa51a39b58

View File

@ -2409,11 +2409,12 @@ public class Editor extends JFrame implements RunnerListener {
}
try {
serialMonitor.setVisible(true);
if (!avoidMultipleOperations) {
serialMonitor.open();
}
serialMonitor.setVisible(true);
success = true;
statusEmpty();
} catch (ConnectException e) {
statusError(tr("Unable to connect: is the sketch using the bridge?"));
} catch (JSchException e) {
@ -2423,6 +2424,7 @@ public class Editor extends JFrame implements RunnerListener {
if (e.getCause() != null && e.getCause() instanceof SerialPortException) {
errorMessage += " (" + ((SerialPortException) e.getCause()).getExceptionType() + ")";
}
serialMonitor = null;
statusError(errorMessage);
try {
serialMonitor.close();
@ -2432,12 +2434,12 @@ public class Editor extends JFrame implements RunnerListener {
} catch (Exception e) {
statusError(e);
} finally {
if (serialMonitor.requiresAuthorization() && !success) {
if (serialMonitor != null && serialMonitor.requiresAuthorization() && !success) {
PreferencesData.remove(serialMonitor.getAuthorizationKey());
}
}
} while (serialMonitor.requiresAuthorization() && !success);
} while (serialMonitor != null && serialMonitor.requiresAuthorization() && !success);
}
@ -2457,6 +2459,7 @@ public class Editor extends JFrame implements RunnerListener {
if (serialPlotter.isClosed()) {
// If it's closed, clear the refrence to the existing
// plotter and create a new one
serialPlotter.dispose();
serialPlotter = null;
}
else {
@ -2510,6 +2513,7 @@ public class Editor extends JFrame implements RunnerListener {
serialPlotter.open();
serialPlotter.setVisible(true);
success = true;
statusEmpty();
} catch (ConnectException e) {
statusError(tr("Unable to connect: is the sketch using the bridge?"));
} catch (JSchException e) {
@ -2520,15 +2524,16 @@ public class Editor extends JFrame implements RunnerListener {
errorMessage += " (" + ((SerialPortException) e.getCause()).getExceptionType() + ")";
}
statusError(errorMessage);
serialPlotter = null;
} catch (Exception e) {
statusError(e);
} finally {
if (serialPlotter.requiresAuthorization() && !success) {
if (serialPlotter != null && serialPlotter.requiresAuthorization() && !success) {
PreferencesData.remove(serialPlotter.getAuthorizationKey());
}
}
} while (serialPlotter.requiresAuthorization() && !success);
} while (serialPlotter != null && serialPlotter.requiresAuthorization() && !success);
}