fix: instance not add if service start after AM
try add instance on JobNew signal Issue: https://github.com/linuxdeepin/developer-center/issues/8879
This commit is contained in:
parent
2dcc4a12e6
commit
2cc1515229
@ -69,6 +69,32 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
|||||||
auto &dispatcher = SystemdSignalDispatcher::instance();
|
auto &dispatcher = SystemdSignalDispatcher::instance();
|
||||||
|
|
||||||
connect(&dispatcher, &SystemdSignalDispatcher::SystemdUnitNew, this, &ApplicationManager1Service::addInstanceToApplication);
|
connect(&dispatcher, &SystemdSignalDispatcher::SystemdUnitNew, this, &ApplicationManager1Service::addInstanceToApplication);
|
||||||
|
connect(&dispatcher, &SystemdSignalDispatcher::SystemdJobNew, this, [this](QString unitName, QDBusObjectPath systemdUnitPath){
|
||||||
|
auto info = processUnitName(unitName);
|
||||||
|
auto appId = std::move(info.applicationID);
|
||||||
|
|
||||||
|
if (appId.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto appIt = std::find_if(m_applicationList.cbegin(),
|
||||||
|
m_applicationList.cend(),
|
||||||
|
[&appId](const QSharedPointer<ApplicationService> &app) { return app->id() == appId; });
|
||||||
|
|
||||||
|
if (appIt == m_applicationList.cend()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 服务在 AM 之后启动那么 instance size 是 0, newJob 时尝试添加一次
|
||||||
|
// 比如 dde-file-manager.service 如果启动的比 AM 晚,那么在 scanInstances 时不会 addInstanceToApplication
|
||||||
|
if ((*appIt)->instances().size() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "add Instance " << unitName << "on JobNew";
|
||||||
|
|
||||||
|
addInstanceToApplication(unitName, systemdUnitPath);
|
||||||
|
});
|
||||||
|
|
||||||
connect(&dispatcher,
|
connect(&dispatcher,
|
||||||
&SystemdSignalDispatcher::SystemdUnitRemoved,
|
&SystemdSignalDispatcher::SystemdUnitRemoved,
|
||||||
|
@ -38,6 +38,16 @@ bool SystemdSignalDispatcher::connectToSignals() noexcept
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!con.connect(SystemdService,
|
||||||
|
SystemdObjectPath,
|
||||||
|
SystemdInterfaceName,
|
||||||
|
"JobNew",
|
||||||
|
this,
|
||||||
|
SLOT(onJobNew(uint32_t, QDBusObjectPath, QString)))) {
|
||||||
|
qCritical() << "can't connect to UnitNew signal of systemd service.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +67,11 @@ void SystemdSignalDispatcher::onUnitNew(QString unitName, QDBusObjectPath system
|
|||||||
emit SystemdUnitNew(unitName, systemdUnitPath);
|
emit SystemdUnitNew(unitName, systemdUnitPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemdSignalDispatcher::onJobNew(uint32_t, QDBusObjectPath systemdUnitPath, QString unitName)
|
||||||
|
{
|
||||||
|
emit SystemdJobNew(unitName, systemdUnitPath);
|
||||||
|
}
|
||||||
|
|
||||||
void SystemdSignalDispatcher::onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath)
|
void SystemdSignalDispatcher::onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath)
|
||||||
{
|
{
|
||||||
emit SystemdUnitRemoved(unitName, systemdUnitPath);
|
emit SystemdUnitRemoved(unitName, systemdUnitPath);
|
||||||
|
@ -20,11 +20,13 @@ public:
|
|||||||
}
|
}
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void SystemdUnitNew(QString unitName, QDBusObjectPath systemdUnitPath);
|
void SystemdUnitNew(QString unitName, QDBusObjectPath systemdUnitPath);
|
||||||
|
void SystemdJobNew(QString unitName, QDBusObjectPath systemdUnitPath);
|
||||||
void SystemdUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath);
|
void SystemdUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath);
|
||||||
void SystemdEnvironmentChanged(QStringList envs);
|
void SystemdEnvironmentChanged(QStringList envs);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath);
|
void onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath);
|
||||||
|
void onJobNew(uint32_t id, QDBusObjectPath systemdUnitPath, QString unitName);
|
||||||
void onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath);
|
void onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath);
|
||||||
void onPropertiesChanged(QString interface, QVariantMap props, QStringList invalid);
|
void onPropertiesChanged(QString interface, QVariantMap props, QStringList invalid);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user