feat: add filesystem watcher for reloading applications
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
#include <QHash>
|
||||
#include <QDBusMessage>
|
||||
#include <QStringBuilder>
|
||||
#include <chrono>
|
||||
#include <unistd.h>
|
||||
|
||||
ApplicationManager1Service::~ApplicationManager1Service() = default;
|
||||
@ -24,6 +25,8 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
||||
: m_identifier(std::move(ptr))
|
||||
, m_storage(std::move(storage))
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
m_reloadTimer.setInterval(1s);
|
||||
}
|
||||
|
||||
void ApplicationManager1Service::initService(QDBusConnection &connection) noexcept
|
||||
@ -61,6 +64,12 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &ApplicationManager1Service::ReloadApplications);
|
||||
auto unhandled = m_watcher.addPaths(getDesktopFileDirs());
|
||||
for (const auto &dir : unhandled) {
|
||||
qCritical() << "couldn't watch directory:" << dir;
|
||||
}
|
||||
|
||||
auto &dispatcher = SystemdSignalDispatcher::instance();
|
||||
|
||||
connect(&dispatcher, &SystemdSignalDispatcher::SystemdUnitNew, this, &ApplicationManager1Service::addInstanceToApplication);
|
||||
@ -604,6 +613,13 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
|
||||
|
||||
void ApplicationManager1Service::ReloadApplications()
|
||||
{
|
||||
if (m_reloadTimer.isActive()) {
|
||||
qInfo() << "reloadTimer is running, ignore...";
|
||||
return;
|
||||
}
|
||||
|
||||
m_reloadTimer.start();
|
||||
|
||||
const auto &desktopFileDirs = getDesktopFileDirs();
|
||||
|
||||
auto apps = m_applicationList.keys();
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <QScopedPointer>
|
||||
#include <memory>
|
||||
#include <QMap>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QTimer>
|
||||
#include "applicationmanagerstorage.h"
|
||||
#include "dbus/jobmanager1service.h"
|
||||
#include "dbus/mimemanager1service.h"
|
||||
@ -71,6 +73,8 @@ private:
|
||||
QScopedPointer<JobManager1Service> m_jobManager{nullptr};
|
||||
QStringList m_hookElements;
|
||||
QStringList m_systemdPathEnv;
|
||||
QFileSystemWatcher m_watcher;
|
||||
QTimer m_reloadTimer;
|
||||
QMap<QDBusObjectPath, QSharedPointer<ApplicationService>> m_applicationList;
|
||||
|
||||
void scanMimeInfos() noexcept;
|
||||
|
Reference in New Issue
Block a user