[gnome-software/wip/temp/ubuntu-xenial-rebased: 212/326] Show a notification if any live-updatable apps needs restarting



commit d8c7b46f15ad9f14cbb9f55ffe55e00e027e7aba
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 |   18 ++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 025f2fa..7ef3eef 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 cae7551..dca6ef3 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -483,10 +483,13 @@ 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) {
                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);
        }
 
@@ -986,6 +989,21 @@ gs_shell_updates_perform_update_cb (GsPluginLoader *plugin_loader,
                                        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);
        }
 }
 


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