From 96418bb9f1b4586d30f056ca1013e432bc8a4e8b Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 15 Oct 2025 20:16:11 +0000 Subject: [PATCH] Make QFileOpenEvent timeout immediate --- Telegram/SourceFiles/core/application.cpp | 24 ++++++++++++----------- Telegram/SourceFiles/core/application.h | 2 -- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index e24cb260ea..19cdb018a6 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_download_manager.h" #include "base/battery_saving.h" #include "base/event_filter.h" +#include "base/invoke_queued.h" #include "base/concurrent_timer.h" #include "base/options.h" #include "base/qt_signal_producer.h" @@ -103,7 +104,6 @@ namespace { constexpr auto kQuitPreventTimeoutMs = crl::time(1500); constexpr auto kAutoLockTimeoutLateMs = crl::time(3000); constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000); -constexpr auto kFileOpenTimeoutMs = crl::time(1000); LaunchState GlobalLaunchState/* = LaunchState::Running*/; @@ -168,8 +168,7 @@ Application::Application() , _langCloudManager(std::make_unique(langpack())) , _emojiKeywords(std::make_unique()) , _tray(std::make_unique()) -, _autoLockTimer([=] { checkAutoLock(); }) -, _fileOpenTimer([=] { checkFileOpen(); }) { +, _autoLockTimer([=] { checkAutoLock(); }) { Ui::Integration::Set(&_private->uiIntegration); _platformIntegration->init(); @@ -693,9 +692,18 @@ bool Application::eventFilter(QObject *object, QEvent *e) { case QEvent::FileOpen: { if (object == QCoreApplication::instance()) { const auto event = static_cast(e); + const auto flushQueued = [=] { + if (_filesToOpen.isEmpty()) { + InvokeQueued([=] { + cSetSendPaths(_filesToOpen); + _filesToOpen.clear(); + checkSendPaths(); + }); + } + }; if (const auto file = event->file(); !file.isEmpty()) { + flushQueued(); _filesToOpen.append(file); - _fileOpenTimer.callOnce(kFileOpenTimeoutMs); } else if (event->url().scheme() == u"tg"_q || event->url().scheme() == u"tonsite"_q) { const auto url = QString::fromUtf8( @@ -707,8 +715,8 @@ bool Application::eventFilter(QObject *object, QEvent *e) { _lastActivePrimaryWindow->activate(); } } else if (event->url().scheme() == u"interpret"_q) { + flushQueued(); _filesToOpen.append(event->url().toString()); - _fileOpenTimer.callOnce(kFileOpenTimeoutMs); } } } break; @@ -1081,12 +1089,6 @@ bool Application::canApplyLangPackWithoutRestart() const { return true; } -void Application::checkFileOpen() { - cSetSendPaths(_filesToOpen); - _filesToOpen.clear(); - checkSendPaths(); -} - void Application::checkSendPaths() { if (!cSendPaths().isEmpty() && _lastActivePrimaryWindow diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 24bec04def..4cfa3ef176 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -272,7 +272,6 @@ public: // Internal links. void checkStartUrl(); void checkSendPaths(); - void checkFileOpen(); bool openLocalUrl(const QString &url, QVariant context); bool openInternalUrl(const QString &url, QVariant context); [[nodiscard]] QString changelogLink() const; @@ -452,7 +451,6 @@ private: base::Timer _autoLockTimer; QStringList _filesToOpen; - base::Timer _fileOpenTimer; std::optional _saveSettingsTimer;