Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/dbus/applicationmanager1service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,27 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
qCCritical(DDEAM) << "open" << fileName << "failed:" << flag.errorString() << ", AM couldn't specify if it's a new session.";
}

void ApplicationManager1Service::addPendingInstanceLaunchType(const QString &instanceId, const QString &launchType) noexcept
{
m_pendingInstanceLaunchTypes.insert(instanceId, launchType);
}

void ApplicationManager1Service::removePendingInstanceLaunchType(const QString &instanceId) noexcept
{
m_pendingInstanceLaunchTypes.remove(instanceId);
}

QString ApplicationManager1Service::takePendingInstanceLaunchType(const QString &appId, const QString &instanceId) noexcept
{
auto launchType = m_pendingInstanceLaunchTypes.take(instanceId);
if (launchType.isEmpty()) {
qCWarning(DDEAM) << "missing pending launch type for app" << appId << "instance" << instanceId;
launchType = u"unknown"_s;
}

return launchType;
}

void ApplicationManager1Service::addInstanceToApplication(const QString &unitName,
const QDBusObjectPath &systemdUnitPath) noexcept
{
Expand Down Expand Up @@ -424,7 +445,9 @@ void ApplicationManager1Service::addInstanceToApplication(UnitInfo info, const Q

const auto &applicationPath = app->applicationPath().path();

if (!app->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher, app->launchType(), app->launchUniqueId())) {
const auto launchType = takePendingInstanceLaunchType(appId, instanceId);

if (!app->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher, launchType)) {
qCCritical(DDEAM) << "failed to add instance" << systemdUnitPath.path() << "to app" << appId;
}

Expand Down Expand Up @@ -480,7 +503,7 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
QStringLiteral("systemd result: %1").arg(result),
app->x_linglong(),
(*instanceIt)->launchType(),
(*instanceIt)->launchUniqueId());
(*instanceIt)->instanceId());
} else if (!result.isEmpty() && result != u"success"_s) {
QStringList logArgs{"--user", QStringLiteral("--unit=%1").arg(unitName),
"-p", "warning", "-n", "6", "-o", "cat", "-o", "with-unit", "--no-pager"};
Expand All @@ -501,7 +524,7 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
unitName,
logInfo,
app->x_linglong(),
(*instanceIt)->launchUniqueId());
(*instanceIt)->instanceId());
}

app->removeOneInstance(instanceIt.key());
Expand Down
6 changes: 6 additions & 0 deletions src/dbus/applicationmanager1service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public Q_SLOTS:
class ApplicationManager1Service final : public QObject, protected QDBusContext
{
Q_OBJECT
friend class ApplicationService;

public:
explicit ApplicationManager1Service(std::unique_ptr<Identifier> ptr,
std::weak_ptr<ApplicationManager1Storage> storage) noexcept;
Expand Down Expand Up @@ -131,6 +133,7 @@ private Q_SLOTS:
bool m_pendingReload{false};
QHash<QString, QSharedPointer<ApplicationService>> m_applicationList;
QHash<QString, QString> m_unitResults;
QHash<QString, QString> m_pendingInstanceLaunchTypes;
QSharedPointer<CompatibilityManager> m_compatibilityManager;
std::unique_ptr<PrelaunchSplashHelper> m_splashHelper;

Expand All @@ -139,6 +142,9 @@ private Q_SLOTS:
void scanInstances() noexcept;
void updateAutostartStatus() noexcept;
void loadHooks() noexcept;
void addPendingInstanceLaunchType(const QString &instanceId, const QString &launchType) noexcept;
void removePendingInstanceLaunchType(const QString &instanceId) noexcept;
QString takePendingInstanceLaunchType(const QString &appId, const QString &instanceId) noexcept;
void addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath) noexcept;
void addInstanceToApplication(UnitInfo info, const QDBusObjectPath &systemdUnitPath) noexcept;
void removeInstanceFromApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath) noexcept;
Expand Down
23 changes: 10 additions & 13 deletions src/dbus/applicationservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,8 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
if (launchType.isEmpty()) {
launchType = u"unknown"_s;
}
setLaunchType(launchType);
auto launchUniqueId = QUuid::createUuid().toString(QUuid::WithoutBraces);
setLaunchUniqueId(launchUniqueId);
qCDebug(DDEAM) << "launch app:" << id() << "launchType:" << launchType << "uniqueID:" << launchUniqueId;
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);
qCDebug(DDEAM) << "launch app:" << id() << "launchType:" << launchType << "uniqueID:" << instanceRandomUUID;

if (isAutostartLaunch) {
if (!parent()->isNewSession()) {
Expand Down Expand Up @@ -507,10 +505,7 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
cmds.push_back("-e"); // run all original execution commands in deepin-terminal
}

// Generate instance UUID early so splash and job lambda share the same id.
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);

EventReporter::reportAppLaunch(eventAppId(), QDateTime::currentMSecsSinceEpoch(), x_linglong(), launchType, launchUniqueId);
EventReporter::reportAppLaunch(eventAppId(), QDateTime::currentMSecsSinceEpoch(), x_linglong(), launchType, instanceRandomUUID);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

