mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-23 17:05:41 +00:00
Fix external close behavior [stage]
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user