diff --git a/apps/dde-application-manager/src/utils.cpp b/apps/dde-application-manager/src/utils.cpp index 716c332..781497c 100644 --- a/apps/dde-application-manager/src/utils.cpp +++ b/apps/dde-application-manager/src/utils.cpp @@ -8,7 +8,7 @@ bool registerObjectToDBus(QObject *o, const QString &path, const QString &interf { auto &con = ApplicationManager1DBus::instance().globalServerBus(); if (!con.registerObject(path, interface, o, QDBusConnection::RegisterOption::ExportAdaptors)) { - qFatal() << "register object failed:" << path << interface << con.lastError(); + qCritical() << "register object failed:" << path << interface << con.lastError(); } else { qInfo() << "register object:" << path << interface; } diff --git a/examples/launchApp/README.md b/examples/launchApp/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/launchApp/main.cpp b/examples/launchApp/main.cpp index 524e68b..b59f56b 100644 --- a/examples/launchApp/main.cpp +++ b/examples/launchApp/main.cpp @@ -40,6 +40,7 @@ public: } } + // TODO: should be QList void launchApp(const QString &appId) { auto msg = diff --git a/src/dbus/applicationmanager1service.cpp b/src/dbus/applicationmanager1service.cpp index 10f433a..a9e4d86 100644 --- a/src/dbus/applicationmanager1service.cpp +++ b/src/dbus/applicationmanager1service.cpp @@ -29,30 +29,38 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptrid() == appId) [[unlikely]] { - const auto &applicationPath = app->m_applicationPath.path(); - if (!app->addOneInstance(instanceId, applicationPath, systemdUnitPath.path())) { - qWarning() << "add Instance failed:" << applicationPath << serviceName << systemdUnitPath.path(); - } - return; - } + auto appIt = std::find_if(m_applicationList.cbegin(), + m_applicationList.cend(), + [&appId](const QSharedPointer &app) { return app->id() == appId; }); + + if (appIt == m_applicationList.cend()) [[unlikely]] { + qWarning() << "couldn't find app" << appId << "in application manager."; + return; } - qWarning() << "couldn't find application:" << serviceName << "in application manager."; + const auto &appRef = *appIt; + const auto &applicationPath = appRef->m_applicationPath.path(); + + if (!appRef->addOneInstance(instanceId, applicationPath, systemdUnitPath.path())) [[likely]] { + qCritical() << "add Instance failed:" << applicationPath << unitName << systemdUnitPath.path(); + } + + return; }); connect(&dispatcher, &SystemdSignalDispatcher::SystemdUnitRemoved, this, [this](const QString &serviceName, QDBusObjectPath systemdUnitPath) { - auto pair = processServiceName(serviceName); + auto pair = processUnitName(serviceName); auto appId = pair.first; auto instanceId = pair.second; if (appId.isEmpty()) { @@ -82,14 +90,14 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr ApplicationManager1Service::processServiceName(const QString &serviceName) noexcept +QPair ApplicationManager1Service::processUnitName(const QString &unitName) noexcept { QString instanceId; QString applicationId; - if (serviceName.endsWith(".service")) { - auto lastDotIndex = serviceName.lastIndexOf('.'); - auto app = serviceName.sliced(0, lastDotIndex - 1); // remove suffix + if (unitName.endsWith(".service")) { + auto lastDotIndex = unitName.lastIndexOf('.'); + auto app = unitName.sliced(0, lastDotIndex - 1); // remove suffix if (app.contains('@')) { auto atIndex = app.indexOf('@'); @@ -98,15 +106,15 @@ QPair ApplicationManager1Service::processServiceName(const QSt } applicationId = app.split('-').last(); // drop launcher if it exists. - } else if (serviceName.endsWith(".scope")) { - auto lastDotIndex = serviceName.lastIndexOf('.'); - auto app = serviceName.sliced(0, lastDotIndex - 1); + } else if (unitName.endsWith(".scope")) { + auto lastDotIndex = unitName.lastIndexOf('.'); + auto app = unitName.sliced(0, lastDotIndex - 1); auto components = app.split('-'); instanceId = components.takeLast(); applicationId = components.takeLast(); } else { - qDebug() << "it's not service or scope:" << serviceName << "ignore."; + qDebug() << "it's not service or scope:" << unitName << "ignore."; return {}; } diff --git a/src/dbus/applicationmanager1service.h b/src/dbus/applicationmanager1service.h index cafde82..dd35874 100644 --- a/src/dbus/applicationmanager1service.h +++ b/src/dbus/applicationmanager1service.h @@ -61,7 +61,7 @@ private: QScopedPointer m_jobManager{nullptr}; QMap> m_applicationList; - static QPair processServiceName(const QString &serviceName) noexcept; + static QPair processUnitName(const QString &serviceName) noexcept; }; #endif diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index 1f67ce3..69ed66a 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -23,16 +23,6 @@ ApplicationService::~ApplicationService() } } -qsizetype ApplicationService::applicationCheck(const QString &serviceName) -{ - const auto &ApplicationId = id(); - if (!serviceName.startsWith(ApplicationId)) [[likely]] { - return 0; - } - - return ApplicationId.size(); -} - QString ApplicationService::GetActionName(const QString &identifier, const QStringList &env) { const auto &supportedActions = actions(); diff --git a/src/dbus/applicationservice.h b/src/dbus/applicationservice.h index 70d090a..b9a80a6 100644 --- a/src/dbus/applicationservice.h +++ b/src/dbus/applicationservice.h @@ -133,7 +133,6 @@ private: QSharedPointer m_Icons{nullptr}; QMap> m_Instances; QString userNameLookup(uid_t uid); - qsizetype applicationCheck(const QString &serviceName); [[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields); }; diff --git a/src/global.h b/src/global.h index 966b432..963c329 100644 --- a/src/global.h +++ b/src/global.h @@ -25,17 +25,15 @@ using IconMap = QMap> inline QString getApplicationLauncherBinary() { - static bool logFlag{true}; - auto value = qgetenv("DEEPIN_APPLICATION_MANAGER_APP_LAUNCH_HELPER_BIN"); - if (value.isEmpty()) { - return ApplicationLaunchHelperBinary; - } - - if (logFlag) { + static const QString bin = []() -> QString { + auto value = qgetenv("DEEPIN_APPLICATION_MANAGER_APP_LAUNCH_HELPER_BIN"); + if (value.isEmpty()) { + return ApplicationLaunchHelperBinary; + } qWarning() << "Using app launch helper defined in environment variable DEEPIN_APPLICATION_MANAGER_APP_LAUNCH_HELPER_BIN."; - logFlag = false; - } - return value; + return value; + }(); + return bin; } enum class DBusType { Session = QDBusConnection::SessionBus, System = QDBusConnection::SystemBus, Custom }; diff --git a/src/systemdsignaldispatcher.cpp b/src/systemdsignaldispatcher.cpp index bdda93b..cbbf5dd 100644 --- a/src/systemdsignaldispatcher.cpp +++ b/src/systemdsignaldispatcher.cpp @@ -31,20 +31,20 @@ bool SystemdSignalDispatcher::connectToSignals() noexcept return true; } -void SystemdSignalDispatcher::onUnitNew(QString serviceName, QDBusObjectPath systemdUnitPath) +void SystemdSignalDispatcher::onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath) { - if (!serviceName.startsWith("app-")) { + if (!unitName.startsWith("app-")) { return; } - emit SystemdUnitNew(serviceName.sliced(4), systemdUnitPath); // remove "app-" + emit SystemdUnitNew(unitName.sliced(sizeof("app-") - 1), systemdUnitPath); } -void SystemdSignalDispatcher::onUnitRemoved(QString serviceName, QDBusObjectPath systemdUnitPath) +void SystemdSignalDispatcher::onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath) { - if (!serviceName.startsWith("app-")) { + if (!unitName.startsWith("app-")) { return; } - emit SystemdUnitRemoved(serviceName.sliced(4), systemdUnitPath); + emit SystemdUnitRemoved(unitName.sliced(sizeof("app-") - 1), systemdUnitPath); } diff --git a/src/systemdsignaldispatcher.h b/src/systemdsignaldispatcher.h index 4818d59..d1f950b 100644 --- a/src/systemdsignaldispatcher.h +++ b/src/systemdsignaldispatcher.h @@ -18,12 +18,12 @@ public: return dispatcher; } Q_SIGNALS: - void SystemdUnitNew(QString serviceName, QDBusObjectPath systemdUnitPath); - void SystemdUnitRemoved(QString serviceName, QDBusObjectPath systemdUnitPath); + void SystemdUnitNew(QString unitName, QDBusObjectPath systemdUnitPath); + void SystemdUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath); private Q_SLOTS: - void onUnitNew(QString serviceName, QDBusObjectPath systemdUnitPath); - void onUnitRemoved(QString serviceName, QDBusObjectPath systemdUnitPath); + void onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath); + void onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath); private: explicit SystemdSignalDispatcher(QObject *parent = nullptr)