feat: scan existing systemd unit

We should scan existing systemd unit when we start application manager.
As application manager crash and restarted later,
we can get the launched application instances back.
This commit is contained in:
black-desk
2023-08-28 17:57:21 +08:00
parent 02317993c8
commit 6adc02375f
4 changed files with 134 additions and 66 deletions

View File

@ -44,21 +44,7 @@ int main(int argc, char *argv[])
registerComplexDbusType();
ApplicationManager1Service AMService{std::make_unique<CGroupsIdentifier>(), AMBus};
QList<DesktopFile> fileList{};
const auto &desktopFileDirs = getDesktopFileDirs();
applyIteratively(QList<QDir>(desktopFileDirs.cbegin(), desktopFileDirs.cend()), [&AMService](const QFileInfo &info) -> bool {
DesktopErrorCode err{DesktopErrorCode::NoError};
auto ret = DesktopFile::searchDesktopFileByPath(info.absoluteFilePath(), err);
if (!ret.has_value()) {
qWarning() << "failed to search File:" << err;
return false;
}
if (!AMService.addApplication(std::move(ret).value())) {
qWarning() << "add Application failed, skip...";
}
return false; // means to apply this function to the rest of the files
});
#ifdef PROFILING_MODE
auto end = std::chrono::high_resolution_clock::now();
qCInfo(DDEAMProf) << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms";