Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CTRL_CLOSE_EVENT on Windows #2952

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ SessionMonitorWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}

WINAPI BOOL
ConsoleCtrlHandler(DWORD type) {
if (type == CTRL_CLOSE_EVENT) {
BOOST_LOG(info) << "Console closed handler called";
lifetime::exit_sunshine(0, false);
}
return FALSE;
}
#endif

int
Expand Down Expand Up @@ -244,6 +253,11 @@ main(int argc, char *argv[]) {
shutdown_event->raise(true);
});

#ifdef _WIN32
// Terminate gracefully on Windows when console window is closed
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
#endif

proc::refresh(config::stream.file_apps);

// If any of the following fail, we log an error and continue event though sunshine will not function correctly.
Expand Down
Loading