Backport: Prevent crash and resolve placeholders in Auto-Type dialog

* Modified backport of specific improvements introduced on develop branch. 

- Prevent crash when multiple screens are at play and QApplication::screenAt returns nullptr. 
- Resolve username/password when copying to clipboard from Auto-Type selection dialog.
This commit is contained in:
Jonathan White 2021-05-16 09:15:31 -04:00
parent bec7dafa91
commit 8f0e0b6f94
2 changed files with 19 additions and 7 deletions

View file

@ -52,18 +52,24 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
setWindowIcon(resources()->applicationIcon());
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QRect screenGeometry = QApplication::screenAt(QCursor::pos())->availableGeometry();
auto screen = QApplication::screenAt(QCursor::pos());
if (!screen) {
// screenAt can return a nullptr, default to the primary screen
screen = QApplication::primaryScreen();
}
QRect screenGeometry = screen->availableGeometry();
#else
QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos());
#endif
// Resize to last used size
QSize size = config()->get(Config::GUI_AutoTypeSelectDialogSize).toSize();
size.setWidth(qMin(size.width(), screenGeometry.width()));
size.setHeight(qMin(size.height(), screenGeometry.height()));
resize(size);
// move dialog to the center of the screen
QPoint screenCenter = screenGeometry.center();
move(screenCenter.x() - (size.width() / 2), screenCenter.y() - (size.height() / 2));
move(screenGeometry.center().x() - (size.width() / 2), screenGeometry.center().y() - (size.height() / 2));
QVBoxLayout* layout = new QVBoxLayout(this);

View file

@ -64,14 +64,20 @@ AutoTypeMatchView::AutoTypeMatchView(QWidget* parent)
void AutoTypeMatchView::userNameCopied()
{
clipboard()->setText(currentMatch().entry->username());
emit matchTextCopied();
auto entry = currentMatch().entry;
if (entry) {
clipboard()->setText(entry->resolvePlaceholder(entry->username()));
emit matchTextCopied();
}
}
void AutoTypeMatchView::passwordCopied()
{
clipboard()->setText(currentMatch().entry->password());
emit matchTextCopied();
auto entry = currentMatch().entry;
if (entry) {
clipboard()->setText(entry->resolvePlaceholder(entry->password()));
emit matchTextCopied();
}
}
void AutoTypeMatchView::keyPressEvent(QKeyEvent* event)