mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-27 01:56:32 -05:00
Fix Single Istance behavior
This commit is contained in:
parent
8ed8e57012
commit
cdad46377b
6 changed files with 236 additions and 10 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "MainWindow.h"
|
||||
#include "core/Config.h"
|
||||
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QFileOpenEvent>
|
||||
|
|
@ -100,6 +101,10 @@ Application::Application(int& argc, char** argv)
|
|||
if (!userName.isEmpty()) {
|
||||
identifier.append("-");
|
||||
identifier.append(userName);
|
||||
#ifdef QT_DEBUG
|
||||
// In DEBUG mode don't interfere with Release instances
|
||||
identifier.append("-DEBUG");
|
||||
#endif
|
||||
}
|
||||
QString socketName = identifier + ".socket";
|
||||
QString lockName = identifier + ".lock";
|
||||
|
|
@ -119,12 +124,14 @@ Application::Application(int& argc, char** argv)
|
|||
alreadyRunning = true;
|
||||
// notify the other instance
|
||||
// try several times, in case the other instance is still starting up
|
||||
QLocalSocket client;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
client.connectToServer(socketName);
|
||||
if (client.waitForConnected(150)) {
|
||||
client.abort();
|
||||
break;
|
||||
if (config()->get("SingleInstance").toBool()) {
|
||||
QLocalSocket client;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
client.connectToServer(socketName);
|
||||
if (client.waitForConnected(150)) {
|
||||
client.abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -232,6 +239,10 @@ void Application::quitBySignal()
|
|||
|
||||
bool Application::isAlreadyRunning() const
|
||||
{
|
||||
return alreadyRunning;
|
||||
#ifdef QT_DEBUG
|
||||
// In DEBUG mode we can run unlimited instances
|
||||
return false;
|
||||
#endif
|
||||
return config()->get("SingleInstance").toBool() && alreadyRunning;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ void SettingsWidget::loadSettings()
|
|||
tr("Access error for config file %1").arg(config()->getFileName()), MessageWidget::Error);
|
||||
}
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
m_generalUi->singleInstanceCheckBox->setEnabled(false);
|
||||
#endif
|
||||
m_generalUi->singleInstanceCheckBox->setChecked(config()->get("SingleInstance").toBool());
|
||||
m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool());
|
||||
m_generalUi->rememberLastKeyFilesCheckBox->setChecked(config()->get("RememberLastKeyFiles").toBool());
|
||||
m_generalUi->openPreviousDatabasesOnStartupCheckBox->setChecked(
|
||||
|
|
@ -176,6 +180,7 @@ void SettingsWidget::saveSettings()
|
|||
return;
|
||||
}
|
||||
|
||||
config()->set("SingleInstance", m_generalUi->singleInstanceCheckBox->isChecked());
|
||||
config()->set("RememberLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked());
|
||||
config()->set("RememberLastKeyFiles", m_generalUi->rememberLastKeyFilesCheckBox->isChecked());
|
||||
config()->set("OpenPreviousDatabasesOnStartup",
|
||||
|
|
|
|||
|
|
@ -33,6 +33,16 @@
|
|||
<string>Basic Settings</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="singleInstanceCheckBox">
|
||||
<property name="text">
|
||||
<string>Start only a single instance of KeePassXC</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
|
||||
<property name="text">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue