[gnome-software] Only show the firmware helper when the device needs user action



commit befd8572f24c9a79d9e7591909444d7d9761b2b2
Author: Richard Hughes <richard hughsie com>
Date:   Thu Aug 18 16:26:33 2016 +0100

    Only show the firmware helper when the device needs user action

 src/gs-app.c                  |    2 +
 src/gs-app.h                  |    4 ++
 src/gs-page.c                 |   73 +++++++++++++++++++++-------------------
 src/plugins/gs-plugin-fwupd.c |    6 +++
 4 files changed, 50 insertions(+), 35 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index e8e67cc..54855ee 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -180,6 +180,8 @@ _as_app_quirk_flag_to_string (AsAppQuirk quirk)
                return "has-shortcut";
        if (quirk == AS_APP_QUIRK_NOT_LAUNCHABLE)
                return "not-launchable";
+       if (quirk == AS_APP_QUIRK_NEEDS_USER_ACTION)
+               return "needs-user-action";
        return NULL;
 }
 
diff --git a/src/gs-app.h b/src/gs-app.h
index 18b2e3c..129ac49 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -97,6 +97,10 @@ typedef enum {
        GS_APP_QUALITY_LAST
 } GsAppQuality;
 
+#if !AS_CHECK_VERSION(0,6,2)
+#define AS_APP_QUIRK_NEEDS_USER_ACTION         (1 << 8)
+#endif
+
 GsApp          *gs_app_new                     (const gchar    *id);
 gchar          *gs_app_to_string               (GsApp          *app);
 
diff --git a/src/gs-page.c b/src/gs-page.c
index a9e614d..7404ba0 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -341,44 +341,13 @@ gs_page_update_app_response_cb (GtkDialog *dialog,
                                           helper);
 }
 
-void
-gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
+static void
+gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
 {
-       GsPagePrivate *priv = gs_page_get_instance_private (page);
-       GsPageHelper *helper;
        GtkWidget *dialog;
-       AsScreenshot *ss;
        g_autofree gchar *escaped = NULL;
+       GsPagePrivate *priv = gs_page_get_instance_private (helper->page);
 
-       /* non-firmware applications do not have to be prepared */
-       helper = g_slice_new0 (GsPageHelper);
-       helper->app = g_object_ref (app);
-       helper->page = g_object_ref (page);
-       helper->cancellable = g_object_ref (cancellable);
-       if (gs_app_get_kind (app) != AS_APP_KIND_FIRMWARE ||
-           gs_app_get_screenshots (app)->len == 0) {
-               gs_plugin_loader_app_action_async (priv->plugin_loader,
-                                                  helper->app,
-                                                  GS_PLUGIN_LOADER_ACTION_UPDATE,
-                                                  helper->cancellable,
-                                                  gs_page_app_installed_cb,
-                                                  helper);
-               return;
-       }
-
-       /* tell the user what they have to do */
-       ss = g_ptr_array_index (gs_app_get_screenshots (app), 0);
-       if (as_screenshot_get_caption (ss, NULL) == NULL) {
-               gs_plugin_loader_app_action_async (priv->plugin_loader,
-                                                  helper->app,
-                                                  GS_PLUGIN_LOADER_ACTION_UPDATE,
-                                                  helper->cancellable,
-                                                  gs_page_app_installed_cb,
-                                                  helper);
-               return;
-       }
-
-       /* show user caption */
        dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
                                         GTK_DIALOG_MODAL,
                                         GTK_MESSAGE_INFO,
@@ -386,7 +355,7 @@ gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
                                         /* TRANSLATORS: this is a prompt message, and
                                          * '%s' is an application summary, e.g. 'GNOME Clocks' */
                                         _("Prepare %s"),
-                                        gs_app_get_name (app));
+                                        gs_app_get_name (helper->app));
        escaped = g_markup_escape_text (as_screenshot_get_caption (ss, NULL), -1);
        gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
                                                    "%s", escaped);
@@ -399,6 +368,40 @@ gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
        gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
 }
 
+void
+gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
+{
+       GsPagePrivate *priv = gs_page_get_instance_private (page);
+       GsPageHelper *helper;
+
+       /* non-firmware applications do not have to be prepared */
+       helper = g_slice_new0 (GsPageHelper);
+       helper->app = g_object_ref (app);
+       helper->page = g_object_ref (page);
+       helper->cancellable = g_object_ref (cancellable);
+
+       /* tell the user what they have to do */
+       if (gs_app_get_kind (app) == AS_APP_KIND_FIRMWARE &&
+           gs_app_has_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION)) {
+               GPtrArray *screenshots = gs_app_get_screenshots (app);
+               if (screenshots->len > 0) {
+                       AsScreenshot *ss = g_ptr_array_index (screenshots, 0);
+                       if (as_screenshot_get_caption (ss, NULL) != NULL) {
+                               gs_page_needs_user_action (helper, ss);
+                               return;
+                       }
+               }
+       }
+
+       /* generic fallback */
+       gs_plugin_loader_app_action_async (priv->plugin_loader,
+                                          helper->app,
+                                          GS_PLUGIN_LOADER_ACTION_UPDATE,
+                                          helper->cancellable,
+                                          gs_page_app_installed_cb,
+                                          helper);
+}
+
 static void
 gs_page_remove_app_response_cb (GtkDialog *dialog,
                                gint response,
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index ae01aa4..3b8eb59 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -349,6 +349,12 @@ gs_plugin_fwupd_new_app_from_results (FwupdResult *res)
                        gs_app_set_update_details (app, tmp);
        }
 
+#if FWUPD_CHECK_VERSION(0,7,3)
+       /* needs action */
+       if (fwupd_result_has_device_flag (res, FU_DEVICE_FLAG_NEEDS_BOOTLOADER))
+               gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
+#endif
+
        /* the same as we have already */
        if (g_strcmp0 (fwupd_result_get_device_version (res),
                       fwupd_result_get_update_version (res)) == 0) {


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