diff --git a/app/src/main/java/io/xpipe/app/core/AppWindowsShutdown.java b/app/src/main/java/io/xpipe/app/core/AppWindowsShutdown.java index 454bfaf97..389f561aa 100644 --- a/app/src/main/java/io/xpipe/app/core/AppWindowsShutdown.java +++ b/app/src/main/java/io/xpipe/app/core/AppWindowsShutdown.java @@ -67,6 +67,11 @@ public class AppWindowsShutdown { if (nCode >= 0 && hookProcStruct.hwnd.equals(hwnd)) { if (hookProcStruct.message.longValue() == WM_QUERYENDSESSION) { TrackEvent.info("Received window shutdown callback WM_QUERYENDSESSION"); + + // We don't always receive an exit signal with a queryendsession, e.g. in case an .msi wants to shut it down + // Guarantee that the shutdown is run regardless + OperationMode.externalShutdown(); + // Indicates that we need to run the endsession case blocking return new WinDef.LRESULT(0); } diff --git a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java index eb79a78b6..0e29d1f05 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java @@ -66,18 +66,22 @@ public abstract class OperationMode { return null; } + public static void externalShutdown() { + // If we used System.exit(), we don't want to do this + if (OperationMode.isInShutdown()) { + return; + } + + inShutdownHook = true; + TrackEvent.info("Received SIGTERM externally"); + OperationMode.shutdown(false); + } + private static void setup(String[] args) { try { // Only for handling SIGTERM Runtime.getRuntime().addShutdownHook(new Thread(() -> { - // If we used System.exit(), we don't want to do this - if (OperationMode.isInShutdown()) { - return; - } - - inShutdownHook = true; - TrackEvent.info("Received SIGTERM externally"); - OperationMode.shutdown(false); + externalShutdown(); })); // Handle uncaught exceptions @@ -318,13 +322,16 @@ public abstract class OperationMode { OperationMode.halt(1); } - if (inShutdown) { - return; - } - TrackEvent.info("Starting shutdown ..."); - inShutdown = true; + synchronized (OperationMode.class) { + if (inShutdown) { + return; + } + + inShutdown = true; + } + // Keep a non-daemon thread running var thread = ThreadHelper.createPlatformThread("shutdown", false, () -> { try { diff --git a/version b/version index 02eb35fd6..dd91b31ec 100644 --- a/version +++ b/version @@ -1 +1 @@ -16.5-2 +16.5-3