[gnome-software] Only notify about upgrades once per month



commit 114ee9b7c167525a73fb33b6c18cab8fa5721cbb
Author: Richard Hughes <richard hughsie com>
Date:   Mon Aug 15 08:54:35 2016 +0100

    Only notify about upgrades once per month
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=769572

 data/org.gnome.software.gschema.xml |    4 ++++
 src/gs-update-monitor.c             |   29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index b146cc7..725159e 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -37,6 +37,10 @@
       <default>0</default>
       <summary>The last update check timestamp</summary>
     </key>
+    <key name="upgrade-notification-timestamp" type="x">
+      <default>0</default>
+      <summary>The last upgrade notification timestamp</summary>
+    </key>
     <key name="security-timestamp" type="x">
       <default>0</default>
       <summary>The timestamp of the first security update, cleared after update</summary>
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index f106a6b..016341a 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -200,6 +200,31 @@ get_updates_finished_cb (GObject *object,
        }
 }
 
+static gboolean
+should_show_upgrade_notification (GsUpdateMonitor *monitor)
+{
+       GTimeSpan d;
+       gint64 tmp;
+       g_autoptr(GDateTime) now = NULL;
+       g_autoptr(GDateTime) then = NULL;
+
+       g_settings_get (monitor->settings, "upgrade-notification-timestamp", "x", &tmp);
+       if (tmp == 0)
+               return TRUE;
+       then = g_date_time_new_from_unix_local (tmp);
+       if (then == NULL) {
+               g_warning ("failed to parse timestamp %" G_GINT64_FORMAT, tmp);
+               return TRUE;
+       }
+
+       now = g_date_time_new_now_local ();
+       d = g_date_time_difference (now, then);
+       if (d >= 30 * G_TIME_SPAN_DAY)
+               return TRUE;
+
+       return FALSE;
+}
+
 static void
 get_upgrades_finished_cb (GObject *object,
                          GAsyncResult *res,
@@ -234,6 +259,10 @@ get_upgrades_finished_cb (GObject *object,
        if (gs_application_has_active_window (GS_APPLICATION (monitor->application)))
                return;
 
+       /* only nag about upgrades once per month */
+       if (!should_show_upgrade_notification (monitor))
+               return;
+
        /* just get the first result : FIXME, do we sort these by date? */
        app = gs_app_list_index (apps, 0);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]