From 569a303ba9a01a5853d148946eaf18070c86ebb7 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 1 Nov 2019 02:10:49 +0100 Subject: [PATCH] Let KDBusService deal with the replace option Summary: Depends on D22946 Test Plan: Replaced my plasmashell and krunner processes Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D22967 --- krunner/main.cpp | 10 +--------- shell/main.cpp | 16 +++------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/krunner/main.cpp b/krunner/main.cpp index cc46cc217..4f67a7fd1 100644 --- a/krunner/main.cpp +++ b/krunner/main.cpp @@ -85,19 +85,11 @@ int main(int argc, char **argv) parser.process(app); aboutData.processCommandLine(&parser); - if (parser.isSet(replaceOption)) { - auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.krunner"), - 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 - } - if (!KAuthorized::authorize(QStringLiteral("run_command"))) { return -1; } - KDBusService service(KDBusService::Unique); + KDBusService service(KDBusService::Unique | KDBusService::StartupOption(parser.isSet(replaceOption) ? KDBusService::Replace : 0)); QGuiApplication::setFallbackSessionManagementEnabled(false); diff --git a/shell/main.cpp b/shell/main.cpp index 4caca65ba..f63735e68 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -88,11 +88,11 @@ int main(int argc, char *argv[]) app.setQuitOnLastWindowClosed(false); - KSharedConfig::Ptr startupConf = KSharedConfig::openConfig(QStringLiteral("plasmashellrc")); KConfigGroup startupConfGroup(startupConf, "Shell"); const QString defaultShell = startupConfGroup.readEntry("ShellPackage", "org.kde.plasma.desktop"); + bool replace = false; { QCommandLineParser cliOptions; @@ -177,17 +177,6 @@ int main(int argc, char *argv[]) qApp->setProperty("_plasma_dbus_master", true); } - if (cliOptions.isSet(replaceOption)) { - auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), - QStringLiteral("/MainApplication"), - QStringLiteral("org.qtproject.Qt.QCoreApplication"), - QStringLiteral("quit")); - auto reply = QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits - - while (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.plasmashell"))) { - QCoreApplication::processEvents(QEventLoop::AllEvents); - } - } QObject::connect(corona, &ShellCorona::glInitializationFailed, &app, [&app]() { //scene graphs errors come from a thread //even though we process them in the main thread, app.exit could still process these events @@ -210,9 +199,10 @@ int main(int argc, char *argv[]) } app.exit(-1); }); + replace = cliOptions.isSet(replaceOption); } - KDBusService service(KDBusService::Unique); + KDBusService service(KDBusService::Unique | KDBusService::StartupOption(replace ? KDBusService::Replace : 0)); SoftwareRendererNotifier::notifyIfRelevant();