refact: use graphical-session.target's InvocationID to determine
autostart Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
6368bf61cf
commit
6a95a97599
@ -64,6 +64,10 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
|||||||
|
|
||||||
scanInstances();
|
scanInstances();
|
||||||
|
|
||||||
|
if (auto *ptr = new (std::nothrow) PropertiesForwarder{DDEApplicationManager1ObjectPath, this}; ptr == nullptr) {
|
||||||
|
qCritical() << "new PropertiesForwarder of Application Manager failed.";
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: This is a workaround, we will use database at the end.
|
// TODO: This is a workaround, we will use database at the end.
|
||||||
auto runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
auto runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
||||||
if (runtimePath.isEmpty()) {
|
if (runtimePath.isEmpty()) {
|
||||||
@ -71,21 +75,23 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDir runtimeDir{runtimePath};
|
QDir runtimeDir{runtimePath};
|
||||||
auto filename = "deepin-application-manager";
|
const auto *filename = u8"deepin-application-manager";
|
||||||
if (runtimeDir.exists(filename)) {
|
QFile flag{runtimeDir.filePath(filename)};
|
||||||
return;
|
|
||||||
|
auto sessionId = getCurrentSessionId();
|
||||||
|
if (flag.open(QFile::ReadOnly | QFile::ExistingOnly)) {
|
||||||
|
auto content = flag.readAll();
|
||||||
|
if (!content.isEmpty() and !sessionId.isEmpty() and content == sessionId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
flag.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile flag{runtimeDir.filePath(filename)};
|
if (flag.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||||
if (!flag.open(QFile::WriteOnly | QFile::NewOnly)) {
|
flag.write(sessionId);
|
||||||
qWarning() << "create record file failed.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scanAutoStart();
|
scanAutoStart();
|
||||||
|
|
||||||
if (auto *ptr = new (std::nothrow) PropertiesForwarder{DDEApplicationManager1ObjectPath, this}; ptr == nullptr) {
|
|
||||||
qCritical() << "new PropertiesForwarder of Application Manager failed.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath)
|
void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath)
|
||||||
|
22
src/global.h
22
src/global.h
@ -17,6 +17,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QDBusObjectPath>
|
#include <QDBusObjectPath>
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
|
#include <QDBusMessage>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
@ -484,4 +485,25 @@ inline FileTimeInfo getFileTimeInfo(const QFileInfo &file)
|
|||||||
return {mtime, ctime, atime};
|
return {mtime, ctime, atime};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QByteArray getCurrentSessionId()
|
||||||
|
{
|
||||||
|
constexpr auto graphicalTarget = u8"graphical-session.target";
|
||||||
|
|
||||||
|
auto msg = QDBusMessage::createMethodCall("org.freedesktop.systemd1",
|
||||||
|
"/org/freedesktop/systemd1/unit/" + escapeToObjectPath(graphicalTarget),
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
"Get");
|
||||||
|
msg << QString{"org.freedesktop.systemd1.Unit"};
|
||||||
|
msg << QString{"InvocationID"};
|
||||||
|
auto bus = QDBusConnection::sessionBus();
|
||||||
|
auto ret = bus.call(msg);
|
||||||
|
if (ret.type() != QDBusMessage::ReplyMessage) {
|
||||||
|
qWarning() << "get graphical session Id failed:" << ret.errorMessage();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto id = ret.arguments().first();
|
||||||
|
return id.value<QDBusVariant>().variant().toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user