@@ -49,6 +49,18 @@ Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
4949#include < windows.h>
5050#endif
5151
52+ namespace
53+ {
54+ QString promptPassword ()
55+ {
56+ // we always need consume a line of STDIN if --pw-stdin is set to clear out the
57+ // buffer for native messaging, even if the specified file does not exist
58+ QTextStream out (stdout, QIODevice::WriteOnly);
59+ out << QObject::tr (" Database password: " ) << Qt::flush;
60+ return Utils::getPassword ();
61+ }
62+ } // namespace
63+
5264int main (int argc, char ** argv)
5365{
5466 QT_REQUIRE_VERSION (argc, argv, QT_VERSION_STR)
@@ -140,9 +152,14 @@ int main(int argc, char** argv)
140152 }
141153 }
142154#endif
155+ Utils::setDefaultTextStreams ();
156+
157+ const bool pwstdin = parser.isSet (pwstdinOption);
158+ const QString keyfile = parser.value (keyfileOption);
143159
144160 // Process single instance and early exit if already running
145161 if (app.isAlreadyRunning ()) {
162+ qWarning () << QObject::tr (" Another instance of KeePassXC is already running." ).toUtf8 ().constData ();
146163 if (parser.isSet (lockOption)) {
147164 if (app.sendLockToInstance ()) {
148165 qInfo () << QObject::tr (" Databases have been locked." ).toUtf8 ().constData ();
@@ -151,11 +168,13 @@ int main(int argc, char** argv)
151168 return EXIT_FAILURE;
152169 }
153170 } else {
154- if (!fileNames.isEmpty ()) {
155- app.sendFileNamesToRunningInstance (fileNames);
171+ for (const QString& filename : fileNames) {
172+ QString password;
173+ if (pwstdin) {
174+ password = promptPassword ();
175+ }
176+ app.sendUnlockToInstance (filename, password, keyfile);
156177 }
157-
158- qWarning () << QObject::tr (" Another instance of KeePassXC is already running." ).toUtf8 ().constData ();
159178 }
160179 return EXIT_SUCCESS;
161180 }
@@ -176,8 +195,6 @@ int main(int argc, char** argv)
176195 return EXIT_FAILURE;
177196 }
178197
179- Utils::setDefaultTextStreams ();
180-
181198 // Apply the configured theme before creating any GUI elements
182199 app.applyTheme ();
183200
@@ -195,17 +212,12 @@ int main(int argc, char** argv)
195212 // This ensures any top-level windows (Main Window, Modal Dialogs, etc.) are excluded from screenshots
196213 mainWindow.setAllowScreenCapture (parser.isSet (allowScreenCaptureOption));
197214
198- const bool pwstdin = parser.isSet (pwstdinOption);
199215 for (const QString& filename : fileNames) {
200216 QString password;
201217 if (pwstdin) {
202- // we always need consume a line of STDIN if --pw-stdin is set to clear out the
203- // buffer for native messaging, even if the specified file does not exist
204- QTextStream out (stdout, QIODevice::WriteOnly);
205- out << QObject::tr (" Database password: " ) << Qt::flush;
206- password = Utils::getPassword ();
218+ password = promptPassword ();
207219 }
208- mainWindow.openDatabase (filename, password, parser. value (keyfileOption) );
220+ mainWindow.openDatabase (filename, password, keyfile );
209221 }
210222
211223 // start minimized if configured
0 commit comments