[gnome-software/fix-install-timestamp: 2/2] New "online-updates-timestamp" gsetting for online updates tracking



commit 90fb37586e4678058480d1adbf8cf40f9265dff3
Author: Umang Jain <umang endlessm com>
Date:   Mon Aug 20 16:42:00 2018 +0530

    New "online-updates-timestamp" gsetting for online updates tracking
    
    "online-updates-timestamp" will denote the last time the system was
    online and got any update. It will play as one of the factor to drive
    pending updates notification logic in gs-update-monitor (See
    no_updates_for_a_week). This timestamp is set by plugin-loader
    whenever there is a update or upgrade operation (that succeeds).
    
    The reason we introduce a new gsetting instead of using a similar
    one "install-timestamp is that, "install-timestamp" is used for
    scheduling offline PackageKit update notifications. If we reuse this
    one for flatpak updates as well, this can lead to PackageKit updates
    never getting any notifications (as flatpak updates are autoinstalled).
    
    Based on Endless dev ticket:
    https://phabricator.endlessm.com/T22720
    
    https://gitlab.gnome.org/GNOME/gnome-software/merge_requests/78

 data/org.gnome.software.gschema.xml |  4 ++++
 lib/gs-plugin-loader.c              |  5 +++++
 lib/gs-utils.c                      | 20 ++++++++++++++++++++
 lib/gs-utils.h                      |  1 +
 src/gs-update-monitor.c             | 14 ++++++++++++--
 5 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 97780e0d..944a9ca5 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -63,6 +63,10 @@
       <default>0</default>
       <summary>The last update timestamp</summary>
     </key>
+    <key name="online-updates-timestamp" type="x">
+      <default>0</default>
+      <summary>The last timestamp when the system was online and got any updates</summary>
+    </key>
     <key name="screenshot-cache-age-maximum" type="u">
       <default>2592000</default>
       <summary>The age in seconds to verify the upstream screenshot is still valid</summary>
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 23a27205..9460a803 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2972,6 +2972,8 @@ gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
                helper->anything_ran = TRUE;
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
+
+       gs_utils_set_online_updates_timestamp (priv->settings);
        return TRUE;
 }
 
@@ -3038,6 +3040,9 @@ gs_plugin_loader_process_thread_cb (GTask *task,
                }
        }
 
+       if (action == GS_PLUGIN_ACTION_UPGRADE_TRIGGER)
+               gs_utils_set_online_updates_timestamp (priv->settings);
+
        /* remove from pending list */
        if (add_to_pending_array)
                gs_plugin_loader_pending_apps_remove (plugin_loader, helper);
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index f063872f..8cc0c7b0 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1159,3 +1159,23 @@ gs_utils_parse_evr (const gchar *evr,
        g_assert (*out_release != NULL);
        return TRUE;
 }
+
+/**
+ * gs_utils_set_online_updates_timestamp:
+ *
+ * Sets the value of online-updates-timestamp to current epoch. "online-updates-timestamp" represents
+ * the last time the system was online and got any updates.
+ *
+ **/
+void
+gs_utils_set_online_updates_timestamp (GSettings *settings)
+{
+       g_autoptr(GDateTime) now = NULL;
+
+       g_return_if_fail (settings != NULL);
+
+       now = g_date_time_new_now_local ();
+       g_settings_set (settings, "online-updates-timestamp", "x", g_date_time_to_unix (now));
+}
+
+/* vim: set noexpandtab: */
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index 824e6b67..b98ede46 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -87,5 +87,6 @@ gboolean       gs_utils_parse_evr             (const gchar     *evr,
                                                 gchar          **out_epoch,
                                                 gchar          **out_version,
                                                 gchar          **out_release);
+void            gs_utils_set_online_updates_timestamp (GSettings *settings);
 
 G_END_DECLS
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index ffb314bb..c55b1536 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -140,14 +140,14 @@ has_important_updates (GsAppList *apps)
 }
 
 static gboolean
-no_updates_for_a_week (GsUpdateMonitor *monitor)
+check_if_timestamp_more_than_a_week_ago (GsUpdateMonitor *monitor, const gchar *timestamp)
 {
        GTimeSpan d;
        gint64 tmp;
        g_autoptr(GDateTime) last_update = NULL;
        g_autoptr(GDateTime) now = NULL;
 
-       g_settings_get (monitor->settings, "install-timestamp", "x", &tmp);
+       g_settings_get (monitor->settings, timestamp, "x", &tmp);
        if (tmp == 0)
                return TRUE;
 
@@ -165,6 +165,16 @@ no_updates_for_a_week (GsUpdateMonitor *monitor)
        return FALSE;
 }
 
+static gboolean
+no_updates_for_a_week (GsUpdateMonitor *monitor)
+{
+       if (check_if_timestamp_more_than_a_week_ago (monitor, "install-timestamp") ||
+           check_if_timestamp_more_than_a_week_ago (monitor, "online-updates-timestamp"))
+               return TRUE;
+
+       return FALSE;
+}
+
 static gboolean
 _filter_by_app_kind (GsApp *app, gpointer user_data)
 {


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