From cacfe4f3ca1b2d69190a67bdce3e08fd8a62f20d Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Sep 2022 07:30:31 +0200 Subject: [PATCH] Fix "Open destination folder" delay on Windows Replaced QDesktopServices by native Windows function to open destination folder due to QDesktopServices issues on Windows. The issues are described in #17482 and even more detailed in #17025. Closes #17482. PR #17723. --- src/gui/utils.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index b40dcbbf6..6bd4f1110 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -31,6 +31,7 @@ #ifdef Q_OS_WIN #include #include +#include #endif #include @@ -146,7 +147,24 @@ void Utils::Gui::openPath(const Path &path) const QUrl url = path.data().startsWith(u"//") ? QUrl(u"file:" + path.data()) : QUrl::fromLocalFile(path.data()); + +#ifdef Q_OS_WIN + auto *thread = QThread::create([path]() + { + if (SUCCEEDED(::CoInitializeEx(NULL, (COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))) + { + const std::wstring pathWStr = path.toString().toStdWString(); + + ::ShellExecuteW(nullptr, nullptr, pathWStr.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + + ::CoUninitialize(); + } + }); + QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater); + thread->start(); +#else QDesktopServices::openUrl(url); +#endif } // Open the parent directory of the given path with a file manager and select