mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-27 01:56:32 -05:00
Pass (using IPC) command line filenames to already running instance
This commit is contained in:
parent
7b9b23b143
commit
165d664524
5 changed files with 136 additions and 58 deletions
61
src/main.cpp
61
src/main.cpp
|
|
@ -57,22 +57,6 @@ int main(int argc, char** argv)
|
|||
// don't set organizationName as that changes the return value of
|
||||
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
|
||||
|
||||
if (app.isAlreadyRunning()) {
|
||||
qWarning() << QCoreApplication::translate("Main", "Another instance of KeePassXC is already running.").toUtf8().constData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
if (!Crypto::init()) {
|
||||
QString error = QCoreApplication::translate("Main",
|
||||
"Fatal error while testing the cryptographic functions.");
|
||||
error.append("\n");
|
||||
error.append(Crypto::errorString());
|
||||
MessageBox::critical(nullptr, QCoreApplication::translate("Main", "KeePassXC - Error"), error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QCoreApplication::translate("main", "KeePassXC - cross-platform password manager"));
|
||||
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "filenames of the password databases to open (*.kdbx)"), "[filename(s)]");
|
||||
|
|
@ -93,7 +77,26 @@ int main(int argc, char** argv)
|
|||
parser.addOption(pwstdinOption);
|
||||
|
||||
parser.process(app);
|
||||
const QStringList args = parser.positionalArguments();
|
||||
const QStringList fileNames = parser.positionalArguments();
|
||||
|
||||
if (app.isAlreadyRunning()) {
|
||||
if (!fileNames.isEmpty()) {
|
||||
app.sendFileNamesToRunningInstance(fileNames);
|
||||
}
|
||||
qWarning() << QCoreApplication::translate("Main", "Another instance of KeePassXC is already running.").toUtf8().constData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
if (!Crypto::init()) {
|
||||
QString error = QCoreApplication::translate("Main",
|
||||
"Fatal error while testing the cryptographic functions.");
|
||||
error.append("\n");
|
||||
error.append(Crypto::errorString());
|
||||
MessageBox::critical(nullptr, QCoreApplication::translate("Main", "KeePassXC - Error"), error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parser.isSet(configOption)) {
|
||||
Config::createConfigFromFile(parser.value(configOption));
|
||||
|
|
@ -109,15 +112,10 @@ int main(int argc, char** argv)
|
|||
MainWindow mainWindow;
|
||||
app.setMainWindow(&mainWindow);
|
||||
|
||||
QObject::connect(&app, &Application::anotherInstanceStarted,
|
||||
[&]() {
|
||||
mainWindow.ensurePolished();
|
||||
mainWindow.setWindowState(mainWindow.windowState() & ~Qt::WindowMinimized);
|
||||
mainWindow.show();
|
||||
mainWindow.raise();
|
||||
mainWindow.activateWindow();
|
||||
});
|
||||
QObject::connect(&app, SIGNAL(anotherInstanceStarted()), &mainWindow, SLOT(bringToFront()));
|
||||
QObject::connect(&app, SIGNAL(applicationActivated()), &mainWindow, SLOT(bringToFront()));
|
||||
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
|
||||
QObject::connect(&app, SIGNAL(quitSignalReceived()), &mainWindow, SLOT(appExit()), Qt::DirectConnection);
|
||||
|
||||
// start minimized if configured
|
||||
bool minimizeOnStartup = config()->get("GUI/MinimizeOnStartup").toBool();
|
||||
|
|
@ -130,20 +128,19 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
|
||||
const QStringList filenames = config()->get("LastOpenedDatabases").toStringList();
|
||||
for (int ii = filenames.size()-1; ii >= 0; ii--) {
|
||||
QString filename = filenames.at(ii);
|
||||
const QStringList fileNames = config()->get("LastOpenedDatabases").toStringList();
|
||||
for (const QString& filename: fileNames) {
|
||||
if (!filename.isEmpty() && QFile::exists(filename)) {
|
||||
mainWindow.openDatabase(filename, QString(), QString());
|
||||
mainWindow.openDatabase(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int ii=0; ii < args.length(); ii++) {
|
||||
QString filename = args[ii];
|
||||
const bool pwstdin = parser.isSet(pwstdinOption);
|
||||
for (const QString& filename: fileNames) {
|
||||
if (!filename.isEmpty() && QFile::exists(filename)) {
|
||||
QString password;
|
||||
if (parser.isSet(pwstdinOption)) {
|
||||
if (pwstdin) {
|
||||
static QTextStream in(stdin, QIODevice::ReadOnly);
|
||||
password = in.readLine();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue