Skip to content

Commit 96418bb

Browse files
ilya-fedinjohn-preston
authored andcommitted
Make QFileOpenEvent timeout immediate
1 parent f750d94 commit 96418bb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Telegram/SourceFiles/core/application.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For license and copyright information please follow this link:
1515
#include "data/data_download_manager.h"
1616
#include "base/battery_saving.h"
1717
#include "base/event_filter.h"
18+
#include "base/invoke_queued.h"
1819
#include "base/concurrent_timer.h"
1920
#include "base/options.h"
2021
#include "base/qt_signal_producer.h"
@@ -103,7 +104,6 @@ namespace {
103104
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
104105
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
105106
constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000);
106-
constexpr auto kFileOpenTimeoutMs = crl::time(1000);
107107

108108
LaunchState GlobalLaunchState/* = LaunchState::Running*/;
109109

@@ -168,8 +168,7 @@ Application::Application()
168168
, _langCloudManager(std::make_unique<Lang::CloudManager>(langpack()))
169169
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
170170
, _tray(std::make_unique<Tray>())
171-
, _autoLockTimer([=] { checkAutoLock(); })
172-
, _fileOpenTimer([=] { checkFileOpen(); }) {
171+
, _autoLockTimer([=] { checkAutoLock(); }) {
173172
Ui::Integration::Set(&_private->uiIntegration);
174173

175174
_platformIntegration->init();
@@ -693,9 +692,18 @@ bool Application::eventFilter(QObject *object, QEvent *e) {
693692
case QEvent::FileOpen: {
694693
if (object == QCoreApplication::instance()) {
695694
const auto event = static_cast<QFileOpenEvent*>(e);
695+
const auto flushQueued = [=] {
696+
if (_filesToOpen.isEmpty()) {
697+
InvokeQueued([=] {
698+
cSetSendPaths(_filesToOpen);
699+
_filesToOpen.clear();
700+
checkSendPaths();
701+
});
702+
}
703+
};
696704
if (const auto file = event->file(); !file.isEmpty()) {
705+
flushQueued();
697706
_filesToOpen.append(file);
698-
_fileOpenTimer.callOnce(kFileOpenTimeoutMs);
699707
} else if (event->url().scheme() == u"tg"_q
700708
|| event->url().scheme() == u"tonsite"_q) {
701709
const auto url = QString::fromUtf8(
@@ -707,8 +715,8 @@ bool Application::eventFilter(QObject *object, QEvent *e) {
707715
_lastActivePrimaryWindow->activate();
708716
}
709717
} else if (event->url().scheme() == u"interpret"_q) {
718+
flushQueued();
710719
_filesToOpen.append(event->url().toString());
711-
_fileOpenTimer.callOnce(kFileOpenTimeoutMs);
712720
}
713721
}
714722
} break;
@@ -1081,12 +1089,6 @@ bool Application::canApplyLangPackWithoutRestart() const {
10811089
return true;
10821090
}
10831091

1084-
void Application::checkFileOpen() {
1085-
cSetSendPaths(_filesToOpen);
1086-
_filesToOpen.clear();
1087-
checkSendPaths();
1088-
}
1089-
10901092
void Application::checkSendPaths() {
10911093
if (!cSendPaths().isEmpty()
10921094
&& _lastActivePrimaryWindow

Telegram/SourceFiles/core/application.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ class Application final : public QObject {
272272
// Internal links.
273273
void checkStartUrl();
274274
void checkSendPaths();
275-
void checkFileOpen();
276275
bool openLocalUrl(const QString &url, QVariant context);
277276
bool openInternalUrl(const QString &url, QVariant context);
278277
[[nodiscard]] QString changelogLink() const;
@@ -452,7 +451,6 @@ class Application final : public QObject {
452451
base::Timer _autoLockTimer;
453452

454453
QStringList _filesToOpen;
455-
base::Timer _fileOpenTimer;
456454

457455
std::optional<base::Timer> _saveSettingsTimer;
458456

0 commit comments

Comments
 (0)