Skip to content

Commit

Permalink
Windows: fix system shutdown handling
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jan 4, 2025
1 parent 993bf9d commit 94f754e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sources/suspend-handler/SuspendHandlerWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <windows.h>
#include <wtsapi32.h>
#include <systray/Systray.h>
#include <QCoreApplication>

#pragma comment (lib, "WtsApi32.Lib")

Expand All @@ -49,7 +50,12 @@ namespace

static void SuspendHandlerQueueHandler(WPARAM wparam)
{
if (instance != nullptr)
if (wparam == 0)
{
auto instance = QCoreApplication::instance();
QUEUE_CALL_0(instance, quit);
}
else if (instance != nullptr)
{
MSG message{};
QByteArray eventType;
Expand Down
7 changes: 7 additions & 0 deletions sources/systray/SystrayWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam,
}
return true;

case WM_QUERYENDSESSION:
if (queueHandler != nullptr && lparam == 0)
{
queueHandler(0);
}
return false;

case WM_CLOSE:
DestroyWindow(hwnd);
hwnd = nullptr;
Expand Down

0 comments on commit 94f754e

Please sign in to comment.