Skip to content

Commit 832cb23

Browse files
committed
Fix application freezing after ⌘-Q when in background
1 parent a2e1dad commit 832cb23

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/main/java/com/airsquared/blobsaver/Background.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ static void startBackground(boolean runOnlyOnce) {
105105
openItem.setFont(Font.decode(null).deriveFont(Font.BOLD)); // bold it
106106

107107
MenuItem exitItem = new MenuItem("Quit");
108-
exitItem.addActionListener(event -> {
109-
executor.shutdownNow();
110-
Platform.runLater(Platform::exit);
111-
tray.remove(trayIcon);
112-
System.exit(0);
113-
});
108+
exitItem.addActionListener(event -> Platform.runLater(Platform::exit));
114109

115110
// setup the popup menu for the application.
116111
final PopupMenu popup = new PopupMenu();
@@ -321,14 +316,13 @@ private static void showStage() {
321316
static void stopBackground(boolean showAlert) {
322317
inBackground = false;
323318
executor.shutdownNow();
324-
SwingUtilities.invokeLater(() -> SystemTray.getSystemTray().remove(trayIcon));
325-
if (showAlert && Platform.isFxApplicationThread()) {
326-
Alert alert = new Alert(Alert.AlertType.INFORMATION,
327-
"The background process has been cancelled",
328-
ButtonType.OK);
329-
alert.showAndWait();
330-
} else if (showAlert) {
331-
Platform.runLater(() -> {
319+
if (SwingUtilities.isEventDispatchThread()) {
320+
SystemTray.getSystemTray().remove(trayIcon);
321+
} else {
322+
SwingUtilities.invokeLater(() -> SystemTray.getSystemTray().remove(trayIcon));
323+
}
324+
if (showAlert) {
325+
Shared.runSafe(() -> {
332326
Alert alert = new Alert(Alert.AlertType.INFORMATION,
333327
"The background process has been cancelled",
334328
ButtonType.OK);

src/main/java/com/airsquared/blobsaver/Controller.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,6 @@ public void startBackgroundHandler() {
750750
appPrefs.putBoolean("Show background startup message", true);
751751
appPrefs.putBoolean("Start background immediately", false);
752752
Platform.exit();
753-
Background.stopBackground(false);
754-
System.exit(0);
755753
} else {
756754
Background.stopBackground(true);
757755
appPrefs.putBoolean("Show background startup message", true);
@@ -766,7 +764,6 @@ public void startBackgroundHandler() {
766764
appPrefs.putBoolean("Show background startup message", false);
767765
appPrefs.putBoolean("Start background immediately", true);
768766
Platform.exit();
769-
System.exit(0);
770767
} else if (appPrefs.getBoolean("Show background startup message", true)) {
771768
Alert alert = new Alert(Alert.AlertType.INFORMATION,
772769
"The application will now enter the background. By default, when you launch this application, it will start up in the background. "
@@ -809,7 +806,6 @@ public void resetAppHandler() {
809806
Alert applicationCloseAlert = new Alert(Alert.AlertType.INFORMATION, "The application data and files have been removed. If you are running Windows, you still will need to run the uninstall .exe. Otherwise, you can just delete the .app or .jar file.\nThe application will now exit.", ButtonType.OK);
810807
applicationCloseAlert.showAndWait();
811808
Platform.exit();
812-
System.exit(0);
813809
} catch (BackingStoreException e) {
814810
newReportableError("There was an error resetting the application.", e.getMessage());
815811
}

src/main/java/com/airsquared/blobsaver/Main.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ public void start(Stage primaryStage) throws IOException {
9999
if (Background.inBackground) {
100100
primaryStage.hide();
101101
} else {
102-
Platform.exit();
103-
System.exit(0);
102+
stop();
104103
}
105104
});
106105
appPrefs.put("App version", appVersion);
107106
}
107+
108+
@Override
109+
public void stop() {
110+
if (Background.inBackground) {
111+
Background.stopBackground(false);
112+
}
113+
}
108114
}
109115
}

0 commit comments

Comments
 (0)