[gnome-software/987-removing-layered-local-package-on-silverblue-does-not-notify-the-user-that-it-was-actually] gs-common: Improve gs_utils_reboot_notify()



commit ae15a2d927461ecb0f6a344dffe646b2bc24e4e1
Author: Milan Crha <mcrha redhat com>
Date:   Fri Apr 16 11:50:34 2021 +0200

    gs-common: Improve gs_utils_reboot_notify()
    
    Two improvements:
    a) distinguish between 'install' and 'remove'
    b) show application name when a single desktop application had been installed/removed

 src/gs-common.c          | 39 ++++++++++++++++++++++++++++++++++-----
 src/gs-common.h          |  3 ++-
 src/gs-page.c            |  2 +-
 src/gs-updates-section.c |  2 +-
 4 files changed, 38 insertions(+), 8 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index 86a86c091..9898888af 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -678,16 +678,45 @@ gs_utils_list_has_component_fuzzy (GsAppList *list, GsApp *app)
 }
 
 void
-gs_utils_reboot_notify (GsAppList *list)
+gs_utils_reboot_notify (GsAppList *list,
+                       gboolean is_install)
 {
        g_autoptr(GNotification) n = NULL;
+       g_autofree gchar *tmp = NULL;
+       const gchar *app_name;
        const gchar *title;
        const gchar *body;
 
-       /* TRANSLATORS: we've just live-updated some apps */
-       title = ngettext ("An update has been installed",
-                         "Updates have been installed",
-                         gs_app_list_length (list));
+       if (gs_app_list_length (list) == 1) {
+               GsApp *app = gs_app_list_index (list, 0);
+               if (gs_app_get_kind (app) == AS_COMPONENT_KIND_DESKTOP_APP) {
+                       app_name = gs_app_get_name (app);
+                       if (!*app_name)
+                               app_name = NULL;
+               }
+       }
+
+       if (is_install) {
+               if (app_name) {
+                       /* TRANSLATORS: The '%s' is replaced with the application name */
+                       tmp = g_strdup_printf ("An application ā€œ%sā€ has been installed", app_name);
+                       title = tmp;
+               } else {
+                       /* TRANSLATORS: we've just live-updated some apps */
+                       title = ngettext ("An update has been installed",
+                                         "Updates have been installed",
+                                         gs_app_list_length (list));
+               }
+       } else if (app_name) {
+               /* TRANSLATORS: The '%s' is replaced with the application name */
+               tmp = g_strdup_printf ("An application ā€œ%sā€ has been removed", app_name);
+               title = tmp;
+       } else {
+               /* TRANSLATORS: we've just removed some apps */
+               title = ngettext ("An application has been removed",
+                                 "Applications have been removed",
+                                 gs_app_list_length (list));
+       }
 
        /* TRANSLATORS: the new apps will not be run until we restart */
        body = ngettext ("A restart is required for it to take effect.",
diff --git a/src/gs-common.h b/src/gs-common.h
index b49cba5f8..7283773e8 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -46,7 +46,8 @@ gchar         *gs_utils_build_unique_id_kind  (AsComponentKind kind,
                                                 const gchar    *id);
 gboolean        gs_utils_list_has_component_fuzzy      (GsAppList      *list,
                                                 GsApp          *app);
-void            gs_utils_reboot_notify         (GsAppList      *list);
+void            gs_utils_reboot_notify         (GsAppList      *list,
+                                                gboolean        is_install);
 gchar          *gs_utils_time_to_string        (gint64          unix_time_seconds);
 void            gs_utils_invoke_reboot         (GCancellable   *cancellable,
                                                 GAsyncReadyCallback ready_callback,
diff --git a/src/gs-page.c b/src/gs-page.c
index 2048e228e..41ac44b58 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -154,7 +154,7 @@ gs_page_app_installed_cb (GObject *source,
        if (gs_app_has_quirk (helper->app, GS_APP_QUIRK_NEEDS_REBOOT)) {
                g_autoptr(GsAppList) list = gs_app_list_new ();
                gs_app_list_add (list, helper->app);
-               gs_utils_reboot_notify (list);
+               gs_utils_reboot_notify (list, TRUE);
        }
 
        /* tell the user what they have to do */
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index 1c43e8864..05660e7d3 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -331,7 +331,7 @@ _perform_update_cb (GsPluginLoader *plugin_loader, GAsyncResult *res, gpointer u
        /* when we are not doing an offline update, show a notification
         * if any application requires a reboot */
        } else if (helper->do_reboot_notification) {
-               gs_utils_reboot_notify (self->list);
+               gs_utils_reboot_notify (self->list, TRUE);
        }
 
 out:


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