[host] windows: handle graceful shutdown on user switch

This commit is contained in:
Geoffrey McRae
2024-03-06 15:02:37 +11:00
parent 6a72633674
commit 545e736389
4 changed files with 185 additions and 161 deletions

View File

@@ -62,7 +62,7 @@ int main(int argc, char * argv[])
void sigHandler(int signo)
{
DEBUG_INFO("SIGINT");
app_quit();
app_quit(LG_HOST_EXIT_USER);
}
bool app_init(void)

View File

@@ -246,7 +246,7 @@ LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
NULL
);
if (clicked == ID_MENU_EXIT ) app_quit();
if (clicked == ID_MENU_EXIT ) app_quit(LG_HOST_EXIT_USER);
else if (clicked == ID_MENU_SHOW_LOG)
{
const char * logFile = option_get_string("os", "logFile");
@@ -259,6 +259,14 @@ LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
}
case WM_WTSSESSION_CHANGE:
if (wParam == WTS_CONSOLE_DISCONNECT)
{
DEBUG_INFO("Console disconnected, shutting down");
app_quit(LG_HOST_EXIT_CAPTURE);
}
break;
default:
if (msg == app.trayRestartMsg)
RegisterTrayIcon();
@@ -440,6 +448,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
AppendMenu(app.trayMenu, MF_SEPARATOR, 0 , NULL );
AppendMenu(app.trayMenu, MF_STRING , ID_MENU_EXIT , "Exit" );
if (!WTSRegisterSessionNotification(app.messageWnd, NOTIFY_FOR_THIS_SESSION))
DEBUG_WINERROR("WTSRegisterSessionNotification failed", GetLastError());
// create the application thread
LGThread * thread;
if (!lgCreateThread("appThread", appThread, NULL, &thread))
@@ -470,6 +481,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
shutdown:
WTSUnRegisterSessionNotification(app.messageWnd);
DestroyMenu(app.trayMenu);
app_shutdown();
UnregisterWait(app.exitWait);