diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-02-14 13:13:04 +0300 |
---|---|---|
committer | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-02-14 13:13:04 +0300 |
commit | d1bfb404a0f2058840da478f8d6ca34b6d78ebdd (patch) | |
tree | 9493e3e7dad3b3bbb2a24fa556a94f17e57d2db0 /src/gui/guiutility.cpp | |
parent | 0e368b350388bb9e1856a359ca4b61608e7504ae (diff) | |
parent | ec4e2069ff65e66e1f2246b3216e768351a0d2b6 (diff) |
Merge remote-tracking branch 'origin/2.10'
Diffstat (limited to 'src/gui/guiutility.cpp')
-rw-r--r-- | src/gui/guiutility.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/gui/guiutility.cpp b/src/gui/guiutility.cpp index e4f6ee230..9e13d0dda 100644 --- a/src/gui/guiutility.cpp +++ b/src/gui/guiutility.cpp @@ -45,30 +45,39 @@ Q_LOGGING_CATEGORY(lcGuiUtility, "gui.utility", QtInfoMsg) using namespace OCC; +#ifdef Q_OS_WIN namespace { -#ifdef Q_OS_WIN // TODO: 2.11 move to the new Platform class struct { HANDLE windowMessageWatcherEvent = CreateEventW(nullptr, true, false, nullptr); bool windowMessageWatcherRun = true; + std::thread *watcherThread = nullptr; } watchWMCtx; +} -void startShutdownWatcher() +void Utility::startShutdownWatcher() { + if (watchWMCtx.watcherThread) { + return; + } // Qt only receives window message if a window was displayed at least once // create an invisible window to handle WM_ENDSESSION // We also block a system shutdown until we are properly shutdown our selfs // In the unlikely case that we require more than 5s Windows will require a fullscreen message // with our icon, title and the reason why we are blocking the shutdown. - new std::thread([] { + + // ensure to initialise the icon in the main thread + HICON icon = {}; + if (qobject_cast<QGuiApplication *>(qApp)) { + icon = QtWin::toHICON(Theme::instance()->applicationIcon().pixmap(64, 64)); + } + watchWMCtx.watcherThread = new std::thread([icon] { WNDCLASS wc = {}; wc.hInstance = GetModuleHandle(nullptr); wc.lpszClassName = L"ocWindowMessageWatcher"; - if (qobject_cast<QGuiApplication *>(qApp)) { - wc.hIcon = QtWin::toHICON(Theme::instance()->applicationIcon().pixmap(64, 64)); - } + wc.hIcon = icon; wc.lpfnWndProc = [](HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -> LRESULT { // qDebug() << MSG { hwnd, msg, wParam, lParam, 0, {} }; if (msg == WM_QUERYENDSESSION) { @@ -116,9 +125,8 @@ void startShutdownWatcher() SetEvent(watchWMCtx.windowMessageWatcherEvent); }); } -Q_COREAPP_STARTUP_FUNCTION(startShutdownWatcher); #endif -} + bool Utility::openBrowser(const QUrl &url, QWidget *errorWidgetParent) { |