From 2fc24be331aaff2c7dfd5d809d2057e497f5471d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Mon, 11 Nov 2024 00:30:38 +0200 Subject: [PATCH] Browser: Fix cancel with database unlock dialog (#11435) --- src/browser/BrowserService.cpp | 13 +++++++++++++ src/browser/BrowserService.h | 1 + src/gui/DatabaseTabWidget.cpp | 3 +++ src/gui/MainWindow.cpp | 4 ++++ src/gui/MainWindow.h | 3 ++- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 38c812f943..9887e6d6aa 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -86,6 +86,10 @@ BrowserService::BrowserService() connect(getMainWindow(), &MainWindow::databaseUnlocked, this, &BrowserService::databaseUnlocked); connect(getMainWindow(), &MainWindow::databaseLocked, this, &BrowserService::databaseLocked); connect(getMainWindow(), &MainWindow::activeDatabaseChanged, this, &BrowserService::activeDatabaseChanged); + connect(getMainWindow(), + &MainWindow::databaseUnlockDialogFinished, + this, + &BrowserService::handleDatabaseUnlockDialogFinished); setEnabled(browserSettings()->isEnabled()); } @@ -1678,6 +1682,15 @@ void BrowserService::activeDatabaseChanged(DatabaseWidget* dbWidget) m_currentDatabaseWidget = dbWidget; } +void BrowserService::handleDatabaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget) +{ + // User canceled the database open dialog + if (dbWidget && !accepted && m_bringToFrontRequested) { + m_bringToFrontRequested = false; + hideWindow(); + } +} + void BrowserService::processClientMessage(QLocalSocket* socket, const QJsonObject& message) { auto clientID = message["clientID"].toString(); diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index 1c7ec5a37e..a77c945305 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -145,6 +145,7 @@ public slots: private slots: void processClientMessage(QLocalSocket* socket, const QJsonObject& message); + void handleDatabaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget); private: enum Access diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index d159352eb7..cf4328e037 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -821,6 +821,9 @@ void DatabaseTabWidget::handleDatabaseUnlockDialogFinished(bool accepted, Databa m_dbWidgetPendingLock = dbWidget; } + // If browser extension requested the unlock make sure cancel is handled + m_databaseOpenInProgress = false; + // signal other objects that the dialog finished emit databaseUnlockDialogFinished(accepted, dbWidget); } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 6d0c510e0d..b9fcee3f2f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -192,6 +192,10 @@ MainWindow::MainWindow() connect(m_ui->tabWidget, &DatabaseTabWidget::databaseLocked, this, &MainWindow::databaseLocked); connect(m_ui->tabWidget, &DatabaseTabWidget::databaseUnlocked, this, &MainWindow::databaseUnlocked); connect(m_ui->tabWidget, &DatabaseTabWidget::activeDatabaseChanged, this, &MainWindow::activeDatabaseChanged); + connect(m_ui->tabWidget, + &DatabaseTabWidget::databaseUnlockDialogFinished, + this, + &MainWindow::databaseUnlockDialogFinished); initViewMenu(); initActionCollection(); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 51a9f79424..b607a45660 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2024 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2020 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,6 +67,7 @@ class MainWindow : public QMainWindow void databaseUnlocked(DatabaseWidget* dbWidget); void databaseLocked(DatabaseWidget* dbWidget); void activeDatabaseChanged(DatabaseWidget* dbWidget); + void databaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget); public slots: void openDatabase(const QString& filePath, const QString& password = {}, const QString& keyfile = {});