Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Type: Allow retyping with automatic relock #7435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@
<source>will expire within </source>
<translation type="unfinished"></translation>
</message>
<message>
<source> s</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Re-lock previously locked database after performing Auto-Type</source>
<translation type="unfinished">Re-lock previously locked database after performing Auto-Type</translation>
</message>
<message>
<source>Remember last typed entry for:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ApplicationSettingsWidgetSecurity</name>
Expand Down Expand Up @@ -520,10 +532,6 @@
<source>Lock databases after minimizing the window</source>
<translation>Lock databases after minimizing the window</translation>
</message>
<message>
<source>Re-lock previously locked database after performing Auto-Type</source>
<translation>Re-lock previously locked database after performing Auto-Type</translation>
</message>
<message>
<source>Hide passwords in the entry preview panel</source>
<translation>Hide passwords in the entry preview panel</translation>
Expand Down
17 changes: 9 additions & 8 deletions src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ namespace
{"f14", Qt::Key_F14},
{"f15", Qt::Key_F15},
{"f16", Qt::Key_F16}};
static constexpr int rememberLastEntrySecs = 30;
} // namespace

AutoType* AutoType::m_instance = nullptr;
Expand All @@ -124,8 +123,15 @@ AutoType::AutoType(QObject* parent, bool test)
, m_windowState(WindowState::Normal)
, m_windowForGlobal(0)
, m_lastMatch(nullptr, QString())
, m_lastMatchTime(0)
, m_lastMatchRetypeTimer(nullptr)
{
// configure timer to reset last match
m_lastMatchRetypeTimer.setSingleShot(true);
connect(&m_lastMatchRetypeTimer, &QTimer::timeout, this, [this] {
m_lastMatch = {nullptr, QString()};
emit autotypeRetypeTimeout();
});

// prevent crash when the plugin has unresolved symbols
m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint);

Expand Down Expand Up @@ -426,11 +432,6 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
return;
}

// Invalidate last match if it's old enough
if (m_lastMatch.first && (Clock::currentSecondsSinceEpoch() - m_lastMatchTime) > rememberLastEntrySecs) {
m_lastMatch = {nullptr, QString()};
}

QList<AutoTypeMatch> matchList;
bool hideExpired = config()->get(Config::AutoTypeHideExpiredEntry).toBool();

Expand Down Expand Up @@ -468,7 +469,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
connect(getMainWindow(), &MainWindow::databaseLocked, selectDialog, &AutoTypeSelectDialog::reject);
connect(selectDialog, &AutoTypeSelectDialog::matchActivated, this, [this](const AutoTypeMatch& match) {
m_lastMatch = match;
m_lastMatchTime = Clock::currentSecondsSinceEpoch();
m_lastMatchRetypeTimer.start(config()->get(Config::GlobalAutoTypeRetypeTime).toInt() * 1000);
executeAutoTypeActions(match.first, nullptr, match.second, m_windowForGlobal);
resetAutoTypeState();
});
Expand Down
4 changes: 3 additions & 1 deletion src/autotype/AutoType.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <QMutex>
#include <QObject>
#include <QTimer>
#include <QWidget>

#include "AutoTypeMatch.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ public slots:
void globalAutoTypeTriggered(const QString& search);
void autotypePerformed();
void autotypeRejected();
void autotypeRetypeTimeout();

private slots:
void startGlobalAutoType(const QString& search);
Expand Down Expand Up @@ -98,7 +100,7 @@ private slots:
WindowState m_windowState;
WId m_windowForGlobal;
AutoTypeMatch m_lastMatch;
qint64 m_lastMatchTime;
QTimer m_lastMatchRetypeTimer;

