Skip to content

Commit

Permalink
Use unlock dialog when unlocking a database from browser extension
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu authored and droidmonkey committed May 19, 2020
1 parent 09f5a74 commit 92a7fe3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ BrowserService::BrowserService()
: QObject()
, m_browserHost(new BrowserHost)
, m_dialogActive(false)
, m_bringToFrontRequested(false)
, m_prevWindowState(WindowState::Normal)
, m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224"))
{
Expand Down Expand Up @@ -110,8 +109,7 @@ bool BrowserService::openDatabase(bool triggerUnlock)
}

if (triggerUnlock) {
m_bringToFrontRequested = true;
raiseWindow(true);
emit requestUnlock();
}

return false;
Expand Down Expand Up @@ -1220,6 +1218,23 @@ void BrowserService::raiseWindow(const bool force)
#endif
}

void BrowserService::updateWindowState()
{
m_prevWindowState = WindowState::Normal;
if (getMainWindow()->isMinimized()) {
m_prevWindowState = WindowState::Minimized;
}
#ifdef Q_OS_MACOS
if (macUtils()->isHidden()) {
m_prevWindowState = WindowState::Hidden;
}
#else
if (getMainWindow()->isHidden()) {
m_prevWindowState = WindowState::Hidden;
}
#endif
}

void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
{
if (dbWidget) {
Expand All @@ -1232,11 +1247,6 @@ void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget)
{
if (dbWidget) {
if (m_bringToFrontRequested) {
hideWindow();
m_bringToFrontRequested = false;
}

QJsonObject msg;
msg["action"] = QString("database-unlocked");
m_browserHost->sendClientMessage(msg);
Expand Down
5 changes: 4 additions & 1 deletion src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class BrowserService : public QObject
static const QString OPTION_ONLY_HTTP_AUTH;
static const QString ADDITIONAL_URL;

signals:
void requestUnlock();

public slots:
void databaseLocked(DatabaseWidget* dbWidget);
void databaseUnlocked(DatabaseWidget* dbWidget);
Expand Down Expand Up @@ -142,6 +145,7 @@ private slots:

void hideWindow() const;
void raiseWindow(const bool force = false);
void updateWindowState();

static bool moveSettingsToCustomData(Entry* entry, const QString& name);
static int moveKeysToCustomData(Entry* entry, QSharedPointer<Database> db);
Expand All @@ -150,7 +154,6 @@ private slots:
QHash<QString, QSharedPointer<BrowserAction>> m_browserClients;

bool m_dialogActive;
bool m_bringToFrontRequested;
WindowState m_prevWindowState;
QUuid m_keepassBrowserUUID;

Expand Down
8 changes: 8 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,3 +755,11 @@ void DatabaseTabWidget::performGlobalAutoType()
unlockDatabaseInDialog(currentDatabaseWidget(), DatabaseOpenDialog::Intent::AutoType);
}
}

void DatabaseTabWidget::performBrowserUnlock()
{
auto dbWidget = currentDatabaseWidget();
if (dbWidget && dbWidget->isLocked()) {
unlockDatabaseInDialog(dbWidget, DatabaseOpenDialog::Intent::Browser);
}
}
1 change: 1 addition & 0 deletions src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public slots:
void changeReports();
void changeDatabaseSettings();
void performGlobalAutoType();
void performBrowserUnlock();

signals:
void databaseOpened(DatabaseWidget* dbWidget);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ MainWindow::MainWindow()
&DatabaseTabWidget::activateDatabaseChanged,
browserService(),
&BrowserService::activeDatabaseChanged);
connect(
browserService(), &BrowserService::requestUnlock, m_ui->tabWidget, &DatabaseTabWidget::performBrowserUnlock);
#endif

#ifdef WITH_XC_SSHAGENT
Expand Down

0 comments on commit 92a7fe3

Please sign in to comment.