fix: ignore (un)lock events for sessions that aren't the current session (#21805)

This commit is contained in:
Samuel Attard 2020-01-19 22:48:12 -08:00 committed by Cheng Zhao
parent 38947f43de
commit ebe8bddc31

View file

@ -58,10 +58,20 @@ LRESULT CALLBACK PowerMonitor::WndProc(HWND hwnd,
WPARAM wparam,
LPARAM lparam) {
if (message == WM_WTSSESSION_CHANGE) {
if (wparam == WTS_SESSION_LOCK) {
Emit("lock-screen");
} else if (wparam == WTS_SESSION_UNLOCK) {
Emit("unlock-screen");
bool should_treat_as_current_session = true;
DWORD current_session_id = 0;
if (!::ProcessIdToSessionId(::GetCurrentProcessId(), &current_session_id)) {
LOG(ERROR) << "ProcessIdToSessionId failed, assuming current session";
} else {
should_treat_as_current_session =
(static_cast<DWORD>(lparam) == current_session_id);
}
if (should_treat_as_current_session) {
if (wparam == WTS_SESSION_LOCK) {
Emit("lock-screen");
} else if (wparam == WTS_SESSION_UNLOCK) {
Emit("unlock-screen");
}
}
}
return ::DefWindowProc(hwnd, message, wparam, lparam);