Q_DISABLE_COPY(AutoType)
};
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::AutoTypeHideExpiredEntry,{QS("AutoTypeHideExpiredEntry"), Roaming, false}},
{Config::GlobalAutoTypeKey,{QS("GlobalAutoTypeKey"), Roaming, 0}},
{Config::GlobalAutoTypeModifiers,{QS("GlobalAutoTypeModifiers"), Roaming, 0}},
{Config::GlobalAutoTypeRetypeTime,{QS("GlobalAutoTypeRetypeTime"), Roaming, 15}},
{Config::FaviconDownloadTimeout,{QS("FaviconDownloadTimeout"), Roaming, 10}},
{Config::UpdateCheckMessageShown,{QS("UpdateCheckMessageShown"), Roaming, false}},
{Config::UseTouchID,{QS("UseTouchID"), Roaming, false}},
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Config : public QObject
AutoTypeHideExpiredEntry,
GlobalAutoTypeKey,
GlobalAutoTypeModifiers,
GlobalAutoTypeRetypeTime,
FaviconDownloadTimeout,
UpdateCheckMessageShown,
UseTouchID,
Expand Down
6 changes: 4 additions & 2 deletions src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void ApplicationSettingsWidget::loadSettings()
showExpiredEntriesOnDatabaseUnlockToggled(m_generalUi->showExpiredEntriesOnDatabaseUnlockCheckBox->isChecked());

m_generalUi->autoTypeAskCheckBox->setChecked(config()->get(Config::Security_AutoTypeAsk).toBool());
m_generalUi->autoTypeRelockDatabaseCheckBox->setChecked(config()->get(Config::Security_RelockAutoType).toBool());

if (autoType()->isAvailable()) {
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get(Config::GlobalAutoTypeKey).toInt());
Expand All @@ -268,6 +269,7 @@ void ApplicationSettingsWidget::loadSettings()
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
m_generalUi->autoTypeShortcutWidget->setShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
}
m_generalUi->autoTypeRetypeTimeSpinBox->setValue(config()->get(Config::GlobalAutoTypeRetypeTime).toInt());
m_generalUi->autoTypeShortcutWidget->setAttribute(Qt::WA_MacShowFocusRect, true);
m_generalUi->autoTypeDelaySpinBox->setValue(config()->get(Config::AutoTypeDelay).toInt());
m_generalUi->autoTypeStartDelaySpinBox->setValue(config()->get(Config::AutoTypeStartDelay).toInt());
Expand Down Expand Up @@ -297,7 +299,6 @@ void ApplicationSettingsWidget::loadSettings()
m_secUi->lockDatabaseMinimizeCheckBox->setChecked(config()->get(Config::Security_LockDatabaseMinimize).toBool());
m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked(
config()->get(Config::Security_LockDatabaseScreenLock).toBool());
m_secUi->relockDatabaseAutoTypeCheckBox->setChecked(config()->get(Config::Security_RelockAutoType).toBool());
m_secUi->fallbackToSearch->setChecked(config()->get(Config::Security_IconDownloadFallback).toBool());

m_secUi->passwordsHiddenCheckBox->setChecked(config()->get(Config::Security_PasswordsHidden).toBool());
Expand Down Expand Up @@ -392,11 +393,13 @@ void ApplicationSettingsWidget::saveSettings()
m_generalUi->showExpiredEntriesOnDatabaseUnlockOffsetSpinBox->value());

config()->set(Config::Security_AutoTypeAsk, m_generalUi->autoTypeAskCheckBox->isChecked());
config()->set(Config::Security_RelockAutoType, m_generalUi->autoTypeRelockDatabaseCheckBox->isChecked());

if (autoType()->isAvailable()) {
config()->set(Config::GlobalAutoTypeKey, m_generalUi->autoTypeShortcutWidget->key());
config()->set(Config::GlobalAutoTypeModifiers,
static_cast<int>(m_generalUi->autoTypeShortcutWidget->modifiers()));
config()->set(Config::GlobalAutoTypeRetypeTime, m_generalUi->autoTypeRetypeTimeSpinBox->value());
config()->set(Config::AutoTypeDelay, m_generalUi->autoTypeDelaySpinBox->value());
config()->set(Config::AutoTypeStartDelay, m_generalUi->autoTypeStartDelaySpinBox->value());
}
Expand All @@ -410,7 +413,6 @@ void ApplicationSettingsWidget::saveSettings()
config()->set(Config::Security_LockDatabaseIdleSeconds, m_secUi->lockDatabaseIdleSpinBox->value());
config()->set(Config::Security_LockDatabaseMinimize, m_secUi->lockDatabaseMinimizeCheckBox->isChecked());
config()->set(Config::Security_LockDatabaseScreenLock, m_secUi->lockDatabaseOnScreenLockCheckBox->isChecked());
config()->set(Config::Security_RelockAutoType, m_secUi->relockDatabaseAutoTypeCheckBox->isChecked());
config()->set(Config::Security_IconDownloadFallback, m_secUi->fallbackToSearch->isChecked());

