Skip to content

Commit

Permalink
[host] windows: handle graceful shutdown on user switch
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Mar 6, 2024
1 parent 6a72633 commit 545e736
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 147 deletions.
2 changes: 1 addition & 1 deletion host/include/interface/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
int app_main(int argc, char * argv[]);
bool app_init(void);
void app_shutdown(void);
void app_quit(void);
void app_quit(int exitcode);

// these must be implemented for each OS
const char * os_getExecutable(void);
Expand Down
2 changes: 1 addition & 1 deletion host/platform/Linux/src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion host/platform/Windows/src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 545e736

Please sign in to comment.