117 lines
3.9 KiB
Diff
117 lines
3.9 KiB
Diff
|
From 1b0c476d66f89332187da2894b06ec2d4b83fa2a Mon Sep 17 00:00:00 2001
|
||
|
From: Milan Crha <mcrha@redhat.com>
|
||
|
Date: Thu, 30 Sep 2021 16:28:11 +0200
|
||
|
Subject: [PATCH 1/2] gs-update-monitor: Use wall-clock time for
|
||
|
one-notification-per-day check
|
||
|
|
||
|
Instead of using the g_timeout_add_seconds(), which uses a monotonic time,
|
||
|
which may or may not increase when the machine is suspended, rather use
|
||
|
the wall-clock time, to avoid issues with machine suspend where the monotonic
|
||
|
time does not increase.
|
||
|
---
|
||
|
src/gs-update-monitor.c | 31 +++++++++++++------------------
|
||
|
1 file changed, 13 insertions(+), 18 deletions(-)
|
||
|
|
||
|
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
|
||
|
index bde39fbbb..787c605a1 100644
|
||
|
--- a/src/gs-update-monitor.c
|
||
|
+++ b/src/gs-update-monitor.c
|
||
|
@@ -44,7 +44,8 @@ struct _GsUpdateMonitor {
|
||
|
guint check_startup_id; /* 60s after startup */
|
||
|
guint check_hourly_id; /* and then every hour */
|
||
|
guint check_daily_id; /* every 3rd day */
|
||
|
- guint notification_blocked_id; /* rate limit notifications */
|
||
|
+
|
||
|
+ gint64 last_notification_time_usec; /* to notify once per day only */
|
||
|
};
|
||
|
|
||
|
G_DEFINE_TYPE (GsUpdateMonitor, gs_update_monitor, G_TYPE_OBJECT)
|
||
|
@@ -88,14 +89,6 @@ with_app_data_free (WithAppData *data)
|
||
|
|
||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(WithAppData, with_app_data_free);
|
||
|
|
||
|
-static gboolean
|
||
|
-reenable_offline_update_notification (gpointer data)
|
||
|
-{
|
||
|
- GsUpdateMonitor *monitor = data;
|
||
|
- monitor->notification_blocked_id = 0;
|
||
|
- return G_SOURCE_REMOVE;
|
||
|
-}
|
||
|
-
|
||
|
static void
|
||
|
check_updates_kind (GsAppList *apps,
|
||
|
gboolean *out_has_important,
|
||
|
@@ -265,16 +258,22 @@ notify_about_pending_updates (GsUpdateMonitor *monitor,
|
||
|
GsAppList *apps)
|
||
|
{
|
||
|
const gchar *title = NULL, *body = NULL;
|
||
|
+ gint64 time_diff_sec;
|
||
|
g_autoptr(GNotification) nn = NULL;
|
||
|
|
||
|
- if (monitor->notification_blocked_id > 0)
|
||
|
+ time_diff_sec = (g_get_real_time () - monitor->last_notification_time_usec) / G_USEC_PER_SEC;
|
||
|
+ if (time_diff_sec < SECONDS_IN_A_DAY) {
|
||
|
+ g_debug ("Skipping update notification daily check, because made one only %" G_GINT64_FORMAT "s ago",
|
||
|
+ time_diff_sec);
|
||
|
return;
|
||
|
+ }
|
||
|
|
||
|
- /* rate limit update notifications to once per day */
|
||
|
- monitor->notification_blocked_id = g_timeout_add_seconds (24 * SECONDS_IN_AN_HOUR, reenable_offline_update_notification, monitor);
|
||
|
-
|
||
|
- if (!should_notify_about_pending_updates (monitor, apps, &title, &body))
|
||
|
+ if (!should_notify_about_pending_updates (monitor, apps, &title, &body)) {
|
||
|
+ g_debug ("No update notification needed");
|
||
|
return;
|
||
|
+ }
|
||
|
+
|
||
|
+ monitor->last_notification_time_usec = g_get_real_time ();
|
||
|
|
||
|
g_debug ("Notify about update: '%s'", title);
|
||
|
|
||
|
@@ -1394,10 +1393,6 @@ gs_update_monitor_dispose (GObject *object)
|
||
|
g_source_remove (monitor->check_startup_id);
|
||
|
monitor->check_startup_id = 0;
|
||
|
}
|
||
|
- if (monitor->notification_blocked_id != 0) {
|
||
|
- g_source_remove (monitor->notification_blocked_id);
|
||
|
- monitor->notification_blocked_id = 0;
|
||
|
- }
|
||
|
if (monitor->cleanup_notifications_id != 0) {
|
||
|
g_source_remove (monitor->cleanup_notifications_id);
|
||
|
monitor->cleanup_notifications_id = 0;
|
||
|
--
|
||
|
GitLab
|
||
|
|
||
|
|
||
|
From 2ff332826f841c4ea1d9458df81648868745ea41 Mon Sep 17 00:00:00 2001
|
||
|
From: Milan Crha <mcrha@redhat.com>
|
||
|
Date: Thu, 30 Sep 2021 16:47:40 +0200
|
||
|
Subject: [PATCH 2/2] gs-update-monitor: Correct last notification timestamp
|
||
|
reset
|
||
|
|
||
|
Do not reset the notification timestamp after the list of updates
|
||
|
is received, that should be done when the notification had been shown.
|
||
|
|
||
|
Reported downstream at:
|
||
|
https://bugzilla.redhat.com/show_bug.cgi?id=2009063
|
||
|
---
|
||
|
src/gs-update-monitor.c | 1 -
|
||
|
1 file changed, 1 deletion(-)
|
||
|
|
||
|
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
|
||
|
index 787c605a1..a8421fcc4 100644
|
||
|
--- a/src/gs-update-monitor.c
|
||
|
+++ b/src/gs-update-monitor.c
|
||
|
@@ -613,7 +613,6 @@ get_updates_finished_cb (GObject *object, GAsyncResult *res, gpointer data)
|
||
|
notify_list = apps;
|
||
|
|
||
|
notify_about_pending_updates (monitor, notify_list);
|
||
|
- reset_update_notification_timestamp (monitor);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
--
|
||
|
GitLab
|
||
|
|