Fix external close behavior [stage]

This commit is contained in:
crschnick
2025-05-21 23:05:16 +00:00
parent 99ac3ff5b4
commit 15fd1aa56c
3 changed files with 26 additions and 14 deletions
@@ -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);
}
@@ -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 {
+1 -1
View File
@@ -1 +1 @@
16.5-2
16.5-3