summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-03-27 13:31:20 +0200
committerJan Grulich <[email protected]>2017-03-27 13:31:20 +0200
commit8f9bb31bd19b8f50423f26f14c56e971655b373e (patch)
treeeab5e49bcd5d948c23b0bb856b96b0adde0fe54b
parent3449a0039db481af206b123cccfc2cbcbf695a1b (diff)
Flatpak notifier: use monitor to watch flatpak installations and re-check updates on change
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp52
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakNotifier.h6
2 files changed, 46 insertions, 12 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp b/libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp
index 528351d..6ce7d29 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp
@@ -27,6 +27,21 @@
#include <QDebug>
#include <QTimer>
+static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, gpointer self)
+{
+ Q_UNUSED(monitor);
+ Q_UNUSED(child);
+ Q_UNUSED(other_file);
+ Q_UNUSED(event_type);
+
+ FlatpakNotifier *notifier = (FlatpakNotifier*)self;
+ if (!notifier) {
+ return;
+ }
+
+ notifier->checkUpdates();
+}
+
FlatpakNotifier::FlatpakNotifier(QObject* parent)
: BackendNotifierModule(parent)
, m_userInstallationUpdates(0)
@@ -34,18 +49,17 @@ FlatpakNotifier::FlatpakNotifier(QObject* parent)
{
m_cancellable = g_cancellable_new();
- doDailyCheck();
+ checkUpdates();
QTimer *dailyCheck = new QTimer(this);
dailyCheck->setInterval(24 * 60 * 60 * 1000); //refresh at least once every day
- connect(dailyCheck, &QTimer::timeout, this, &FlatpakNotifier::doDailyCheck);
-
- // TODO install GFileMonitor and watch every change in flatpak installations so we re-check
- // updates on app removal etc.
+ connect(dailyCheck, &QTimer::timeout, this, &FlatpakNotifier::checkUpdates);
}
FlatpakNotifier::~FlatpakNotifier()
{
+ g_object_unref(m_userInstallationMonitor);
+ g_object_unref(m_systemInstallationMonitor);
g_object_unref(m_flatpakInstallationSystem);
g_object_unref(m_flatpakInstallationUser);
g_object_unref(m_cancellable);
@@ -53,9 +67,7 @@ FlatpakNotifier::~FlatpakNotifier()
void FlatpakNotifier::recheckSystemUpdateNeeded()
{
- // Load updates from remote repositories
- loadRemoteUpdates(m_flatpakInstallationSystem);
- loadRemoteUpdates(m_flatpakInstallationUser);
+ checkUpdates();
}
bool FlatpakNotifier::isSystemUpToDate() const
@@ -73,7 +85,7 @@ uint FlatpakNotifier::updatesCount()
return m_systemInstallationUpdates + m_userInstallationUpdates;
}
-void FlatpakNotifier::doDailyCheck()
+void FlatpakNotifier::checkUpdates()
{
g_autoptr(GError) error = nullptr;
@@ -81,7 +93,9 @@ void FlatpakNotifier::doDailyCheck()
if (!setupFlatpakInstallations(&error)) {
qWarning() << "Failed to setup flatpak installations: " << error->message;
} else {
- recheckSystemUpdateNeeded();
+ // Load updates from remote repositories
+ loadRemoteUpdates(m_flatpakInstallationSystem);
+ loadRemoteUpdates(m_flatpakInstallationUser);
}
}
@@ -141,6 +155,24 @@ bool FlatpakNotifier::setupFlatpakInstallations(GError **error)
}
}
+ if (!m_systemInstallationMonitor) {
+ m_systemInstallationMonitor = flatpak_installation_create_monitor(m_flatpakInstallationSystem, m_cancellable, error);
+ if (!m_systemInstallationMonitor) {
+ return false;
+ }
+
+ g_signal_connect(m_systemInstallationMonitor, "changed", G_CALLBACK(installationChanged), this);
+ }
+
+ if (!m_userInstallationMonitor) {
+ m_userInstallationMonitor = flatpak_installation_create_monitor(m_flatpakInstallationUser, m_cancellable, error);
+ if (!m_userInstallationMonitor) {
+ return false;
+ }
+
+ g_signal_connect(m_userInstallationMonitor, "changed", G_CALLBACK(installationChanged), this);
+ }
+
return true;
}
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakNotifier.h b/libdiscover/backends/FlatpakBackend/FlatpakNotifier.h
index 2d94880..f4f5e02 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakNotifier.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakNotifier.h
@@ -41,8 +41,8 @@ public:
uint securityUpdatesCount() override;
uint updatesCount() override;
-private Q_SLOTS:
- void doDailyCheck();
+public Q_SLOTS:
+ void checkUpdates();
void onFetchUpdatesFinished(FlatpakInstallation *flatpakInstallation, GPtrArray *updates);
private:
@@ -52,6 +52,8 @@ private:
uint m_userInstallationUpdates;
uint m_systemInstallationUpdates;
GCancellable *m_cancellable;
+ GFileMonitor *m_userInstallationMonitor = nullptr;
+ GFileMonitor *m_systemInstallationMonitor = nullptr;
FlatpakInstallation *m_flatpakInstallationUser = nullptr;
FlatpakInstallation *m_flatpakInstallationSystem = nullptr;
};