From e397a5af753b0bfa5e413bc90ba1bfd804860a6e Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Sun, 18 Jun 2023 16:02:05 +0800 Subject: [PATCH] Add close window support for Windows (#1111) * Add close window support for Windows * Support logoff and shudown events as well Without this change, when you close the terminal/shell window, it won't have the time to clean up which can cause authentication errors if you try to reconnect. Blocking here infinitely is fine since when our main thread returns, it will shut down anyway I found Go is doing this when I was searching, and there's a comment explained how it works: https://github.com/golang/go/issues/41884#issuecomment-706695923 --- src/edge.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/edge.c b/src/edge.c index 8bbf162..db4da65 100644 --- a/src/edge.c +++ b/src/edge.c @@ -946,6 +946,13 @@ BOOL WINAPI term_handler(DWORD sig) keep_on_running = false; #ifdef WIN32 + switch (sig) { + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + // Will terminate us after we return, blocking it to cleanup + Sleep(INFINITE); + } return(TRUE); #endif }