Skip to content

Commit 85f7276

Browse files
committed
Revert Auto-Type change that caused race condition
* Fixes #12723
1 parent 967dc59 commit 85f7276

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/autotype/AutoType.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ namespace
115115
{"f14", Qt::Key_F14},
116116
{"f15", Qt::Key_F15},
117117
{"f16", Qt::Key_F16}};
118+
constexpr int s_minWaitDelay = 100; // 100 ms
119+
constexpr int s_maxWaitDelay = 10000; // 10 seconds
118120
} // namespace
119121

120122
AutoType* AutoType::m_instance = nullptr;
@@ -312,6 +314,9 @@ void AutoType::executeAutoTypeActions(const Entry* entry,
312314
// Restore executor mode
313315
m_executor->mode = mode;
314316

317+
// Initial Auto-Type delay to allow window to come to foreground
318+
Tools::wait(qBound(s_minWaitDelay, config()->get(Config::AutoTypeStartDelay).toInt(), s_maxWaitDelay));
319+
315320
// Grab the current active window after everything settles
316321
if (window == 0) {
317322
window = m_plugin->activeWindow();
@@ -543,16 +548,16 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
543548
}
544549

545550
const int maxTypeDelay = 500;
546-
const int maxWaitDelay = 10000;
547551
const int maxRepetition = 100;
552+
548553
int currentTypingDelay = qBound(0, config()->get(Config::AutoTypeDelay).toInt(), maxTypeDelay);
549-
int cumulativeDelay = qBound(0, config()->get(Config::AutoTypeStartDelay).toInt(), maxWaitDelay);
554+
// Take into account the initial delay which is added before any actions are performed
555+
int cumulativeDelay = qBound(s_minWaitDelay, config()->get(Config::AutoTypeStartDelay).toInt(), s_maxWaitDelay);
550556

551557
// Initial actions include start delay and initial inter-key delay
552558
QList<QSharedPointer<AutoTypeAction>> actions;
553559
actions << QSharedPointer<AutoTypeBegin>::create();
554560
actions << QSharedPointer<AutoTypeDelay>::create(currentTypingDelay, true);
555-
actions << QSharedPointer<AutoTypeDelay>::create(cumulativeDelay);
556561

557562
// Replace escaped braces with a template for easier regex
558563
QString sequence = entrySequence;
@@ -631,12 +636,12 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
631636
actions << QSharedPointer<AutoTypeDelay>::create(qBound(0, delay, maxTypeDelay), true);
632637
} else if (placeholder == "delay") {
633638
// Mid typing delay (wait), repeat represents the desired delay in milliseconds
634-
if (repeat > maxWaitDelay) {
635-
error = tr("Very long delay detected, max is %1: %2").arg(maxWaitDelay).arg(fullPlaceholder);
639+
if (repeat > s_maxWaitDelay) {
640+
error = tr("Very long delay detected, max is %1: %2").arg(s_maxWaitDelay).arg(fullPlaceholder);
636641
return {};
637642
}
638643
cumulativeDelay += repeat;
639-
actions << QSharedPointer<AutoTypeDelay>::create(qBound(0, repeat, maxWaitDelay));
644+
actions << QSharedPointer<AutoTypeDelay>::create(qBound(0, repeat, s_maxWaitDelay));
640645
} else if (placeholder == "clearfield") {
641646
// Platform-specific field clearing
642647
actions << QSharedPointer<AutoTypeClearField>::create();

0 commit comments

Comments
 (0)