mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-31 10:39:14 -04:00
Fix Single Istance behavior
This commit is contained in:
parent
8ed8e57012
commit
cdad46377b
6 changed files with 236 additions and 10 deletions
|
@ -107,6 +107,7 @@ void Config::init(const QString& fileName)
|
|||
{
|
||||
m_settings.reset(new QSettings(fileName, QSettings::IniFormat));
|
||||
|
||||
m_defaults.insert("SingleInstance", true);
|
||||
m_defaults.insert("RememberLastDatabases", true);
|
||||
m_defaults.insert("RememberLastKeyFiles", true);
|
||||
m_defaults.insert("OpenPreviousDatabasesOnStartup", true);
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -57,13 +57,11 @@ int main(int argc, char** argv)
|
|||
// don't set organizationName as that changes the return value of
|
||||
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
|
||||
|
||||
#ifndef QT_DEBUG
|
||||
if (app.isAlreadyRunning()) {
|
||||
qWarning() << QCoreApplication::translate("Main", "Another instance of KeePassXC is already running.").toUtf8().constData();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
if (!Crypto::init()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue