Skip to content

Commit

Permalink
Browser: Fix cancel with database unlock dialog (#11435)
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu authored Nov 10, 2024
1 parent bff0b93 commit 2fc24be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public slots:

private slots:
void processClientMessage(QLocalSocket* socket, const QJsonObject& message);
void handleDatabaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget);

private:
enum Access
Expand Down
3 changes: 3 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/gui/MainWindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2024 KeePassXC Team <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2020 KeePassXC Team <[email protected]>
*
* 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
Expand Down Expand Up @@ -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 = {});
Expand Down

0 comments on commit 2fc24be

Please sign in to comment.