1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-01 23:29:28 +01:00

Merge pull request #8184 from facchinm/kill_programmer_at_exit

Kill active programmer if still alive after closing last IDE window
This commit is contained in:
Martino Facchin 2018-11-23 12:07:13 +01:00 committed by GitHub
commit c1d9c588b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 28 deletions

View File

@ -26,6 +26,7 @@ import cc.arduino.Compiler;
import cc.arduino.Constants; import cc.arduino.Constants;
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler; import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
import cc.arduino.UploaderUtils; import cc.arduino.UploaderUtils;
import cc.arduino.packages.Uploader;
import cc.arduino.contributions.*; import cc.arduino.contributions.*;
import cc.arduino.contributions.libraries.*; import cc.arduino.contributions.libraries.*;
import cc.arduino.contributions.libraries.ui.LibraryManagerUI; import cc.arduino.contributions.libraries.ui.LibraryManagerUI;
@ -925,45 +926,20 @@ public class Base {
*/ */
public boolean handleClose(Editor editor) { public boolean handleClose(Editor editor) {
// Check if modified // Check if modified
// boolean immediate = editors.size() == 1;
if (!editor.checkModified()) { if (!editor.checkModified()) {
return false; return false;
} }
if (editors.size() == 1) { if (editors.size() == 1) {
storeScreenDimensions();
storeSketches();
// This will store the sketch count as zero handleQuit();
editors.remove(editor);
try {
Editor.serialMonitor.close();
} catch (Exception e) {
//ignore
}
rebuildRecentSketchesMenuItems();
// Save out the current prefs state
PreferencesData.save();
// Since this wasn't an actual Quit event, call System.exit()
System.exit(0);
} else { } else {
// More than one editor window open, // More than one editor window open,
// proceed with closing the current window. // proceed with closing the current window.
editor.setVisible(false); editor.setVisible(false);
editor.dispose(); editor.dispose();
// for (int i = 0; i < editorCount; i++) {
// if (editor == editors[i]) {
// for (int j = i; j < editorCount-1; j++) {
// editors[j] = editors[j+1];
// }
// editorCount--;
// // Set to null so that garbage collection occurs
// editors[editorCount] = null;
// }
// }
editors.remove(editor); editors.remove(editor);
} }
return true; return true;
@ -986,6 +962,14 @@ public class Base {
// ignore // ignore
} }
// kill uploader (if still alive)
UploaderUtils uploaderInstance = new UploaderUtils();
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
if (uploader != null && uploader.programmerPid != null && uploader.programmerPid.isAlive()) {
// kill the stuck programmer
uploader.programmerPid.destroyForcibly();
}
if (handleQuitEach()) { if (handleQuitEach()) {
// Save out the current prefs state // Save out the current prefs state
PreferencesData.save(); PreferencesData.save();

View File

@ -106,7 +106,7 @@ public abstract class Uploader implements MessageConsumer {
} }
// static field for last executed programmer process ID // static field for last executed programmer process ID
static protected Process programmerPid; static public Process programmerPid;
protected boolean executeUploadCommand(Collection<String> command) throws Exception { protected boolean executeUploadCommand(Collection<String> command) throws Exception {
return executeUploadCommand(command.toArray(new String[command.size()])); return executeUploadCommand(command.toArray(new String[command.size()]));