Skip to content

Commit

Permalink
Prevent multiple lock requests on Linux
Browse files Browse the repository at this point in the history
* Fixes #11000

When the screen locks on e.g. gnome we receive multiple independent signals of that, namely the Gnome session manager and the gnome / freedesktop screensaver.

When this happens, this causes multiple "lock database" requests to be issued. The first one correctly shows the question to discard/cancel, but the second one while the first is still asking goes and dismisses the question and then goes to ask it again. The result is it acts like you didn't answer correctly (ie, to cancel) and the database is locked.
  • Loading branch information
droidmonkey committed Oct 7, 2024
1 parent 53bbc47 commit 36ec1aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,8 @@ bool DatabaseWidget::focusNextPrevChild(bool next)

bool DatabaseWidget::lock()
{
if (isLocked()) {
return true;
if (isLocked() || m_attemptingLock) {
return isLocked();
}

// Don't try to lock the database while saving, this will cause a deadlock
Expand All @@ -1797,6 +1797,8 @@ bool DatabaseWidget::lock()
return false;
}

m_attemptingLock = true;

emit databaseLockRequested();

// Force close any modal widgets associated with this widget
Expand All @@ -1821,6 +1823,7 @@ bool DatabaseWidget::lock()
MessageBox::Discard | MessageBox::Cancel,
MessageBox::Cancel);
if (result == MessageBox::Cancel) {
m_attemptingLock = false;
return false;
}
}
Expand All @@ -1847,9 +1850,11 @@ bool DatabaseWidget::lock()
MessageBox::Save);
if (result == MessageBox::Save) {
if (!save()) {
m_attemptingLock = false;
return false;
}
} else if (result == MessageBox::Cancel) {
m_attemptingLock = false;
return false;
}
}
Expand Down Expand Up @@ -1881,6 +1886,7 @@ bool DatabaseWidget::lock()
auto newDb = QSharedPointer<Database>::create(m_db->filePath());
replaceDatabase(newDb);

m_attemptingLock = false;
emit databaseLocked();

return true;
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private slots:
QUuid m_entryBeforeLock;

int m_saveAttempts;
bool m_attemptingLock = false;

// Search state
QScopedPointer<EntrySearcher> m_entrySearcher;
Expand Down

0 comments on commit 36ec1aa

Please sign in to comment.