From d80ef67d1d54cbf34f4be197845ceafe9b0f8704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 23 Jul 2019 23:37:09 +0000 Subject: [PATCH] extension-tool: Use enable/disable D-Bus API if possible Commit 4589da957 added D-Bus API for enabling/disabling extensions, use that if possible to provide better feedback and not clutter the settings with non-existent UUIDs. The old code path is preserved as fallback to keep the commands working from outside a running shell session. https://gitlab.gnome.org/GNOME/gnome-shell/issues/2391 --- .../extensions-tool/src/command-disable.c | 46 ++++++++++++++++++- .../extensions-tool/src/command-enable.c | 46 ++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/subprojects/extensions-tool/src/command-disable.c b/subprojects/extensions-tool/src/command-disable.c index 116f6699c..93c316bf7 100644 --- a/subprojects/extensions-tool/src/command-disable.c +++ b/subprojects/extensions-tool/src/command-disable.c @@ -26,7 +26,37 @@ #include "config.h" static gboolean -disable_extension (const char *uuid) +disable_extension_dbus (GDBusProxy *proxy, + const char *uuid) +{ + g_autoptr (GVariant) response = NULL; + g_autoptr (GError) error = NULL; + gboolean success = FALSE; + + response = g_dbus_proxy_call_sync (proxy, + "DisableExtension", + g_variant_new ("(s)", uuid), + 0, + -1, + NULL, + &error); + + if (response == NULL) + { + g_printerr (_("Failed to connect to GNOME Shell\n")); + return FALSE; + } + + g_variant_get (response, "(b)", &success); + + if (!success) + g_printerr (_("Extension ā€œ%sā€ does not exist\n"), uuid); + + return success; +} + +static gboolean +disable_extension_gsettings (const char *uuid) { g_autoptr(GSettings) settings = get_shell_settings (); @@ -37,6 +67,20 @@ disable_extension (const char *uuid) settings_list_add (settings, "disabled-extensions", uuid); } +static gboolean +disable_extension (const char *uuid) +{ + g_autoptr (GDBusProxy) proxy = NULL; + g_autoptr (GError) error = NULL; + + proxy = get_shell_proxy (&error); + + if (proxy != NULL) + return disable_extension_dbus (proxy, uuid); + else + return disable_extension_gsettings (uuid); +} + int handle_disable (int argc, char *argv[], gboolean do_help) { diff --git a/subprojects/extensions-tool/src/command-enable.c b/subprojects/extensions-tool/src/command-enable.c index 786e45109..6ae3a8351 100644 --- a/subprojects/extensions-tool/src/command-enable.c +++ b/subprojects/extensions-tool/src/command-enable.c @@ -26,7 +26,37 @@ #include "config.h" static gboolean -enable_extension (const char *uuid) +enable_extension_dbus (GDBusProxy *proxy, + const char *uuid) +{ + g_autoptr (GVariant) response = NULL; + g_autoptr (GError) error = NULL; + gboolean success = FALSE; + + response = g_dbus_proxy_call_sync (proxy, + "EnableExtension", + g_variant_new ("(s)", uuid), + 0, + -1, + NULL, + &error); + + if (response == NULL) + { + g_printerr (_("Failed to connect to GNOME Shell\n")); + return FALSE; + } + + g_variant_get (response, "(b)", &success); + + if (!success) + g_printerr (_("Extension ā€œ%sā€ does not exist\n"), uuid); + + return success; +} + +static gboolean +enable_extension_gsettings (const char *uuid) { g_autoptr(GSettings) settings = get_shell_settings (); @@ -37,6 +67,20 @@ enable_extension (const char *uuid) settings_list_remove (settings, "disabled-extensions", uuid); } +static gboolean +enable_extension (const char *uuid) +{ + g_autoptr (GDBusProxy) proxy = NULL; + g_autoptr (GError) error = NULL; + + proxy = get_shell_proxy (&error); + + if (proxy != NULL) + return enable_extension_dbus (proxy, uuid); + else + return enable_extension_gsettings (uuid); +} + int handle_enable (int argc, char *argv[], gboolean do_help) {