Fix focus loss when using Auto-Type from locked database

* Fixes #10439
This commit is contained in:
Jonathan White 2024-04-05 19:27:35 -04:00
parent cb1ae44a3b
commit 35af1c6695
3 changed files with 18 additions and 17 deletions

View File

@ -271,7 +271,7 @@ void AutoType::executeAutoTypeActions(const Entry* entry,
MessageBox::critical(getMainWindow(), tr("Auto-Type Error"), errorMsg);
}
qWarning() << errorMsg;
emit autotypeRejected();
emit autotypeFinished();
return;
}
@ -318,13 +318,13 @@ void AutoType::executeAutoTypeActions(const Entry* entry,
}
for (const auto& action : asConst(actions)) {
// Cancel Auto-Type if the active window changed
if (m_plugin->activeWindow() != window) {
qWarning("Active window changed, interrupting auto-type.");
emit autotypeRejected();
m_inAutoType.unlock();
return;
break;
}
bool failed = false;
constexpr int max_retries = 5;
for (int i = 1; i <= max_retries; i++) {
auto result = action->exec(m_executor);
@ -339,20 +339,22 @@ void AutoType::executeAutoTypeActions(const Entry* entry,
if (getMainWindow()) {
MessageBox::critical(getMainWindow(), tr("Auto-Type Error"), result.errorString());
}
emit autotypeRejected();
m_inAutoType.unlock();
return;
failed = true;
break;
}
Tools::wait(delay);
}
// Last action failed to complete, cancel the rest of the sequence
if (failed) {
break;
}
}
m_windowForGlobal = 0;
m_windowTitleForGlobal.clear();
emit autotypePerformed();
resetAutoTypeState();
m_inAutoType.unlock();
emit autotypeFinished();
}
/**
@ -387,7 +389,7 @@ void AutoType::performAutoTypeWithSequence(const Entry* entry, const QString& se
void AutoType::startGlobalAutoType(const QString& search)
{
// Never Auto-Type into KeePassXC itself
if (qApp->focusWindow()) {
if (getMainWindow() && (qApp->activeWindow() || qApp->activeModalWidget())) {
return;
}
@ -495,7 +497,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
connect(selectDialog, &QDialog::rejected, this, [this] {
restoreWindowState();
resetAutoTypeState();
emit autotypeRejected();
emit autotypeFinished();
});
#ifdef Q_OS_MACOS
@ -512,7 +514,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
} else {
// We should never get here
resetAutoTypeState();
emit autotypeRejected();
emit autotypeFinished();
}
}

View File

@ -60,8 +60,7 @@ public slots:
signals:
void globalAutoTypeTriggered(const QString& search);
void autotypePerformed();
void autotypeRejected();
void autotypeFinished();
void autotypeRetypeTimeout();
private slots:

View File

@ -57,7 +57,7 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
m_dbWidgetStateSync, SLOT(setActive(DatabaseWidget*)));
connect(autoType(), SIGNAL(globalAutoTypeTriggered(const QString&)), SLOT(performGlobalAutoType(const QString&)));
connect(autoType(), SIGNAL(autotypeRetypeTimeout()), SLOT(relockPendingDatabase()));
connect(autoType(), SIGNAL(autotypeRejected()), SLOT(relockPendingDatabase()));
connect(autoType(), SIGNAL(autotypeFinished()), SLOT(relockPendingDatabase()));
connect(m_databaseOpenDialog.data(), &DatabaseOpenDialog::dialogFinished,
this, &DatabaseTabWidget::handleDatabaseUnlockDialogFinished);
// clang-format on