config()->set(Config::Security_PasswordsHidden, m_secUi->passwordsHiddenCheckBox->isChecked());
Expand Down
148 changes: 89 additions & 59 deletions src/gui/ApplicationSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,15 @@
<property name="accessibleName">
<string>On database unlock, show entries that </string>
</property>
<property name="prefix">
<string>will expire within </string>
<property name="specialValueText">
<string>are expired</string>
</property>
<property name="suffix">
<string> days</string>
</property>
<property name="prefix">
<string>will expire within </string>
</property>
<property name="minimum">
<number>0</number>
</property>
Expand All @@ -281,9 +284,6 @@
<property name="value">
<number>0</number>
</property>
<property name="specialValueText">
<string>are expired</string>
</property>
</widget>
</item>
<item row="0" column="2">
Expand Down Expand Up @@ -1020,6 +1020,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoTypeRelockDatabaseCheckBox">
<property name="text">
<string>Re-lock previously locked database after performing Auto-Type</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
Expand All @@ -1045,57 +1052,32 @@
<number>8</number>
</property>
<item row="2" column="0">
<widget class="QLabel" name="autoTypeDelayLabel">
<widget class="QLabel" name="autoTypeStartDelayLabel">
<property name="text">
<string>Auto-Type typing delay:</string>
<string>Auto-Type start delay:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>autoTypeDelaySpinBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ShortcutWidget" name="autoTypeShortcutWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName">
<string>Global auto-type shortcut</string>
<cstring>autoTypeStartDelaySpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="autoTypeDelaySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName">
<string>Auto-type character typing delay milliseconds</string>
</property>
<property name="suffix">
<string comment="Milliseconds"> ms</string>
</property>
<property name="prefix">
<string/>
<item row="0" column="0">
<widget class="QLabel" name="autoTypeShortcutLabel">
<property name="text">
<string>Global Auto-Type shortcut:</string>
</property>
<property name="maximum">
<number>1000</number>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="value">
<number>25</number>
<property name="buddy">
<cstring>autoTypeShortcutWidget</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="autoTypeStartDelaySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand Down Expand Up @@ -1126,29 +1108,16 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="autoTypeShortcutLabel">
<property name="text">
<string>Global Auto-Type shortcut:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>autoTypeShortcutWidget</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="autoTypeStartDelayLabel">
<item row="3" column="0">
<widget class="QLabel" name="autoTypeDelayLabel">
<property name="text">
<string>Auto-Type start delay:</string>
<string>Auto-Type typing delay:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>autoTypeStartDelaySpinBox</cstring>
<cstring>autoTypeDelaySpinBox</cstring>
</property>
</widget>
</item>
Expand All @@ -1165,6 +1134,67 @@
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="ShortcutWidget" name="autoTypeShortcutWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName">
<string>Global auto-type shortcut</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="autoTypeDelaySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName">
<string>Auto-type character typing delay milliseconds</string>
</property>
<property name="suffix">
<string comment="Milliseconds"> ms</string>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>25</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="autoTypeRetypeLabel">
<property name="text">
<string>Remember last typed entry for:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="autoTypeRetypeTimeSpinBox">
<property name="suffix">
<string> s</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>60</number>
</property>
<property name="value">
<number>15</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
8 changes: 0 additions & 8 deletions src/gui/ApplicationSettingsWidgetSecurity.ui
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="relockDatabaseAutoTypeCheckBox">
<property name="text">
<string>Re-lock previously locked database after performing Auto-Type</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="passwordsRepeatVisibleCheckBox">
<property name="text">
Expand Down Expand Up @@ -320,7 +313,6 @@
<tabstop>lockDatabaseOnScreenLockCheckBox</tabstop>
<tabstop>touchIDResetOnScreenLockCheckBox</tabstop>
<tabstop>lockDatabaseMinimizeCheckBox</tabstop>
<tabstop>relockDatabaseAutoTypeCheckBox</tabstop>
<tabstop>passwordsRepeatVisibleCheckBox</tabstop>
<tabstop>passwordsHiddenCheckBox</tabstop>
<tabstop>passwordShowDotsCheckBox</tabstop>
Expand Down
Loading