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
This commit is contained in:
Florian Müllner 2019-07-23 23:37:09 +00:00
parent 62f3457a95
commit d80ef67d1d
2 changed files with 90 additions and 2 deletions

View File

@ -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)
{

View File

@ -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)
{