[gnome-software/wip/rancell/ubuntu-3-20-rebase: 6/17] Show a notification if any live-updatable apps needs restarting



commit 6a7ac1a416e6f624042e7a5dbc012cdf5d1620e5
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 8 12:35:57 2016 +0100

    Show a notification if any live-updatable apps needs restarting
    
    This covers the case where an xdg-app might need restarting because of the
    runtime having a security update.
    
    We don't force a shell restart for all cases as this is overly draconian and
    this extra step seems like the right thing to do.

 src/gs-application.c   |   40 ++++++++++++++++++++++++++++++
 src/gs-shell-updates.c |   64 ++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 91 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index bffb138..6b10e01 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -460,6 +460,45 @@ offline_update_cb (GsPluginLoader *plugin_loader,
                                app);
 }
 
+/**
+ * gs_application_reboot_failed_cb:
+ **/
+static void
+gs_application_reboot_failed_cb (GObject *source,
+                                GAsyncResult *res,
+                                gpointer user_data)
+{
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GVariant) retval = NULL;
+
+       /* get result */
+       retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
+       if (retval != NULL)
+               return;
+       if (error != NULL) {
+               g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s",
+                          error->message);
+       }
+}
+
+static void
+reboot_activated (GSimpleAction *action,
+                  GVariant      *parameter,
+                  gpointer       data)
+{
+       g_autoptr(GDBusConnection) bus = NULL;
+       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+       g_dbus_connection_call (bus,
+                               "org.gnome.SessionManager",
+                               "/org/gnome/SessionManager",
+                               "org.gnome.SessionManager",
+                               "Reboot",
+                               NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
+                               G_MAXINT, NULL,
+                               gs_application_reboot_failed_cb,
+                               NULL);
+}
+
 static void
 reboot_and_install (GSimpleAction *action,
                    GVariant      *parameter,
@@ -645,6 +684,7 @@ static GActionEntry actions[] = {
        { "quit", quit_activated, NULL, NULL, NULL },
        { "profile", profile_activated, NULL, NULL, NULL },
        { "reboot-and-install", reboot_and_install, NULL, NULL, NULL },
+       { "reboot", reboot_activated, NULL, NULL, NULL },
        { "set-mode", set_mode_activated, "s", NULL, NULL },
        { "search", search_activated, "s", NULL, NULL },
        { "details", details_activated, "(ss)", NULL, NULL },
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 0e908d6..558886a 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -63,6 +63,8 @@ struct _GsShellUpdates
        GSettings               *desktop_settings;
        gboolean                 cache_valid;
        gboolean                 in_progress;
+       gboolean                 all_updates_are_live;
+       gboolean                 any_require_reboot;
        GsShell                 *shell;
        GNetworkMonitor         *network_monitor;
        gulong                   network_changed_handler;
@@ -467,9 +469,27 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
 
        /* get the results */
        list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
+       self->all_updates_are_live = TRUE;
+       self->any_require_reboot = FALSE;
        for (l = list; l != NULL; l = l->next) {
-               gs_update_list_add_app (GS_UPDATE_LIST (self->list_box_updates),
-                                       GS_APP (l->data));
+               GsApp *app = GS_APP (l->data);
+               if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE_LIVE)
+                       self->all_updates_are_live = FALSE;
+               if (gs_app_has_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT))
+                       self->any_require_reboot = TRUE;
+               gs_update_list_add_app (GS_UPDATE_LIST (self->list_box_updates), app);
+       }
+
+       /* change the button as to whether a reboot is required to
+        * apply all the updates */
+       if (self->all_updates_are_live) {
+               gtk_button_set_label (GTK_BUTTON (self->button_update_all),
+                                     /* TRANSLATORS: all updates will be installed */
+                                     _("_Install All"));
+       } else {
+               gtk_button_set_label (GTK_BUTTON (self->button_update_all),
+                                     /* TRANSLATORS: this is an offline update */
+                                     _("Restart & _Install"));
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "button_updates_counter"));
@@ -935,17 +955,35 @@ gs_shell_updates_offline_update_cb (GsPluginLoader *plugin_loader,
                return;
        }
 
-       /* trigger reboot */
-       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
-       g_dbus_connection_call (bus,
-                               "org.gnome.SessionManager",
-                               "/org/gnome/SessionManager",
-                               "org.gnome.SessionManager",
-                               "Reboot",
-                               NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
-                               G_MAXINT, NULL,
-                               gs_shell_updates_reboot_failed_cb,
-                               self);
+       /* trigger reboot if any application was not updatable live */
+       if (!self->all_updates_are_live) {
+               g_autoptr(GDBusConnection) bus = NULL;
+               bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+               g_dbus_connection_call (bus,
+                                       "org.gnome.SessionManager",
+                                       "/org/gnome/SessionManager",
+                                       "org.gnome.SessionManager",
+                                       "Reboot",
+                                       NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
+                                       G_MAXINT, NULL,
+                                       gs_shell_updates_reboot_failed_cb,
+                                       self);
+
+       /* when we are not doing an offline update, show a notification
+        * if any application requires a reboot */
+       } else if (self->any_require_reboot) {
+               g_autoptr(GNotification) n = NULL;
+               /* TRANSLATORS: we've just live-updated some apps */
+               n = g_notification_new (_("Updates have been installed"));
+               /* TRANSLATORS: the new apps will not be run until we restart */
+               g_notification_set_body (n, _("A restart is required for them to take effect."));
+               /* TRANSLATORS: button text */
+               g_notification_add_button (n, _("Not Now"), "app.nop");
+               /* TRANSLATORS: button text */
+               g_notification_add_button_with_target (n, _("Restart"), "app.reboot", NULL);
+               g_notification_set_default_action_and_target (n, "app.set-mode", "s", "updates");
+               g_application_send_notification (g_application_get_default (), "restart-required", n);
+       }
 }
 
 static void


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