From 6389063edae59a2eab7c80996b412cfca1639911 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Tue, 30 Jan 2024 14:19:15 +0800 Subject: [PATCH] The ID of the current Session is used to register the singleton process --- include/kernel/dguiapplicationhelper.h | 1 + src/kernel/dguiapplicationhelper.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/kernel/dguiapplicationhelper.h b/include/kernel/dguiapplicationhelper.h index 72e3577..d777a36 100644 --- a/include/kernel/dguiapplicationhelper.h +++ b/include/kernel/dguiapplicationhelper.h @@ -137,6 +137,7 @@ Q_SIGNALS: protected: explicit DGuiApplicationHelper(); virtual void initialize(); + static QString getSessionID(); private: D_PRIVATE_SLOT(void _q_initApplicationTheme(bool)) diff --git a/src/kernel/dguiapplicationhelper.cpp b/src/kernel/dguiapplicationhelper.cpp index f9b3fd1..913c410 100644 --- a/src/kernel/dguiapplicationhelper.cpp +++ b/src/kernel/dguiapplicationhelper.cpp @@ -491,6 +491,21 @@ void DGuiApplicationHelper::initialize() d->init(); } +QString DGuiApplicationHelper::getSessionID() +{ + QString sessionID = "0"; + + QDBusInterface *inter = new QDBusInterface("org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + QDBusConnection::sessionBus()); + + sessionID = inter->call("GetId").arguments().value(0).toString(); + inter->deleteLater(); + + return sessionID; +} + /*! \brief 创建 DGuiApplicationHelper 对象. @@ -1369,7 +1384,7 @@ bool DGuiApplicationHelper::setSingleInstance(const QString &key, DGuiApplicatio _d_singleServer->close(); } - QString socket_key = "_d_dtk_single_instance_"; + QString socket_key = QString("_d_dtk_single_instance_%1_").arg(getSessionID()); switch (singleScope) { case GroupScope: -- 2.20.1