From c029ae2bc20d3900243da68ca89d2fed38d13b22 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Sat, 27 Apr 2019 23:03:24 +0200 Subject: [PATCH] add --replace option to kdeconnectd --- daemon/kdeconnectd.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/daemon/kdeconnectd.cpp b/daemon/kdeconnectd.cpp index 5d622b66e..cfc7b2e2e 100644 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -22,6 +22,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -106,6 +110,21 @@ int main(int argc, char* argv[]) app.setQuitOnLastWindowClosed(false); app.setDesktopFileName(QStringLiteral("org.kde.kdeconnect.daemon")); + QCommandLineParser parser; + QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance")); + parser.addOption(replaceOption); + aboutData.setupCommandLine(&parser); + + parser.process(app); + aboutData.processCommandLine(&parser); + if (parser.isSet(replaceOption)) { + auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnectd"), + QStringLiteral("/MainApplication"), + QStringLiteral("org.qtproject.Qt.QCoreApplication"), + QStringLiteral("quit")); + QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits + } + KDBusService dbusService(KDBusService::Unique); DesktopDaemon daemon;