feat: add property Launcher, Orphaned
refactor some method which are related with systemd unit Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
@ -103,9 +103,11 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
|
||||
return;
|
||||
}
|
||||
|
||||
auto pair = processUnitName(unitName);
|
||||
auto appId = pair.first;
|
||||
auto instanceId = pair.second;
|
||||
auto info = processUnitName(unitName);
|
||||
auto appId = std::move(info.applicationID);
|
||||
auto launcher = std::move(info.Launcher);
|
||||
auto instanceId = std::move(info.instanceID);
|
||||
|
||||
if (appId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -132,7 +134,7 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
|
||||
|
||||
const auto &applicationPath = (*appIt)->applicationPath().path();
|
||||
|
||||
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path())) [[likely]] {
|
||||
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher)) [[likely]] {
|
||||
qCritical() << "add Instance failed:" << applicationPath << unitName << systemdUnitPath.path();
|
||||
}
|
||||
}
|
||||
@ -143,9 +145,11 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
|
||||
return;
|
||||
}
|
||||
|
||||
auto pair = processUnitName(unitName);
|
||||
auto appId = pair.first;
|
||||
auto instanceId = pair.second;
|
||||
auto info = processUnitName(unitName);
|
||||
auto appId = std::move(info.applicationID);
|
||||
auto launcher = std::move(info.Launcher);
|
||||
auto instanceId = std::move(info.instanceID);
|
||||
|
||||
if (appId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -163,12 +167,17 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
|
||||
|
||||
auto instanceIt =
|
||||
std::find_if(appIns.cbegin(), appIns.cend(), [&systemdUnitPath](const QSharedPointer<InstanceService> &value) {
|
||||
return value->systemdUnitPath() == systemdUnitPath;
|
||||
return value->property("SystemdUnitPath") == systemdUnitPath;
|
||||
});
|
||||
|
||||
if (instanceIt != appIns.cend()) [[likely]] {
|
||||
(*appIt)->removeOneInstance(instanceIt.key());
|
||||
return;
|
||||
}
|
||||
|
||||
orphanedInstances->removeIf([&systemdUnitPath](const QSharedPointer<InstanceService> &ptr) {
|
||||
return (ptr->property("SystemdUnitPath").value<QDBusObjectPath>() == systemdUnitPath);
|
||||
});
|
||||
}
|
||||
|
||||
void ApplicationManager1Service::scanApplications() noexcept
|
||||
@ -357,28 +366,28 @@ QString ApplicationManager1Service::Identify(const QDBusUnixFileDescriptor &pidf
|
||||
}
|
||||
|
||||
void ApplicationManager1Service::updateApplication(const QSharedPointer<ApplicationService> &destApp,
|
||||
const DesktopFile &desktopFile) noexcept
|
||||
DesktopFile desktopFile) noexcept
|
||||
{
|
||||
// TODO: add propertyChanged
|
||||
if (auto app = m_applicationList.find(destApp->applicationPath()); app == m_applicationList.cend()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto timeInfo = getFileTimeInfo(QFileInfo{desktopFile.sourceFileRef()});
|
||||
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||
if (newEntry == nullptr) {
|
||||
qCritical() << "new DesktopEntry failed.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (destApp->desktopFileSource().modified(timeInfo.mtime)) {
|
||||
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||
if (newEntry == nullptr) {
|
||||
qCritical() << "new DesktopEntry failed.";
|
||||
return;
|
||||
}
|
||||
auto err = newEntry->parse(desktopFile);
|
||||
if (err != DesktopErrorCode::NoError) {
|
||||
qWarning() << "update desktop file failed:" << err << ", content wouldn't change.";
|
||||
return;
|
||||
}
|
||||
|
||||
auto err = newEntry->parse(destApp->desktopFileSource());
|
||||
if (err != DesktopErrorCode::NoError) {
|
||||
qWarning() << "update desktop file failed:" << err << ", content wouldn't change.";
|
||||
return;
|
||||
}
|
||||
if (destApp->m_entry != newEntry) {
|
||||
destApp->resetEntry(newEntry);
|
||||
destApp->m_desktopSource = std::move(desktopFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -407,9 +416,9 @@ void ApplicationManager1Service::ReloadApplications()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (destApp != m_applicationList.cend()) {
|
||||
if (destApp != m_applicationList.cend() and apps.contains(destApp.key())) {
|
||||
apps.removeOne(destApp.key());
|
||||
updateApplication(destApp.value(), file);
|
||||
updateApplication(destApp.value(), std::move(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
void removeOneApplication(const QDBusObjectPath &application) noexcept;
|
||||
void removeAllApplication() noexcept;
|
||||
|
||||
void updateApplication(const QSharedPointer<ApplicationService> &destApp, const DesktopFile &desktopFile) noexcept;
|
||||
void updateApplication(const QSharedPointer<ApplicationService> &destApp, DesktopFile desktopFile) noexcept;
|
||||
|
||||
JobManager1Service &jobManager() noexcept { return *m_jobManager; }
|
||||
|
||||
|
@ -34,10 +34,8 @@ ApplicationService::ApplicationService(DesktopFile source,
|
||||
ApplicationService::~ApplicationService()
|
||||
{
|
||||
for (auto &instance : m_Instances.values()) {
|
||||
instance->m_Application = QDBusObjectPath{"/"};
|
||||
auto *ptr = instance.get();
|
||||
instance.reset(nullptr);
|
||||
ptr->setParent(qApp); // detach all instances to qApp
|
||||
orphanedInstances->append(instance);
|
||||
instance->m_orphaned = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,9 +463,12 @@ QList<QDBusObjectPath> ApplicationService::instances() const noexcept
|
||||
return m_Instances.keys();
|
||||
}
|
||||
|
||||
bool ApplicationService::addOneInstance(const QString &instanceId, const QString &application, const QString &systemdUnitPath)
|
||||
bool ApplicationService::addOneInstance(const QString &instanceId,
|
||||
const QString &application,
|
||||
const QString &systemdUnitPath,
|
||||
const QString &launcher)
|
||||
{
|
||||
auto *service = new InstanceService{instanceId, application, systemdUnitPath};
|
||||
auto *service = new InstanceService{instanceId, application, systemdUnitPath, launcher};
|
||||
auto *adaptor = new InstanceAdaptor(service);
|
||||
QString objectPath{m_applicationPath.path() + "/" + instanceId};
|
||||
|
||||
|
@ -86,7 +86,10 @@ public:
|
||||
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
|
||||
void setLauncher(const QString &launcher) noexcept { m_launcher = launcher; }
|
||||
|
||||
bool addOneInstance(const QString &instanceId, const QString &application, const QString &systemdUnitPath);
|
||||
bool addOneInstance(const QString &instanceId,
|
||||
const QString &application,
|
||||
const QString &systemdUnitPath,
|
||||
const QString &launcher);
|
||||
void recoverInstances(const QList<QDBusObjectPath> &instanceList) noexcept;
|
||||
void removeOneInstance(const QDBusObjectPath &instance) noexcept;
|
||||
void removeAllInstance() noexcept;
|
||||
|
@ -3,22 +3,14 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "dbus/instanceservice.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath)
|
||||
: m_instanceId(std::move(instanceId))
|
||||
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher)
|
||||
: m_Launcher(std::move(launcher))
|
||||
, m_instanceId(std::move(instanceId))
|
||||
, m_Application(std::move(application))
|
||||
, m_SystemdUnitPath(std::move(systemdUnitPath))
|
||||
{
|
||||
}
|
||||
|
||||
InstanceService::~InstanceService() = default;
|
||||
|
||||
QDBusObjectPath InstanceService::application() const
|
||||
{
|
||||
return m_Application;
|
||||
}
|
||||
|
||||
QDBusObjectPath InstanceService::systemdUnitPath() const
|
||||
{
|
||||
return m_SystemdUnitPath;
|
||||
}
|
||||
|
@ -18,20 +18,23 @@ public:
|
||||
InstanceService &operator=(const InstanceService &) = delete;
|
||||
InstanceService &operator=(InstanceService &&) = delete;
|
||||
|
||||
Q_PROPERTY(QDBusObjectPath Application READ application)
|
||||
[[nodiscard]] QDBusObjectPath application() const;
|
||||
|
||||
Q_PROPERTY(QDBusObjectPath SystemdUnitPath READ systemdUnitPath)
|
||||
[[nodiscard]] QDBusObjectPath systemdUnitPath() const;
|
||||
Q_PROPERTY(QDBusObjectPath Application MEMBER m_Application)
|
||||
Q_PROPERTY(QDBusObjectPath SystemdUnitPath MEMBER m_SystemdUnitPath)
|
||||
Q_PROPERTY(QString Launcher MEMBER m_Launcher)
|
||||
Q_PROPERTY(bool Orphaned MEMBER m_orphaned)
|
||||
|
||||
[[nodiscard]] const QString &instanceId() const noexcept { return m_instanceId; }
|
||||
|
||||
private:
|
||||
friend class ApplicationService;
|
||||
InstanceService(QString instanceId, QString application, QString systemdUnitPath);
|
||||
InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher);
|
||||
bool m_orphaned{false};
|
||||
QString m_Launcher;
|
||||
QString m_instanceId;
|
||||
QDBusObjectPath m_Application;
|
||||
QDBusObjectPath m_SystemdUnitPath;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(QList<QSharedPointer<InstanceService>>, orphanedInstances)
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user