瀏覽代碼

fix premature shutdown (e.g. on ⌘Q on macOS)

Sebastian Stenzel 3 年之前
父節點
當前提交
6eacc6a9d3

+ 1 - 0
src/main/java/org/cryptomator/launcher/Cryptomator.java

@@ -46,6 +46,7 @@ public class Cryptomator {
 
 	public static void main(String[] args) {
 		int exitCode = CRYPTOMATOR_COMPONENT.application().run(args);
+		LOG.info("Exit {}", exitCode);
 		System.exit(exitCode); // end remaining non-daemon threads.
 	}
 

+ 8 - 2
src/main/java/org/cryptomator/ui/launcher/AppLifecycleListener.java

@@ -19,6 +19,7 @@ import java.awt.Desktop;
 import java.awt.EventQueue;
 import java.awt.desktop.AboutEvent;
 import java.awt.desktop.QuitResponse;
+import java.awt.desktop.QuitStrategy;
 import java.util.EnumSet;
 import java.util.EventObject;
 import java.util.Set;
@@ -61,6 +62,11 @@ public class AppLifecycleListener {
 			Desktop.getDesktop().setQuitHandler(this::handleQuitRequest);
 		}
 
+		// set quit strategy (cmd+q would call `System.exit(0)` otherwise)
+		if (Desktop.getDesktop().isSupported(Desktop.Action.APP_QUIT_STRATEGY)) {
+			Desktop.getDesktop().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
+		}
+
 		shutdownHook.runOnShutdown(this::forceUnmountRemainingVaults);
 	}
 
@@ -71,7 +77,7 @@ public class AppLifecycleListener {
 		handleQuitRequest(null, new QuitResponse() {
 			@Override
 			public void performQuit() {
-				System.exit(0);
+				// no-op
 			}
 
 			@Override
@@ -96,7 +102,7 @@ public class AppLifecycleListener {
 			public void performQuit() {
 				Platform.exit(); // will be no-op, if JavaFX never started.
 				shutdownLatch.countDown(); // main thread is waiting for this latch
-				EventQueue.invokeLater(originalQuitResponse::performQuit); // this will eventually call System.exit(0)
+				originalQuitResponse.performQuit();
 			}
 
 			@Override