// Notify the compositor to show a splash screen (after validation passes).
if (isAutostartLaunch) {
Expand All @@ -532,10 +527,12 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
qCWarning(amPrelaunchSplash) << "Skip prelaunch splash (no parent ApplicationManager1Service)" << id();
}

parent()->addPendingInstanceLaunchType(instanceRandomUUID, launchType);

auto &jobManager = parent()->jobManager();
return jobManager.addJob(
m_applicationPath.path(),
[this, task, instanceRandomUUID = std::move(instanceRandomUUID), cmds = std::move(cmds), launchType, launchUniqueId](
[this, task, instanceRandomUUID = std::move(instanceRandomUUID), cmds = std::move(cmds), launchType](
const QVariant &value) mutable -> QVariant {
QStringList newCommands;
const int estimatedSize = 6 + cmds.size() + task.command.size() + (value.isValid() ? 1 : 0);
Expand Down Expand Up @@ -607,7 +604,8 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
QStringLiteral("app-launch-helper exited with code %1").arg(exitCode),
x_linglong(),
launchType,
launchUniqueId);
instanceRandomUUID);
parent()->removePendingInstanceLaunchType(instanceRandomUUID);
return QDBusError::Failed;
}

Expand Down Expand Up @@ -1087,10 +1085,9 @@ bool ApplicationService::addOneInstance(const QString &instanceId,
const QString &application,
const QString &systemdUnitPath,
const QString &launcher,
const QString &launchType,
const QString &uniqueId) noexcept
const QString &launchType) noexcept
{
auto *service = new (std::nothrow) InstanceService{instanceId, application, systemdUnitPath, launcher, launchType, uniqueId};
auto *service = new (std::nothrow) InstanceService{instanceId, application, systemdUnitPath, launcher, launchType};
if (service == nullptr) {
qCritical() << "couldn't new InstanceService.";
return false;
Expand Down
11 changes: 1 addition & 10 deletions src/dbus/applicationservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,14 @@ class ApplicationService : public QObject, protected QDBusContext
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
void setLauncher(const QString &launcher) noexcept { m_launcher = launcher; }

void setLaunchType(const QString &launchType) noexcept { m_launchType = launchType; }
[[nodiscard]] const QString &launchType() const noexcept { return m_launchType; }

void setLaunchUniqueId(const QString &uniqueId) noexcept { m_launchUniqueId = uniqueId; }
[[nodiscard]] const QString &launchUniqueId() const noexcept { return m_launchUniqueId; }

void setEventAppId(const QString &appId) noexcept { m_eventAppId = appId; }
[[nodiscard]] QString eventAppId() const noexcept { return m_eventAppId.isEmpty() ? id() : m_eventAppId; }

bool addOneInstance(const QString &instanceId,
const QString &application,
const QString &systemdUnitPath,
const QString &launcher,
const QString &launchType = {},
const QString &uniqueId = {}) noexcept;
const QString &launchType = {}) noexcept;
void recoverInstances(const QList<QDBusObjectPath> &instanceList) noexcept;
void removeOneInstance(const QDBusObjectPath &instance) noexcept;
void removeAllInstance() noexcept;
Expand Down Expand Up @@ -221,8 +214,6 @@ public Q_SLOTS:
QHash<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
QSet<QString> m_splashInstanceIds;
bool m_propertiesForwarderInitialized{false};
QString m_launchType;
QString m_launchUniqueId;
QString m_eventAppId;
void updateAfterLaunch(bool isLaunch) noexcept;
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
Expand Down
3 changes: 1 addition & 2 deletions src/dbus/instanceservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
#include <QDBusMessage>
#include "global.h"

InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher, const QString &launchType, const QString &uniqueId)
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher, const QString &launchType)
: m_Launcher(std::move(launcher))
, m_instanceId(std::move(instanceId))
, m_Application(std::move(application))
, m_SystemdUnitPath(std::move(systemdUnitPath))
, m_launchType(launchType)
, m_uniqueId(uniqueId)
{
if (auto *tmp = new (std::nothrow)
PropertiesForwarder{application + "/" + instanceId, fromStaticRaw(InstanceInterface), this};
Expand Down
4 changes: 1 addition & 3 deletions src/dbus/instanceservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class InstanceService : public QObject, protected QDBusContext

[[nodiscard]] const QString &instanceId() const noexcept { return m_instanceId; }
[[nodiscard]] const QString &launchType() const noexcept { return m_launchType; }
[[nodiscard]] const QString &launchUniqueId() const noexcept { return m_uniqueId; }

public Q_SLOTS:
void KillAll(int signal);
Expand All @@ -37,11 +36,10 @@ public Q_SLOTS:

private:
friend class ApplicationService;
InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher, const QString &launchType = {}, const QString &uniqueId = {});
InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher, const QString &launchType = {});
bool m_orphaned{false};
QString m_Launcher;
QString m_launchType;
QString m_uniqueId;
QString m_instanceId;
QDBusObjectPath m_Application;
QDBusObjectPath m_SystemdUnitPath;
Expand Down
Loading