From bbe0551ffb07b6dc5b5e4e016e4f24060b5569a5 Mon Sep 17 00:00:00 2001 From: ComixHe Date: Fri, 15 Sep 2023 17:14:58 +0800 Subject: [PATCH] fix: launch autostart application after scaleFactor has been set Signed-off-by: ComixHe --- ...desktopspec.ApplicationManager1.service.in | 3 ++ src/dbus/applicationmanager1service.cpp | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/misc/systemd/user/org.desktopspec.ApplicationManager1.service.in b/misc/systemd/user/org.desktopspec.ApplicationManager1.service.in index 3b85497..5ddeac7 100644 --- a/misc/systemd/user/org.desktopspec.ApplicationManager1.service.in +++ b/misc/systemd/user/org.desktopspec.ApplicationManager1.service.in @@ -9,6 +9,9 @@ RefuseManualStop=no StartLimitBurst=3 CollectMode=inactive-or-failed +Requisite=dde-session-pre.target +After=dde-session-pre.target + Requisite=dde-session-initialized.target PartOf=dde-session-initialized.target Before=dde-session-initialized.target diff --git a/src/dbus/applicationmanager1service.cpp b/src/dbus/applicationmanager1service.cpp index f474fb7..6dac30e 100644 --- a/src/dbus/applicationmanager1service.cpp +++ b/src/dbus/applicationmanager1service.cpp @@ -97,7 +97,37 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce flag.write(sessionId, sessionId.size()); } - scanAutoStart(); + constexpr auto XSettings = "org.deepin.dde.XSettings1"; + + auto *watcher = + new QDBusServiceWatcher{XSettings, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this}; + + auto *sigCon = new QMetaObject::Connection{}; + + auto singleSlot = [this, watcher, sigCon]() { + QObject::disconnect(*sigCon); + delete sigCon; + qDebug() << XSettings << "is registered."; + scanAutoStart(); + watcher->deleteLater(); + }; + + *sigCon = connect(watcher, &QDBusServiceWatcher::serviceRegistered, std::move(singleSlot)); + + auto msg = + QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner"); + msg << XSettings; + + auto reply = QDBusConnection::sessionBus().call(msg); + if (reply.type() != QDBusMessage::ReplyMessage) { + qWarning() << "call org.freedesktop.DBus::NameHasOwner failed, skip autostart:" << reply.errorMessage(); + // ... + return; + } + + if (reply.arguments().first().toBool()) { + singleSlot(); + } } void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath)