[gnome-shell] extensions-tool: Split out get_extension_property() helper



commit 636ab4b0e91a8612d4bb0f37ceb2511ed0308c28
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Mar 14 11:38:24 2020 +0100

    extensions-tool: Split out get_extension_property() helper
    
    For the prefs command, we first fetch the extension info to check
    whether the extension exists and actually has preferences. This
    pattern can be useful for other commands and properties, so split
    out a generic helper function.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/2391

 subprojects/extensions-tool/src/command-prefs.c | 30 ++++-----------------
 subprojects/extensions-tool/src/common.h        |  4 +++
 subprojects/extensions-tool/src/main.c          | 35 +++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 25 deletions(-)
---
diff --git a/subprojects/extensions-tool/src/command-prefs.c b/subprojects/extensions-tool/src/command-prefs.c
index 25d1626c4d..50e4b80ba2 100644
--- a/subprojects/extensions-tool/src/command-prefs.c
+++ b/subprojects/extensions-tool/src/command-prefs.c
@@ -29,9 +29,7 @@ static gboolean
 launch_extension_prefs (const char *uuid)
 {
   g_autoptr (GDBusProxy) proxy = NULL;
-  g_autoptr (GVariant) response = NULL;
-  g_autoptr (GVariant) asv = NULL;
-  g_autoptr (GVariantDict) info = NULL;
+  g_autoptr (GVariant) info = NULL;
   g_autoptr (GError) error = NULL;
   gboolean has_prefs;
 
@@ -39,29 +37,11 @@ launch_extension_prefs (const char *uuid)
   if (proxy == NULL)
     return FALSE;
 
-  response = g_dbus_proxy_call_sync (proxy,
-                                     "GetExtensionInfo",
-                                     g_variant_new ("(s)", uuid),
-                                     0,
-                                     -1,
-                                     NULL,
-                                     &error);
-  if (response == NULL)
-    {
-      g_printerr (_("Failed to connect to GNOME Shell"));
-      return FALSE;
-    }
-
-  asv = g_variant_get_child_value (response, 0);
-  info = g_variant_dict_new (asv);
-
-  if (!g_variant_dict_contains (info, "uuid"))
-    {
-      g_printerr (_("Extension “%s” doesn't exist\n"), uuid);
-      return FALSE;
-    }
+  info = get_extension_property (proxy, uuid, "hasPrefs");
+  if (info == NULL)
+    return FALSE;
 
-  g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs);
+  has_prefs = g_variant_get_boolean (info);
   if (!has_prefs)
     {
       g_printerr (_("Extension “%s” doesn't have preferences\n"), uuid);
diff --git a/subprojects/extensions-tool/src/common.h b/subprojects/extensions-tool/src/common.h
index fb23b65804..2b0448495d 100644
--- a/subprojects/extensions-tool/src/common.h
+++ b/subprojects/extensions-tool/src/common.h
@@ -54,6 +54,10 @@ void print_extension_info (GVariantDict  *info,
                            DisplayFormat  format);
 
 GDBusProxy *get_shell_proxy (GError **error);
+GVariant   *get_extension_property (GDBusProxy *proxy,
+                                    const char *uuid,
+                                    const char *property);
+
 GSettings  *get_shell_settings (void);
 
 gboolean settings_list_add (GSettings  *settings,
diff --git a/subprojects/extensions-tool/src/main.c b/subprojects/extensions-tool/src/main.c
index cc7cd80cd6..c33058dc67 100644
--- a/subprojects/extensions-tool/src/main.c
+++ b/subprojects/extensions-tool/src/main.c
@@ -124,6 +124,41 @@ get_shell_settings (void)
   return g_settings_new_full (schema, NULL, NULL);
 }
 
+GVariant *
+get_extension_property (GDBusProxy *proxy,
+                        const char *uuid,
+                        const char *property)
+{
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GVariant) asv = NULL;
+  g_autoptr (GVariantDict) info = NULL;
+  g_autoptr (GError) error = NULL;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "GetExtensionInfo",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+  if (response == NULL)
+    {
+      g_printerr (_("Failed to connect to GNOME Shell"));
+      return NULL;
+    }
+
+  asv = g_variant_get_child_value (response, 0);
+  info = g_variant_dict_new (asv);
+
+  if (!g_variant_dict_contains (info, "uuid"))
+    {
+      g_printerr (_("Extension “%s” doesn't exist\n"), uuid);
+      return NULL;
+    }
+
+  return g_variant_dict_lookup_value (info, property, NULL);
+}
+
 gboolean
 settings_list_add (GSettings  *settings,
                    const char *key,


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