From 653e6c85bbe6b098a5bb5298d7ede491169a8511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 11 Jan 2019 12:03:17 +0100 Subject: [PATCH] extensions-tool: Add 'prefs' command Easily launching an extension's preference dialog from the command line can be quicker than using a UI like Tweaks or the extension website, so add that functionality. https://gitlab.gnome.org/fmuellner/gnome-extensions-tool/merge_requests/2 https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234 --- src/extensions-tool/command-prefs.c | 117 ++++++++++++++++++ src/extensions-tool/commands.h | 1 + .../completion/bash/gnome-extensions | 7 +- src/extensions-tool/main.c | 3 + src/extensions-tool/man/gnome-extensions.txt | 6 + src/extensions-tool/meson-src.build | 1 + src/extensions-tool/meson.build | 1 + 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/extensions-tool/command-prefs.c diff --git a/src/extensions-tool/command-prefs.c b/src/extensions-tool/command-prefs.c new file mode 100644 index 000000000..022ff8f86 --- /dev/null +++ b/src/extensions-tool/command-prefs.c @@ -0,0 +1,117 @@ +/* commands-prefs.c + * + * Copyright 2019 Florian Müllner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include + +#include "commands.h" +#include "common.h" +#include "config.h" + +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 (GError) error = NULL; + gboolean has_prefs; + + proxy = get_shell_proxy (&error); + 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) + return FALSE; + + asv = g_variant_get_child_value (response, 0); + info = g_variant_dict_new (asv); + + if (!g_variant_dict_contains (info, "uuid")) + return FALSE; + + g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs); + if (!has_prefs) + return FALSE; + + g_dbus_proxy_call_sync (proxy, + "LaunchExtensionPrefs", + g_variant_new ("(s)", uuid), + 0, + -1, + NULL, + &error); + + return TRUE; +} + +int +handle_prefs (int argc, char *argv[], gboolean do_help) +{ + g_autoptr (GOptionContext) context = NULL; + g_autoptr (GError) error = NULL; + g_auto(GStrv) uuids = NULL; + GOptionEntry entries[] = { + { .long_name = G_OPTION_REMAINING, + .arg_description = "UUID", + .arg = G_OPTION_ARG_STRING_ARRAY, .arg_data = &uuids }, + { NULL } + }; + + g_set_prgname ("gnome-extensions prefs"); + + context = g_option_context_new (NULL); + g_option_context_set_help_enabled (context, FALSE); + g_option_context_set_summary (context, _("Opens extension preferences")); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); + + if (do_help) + { + show_help (context, NULL); + return 0; + } + + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + show_help (context, error->message); + return 1; + } + + if (uuids == NULL) + { + show_help (context, _("No UUID given")); + return 1; + } + else if (g_strv_length (uuids) > 1) + { + show_help (context, _("More than one UUID given")); + return 1; + } + + return launch_extension_prefs (*uuids) ? 0 : 2; +} diff --git a/src/extensions-tool/commands.h b/src/extensions-tool/commands.h index 247a14434..04de71c7c 100644 --- a/src/extensions-tool/commands.h +++ b/src/extensions-tool/commands.h @@ -28,6 +28,7 @@ int handle_enable (int argc, char *argv[], gboolean do_help); int handle_disable (int argc, char *argv[], gboolean do_help); int handle_list (int argc, char *argv[], gboolean do_help); int handle_info (int argc, char *argv[], gboolean do_help); +int handle_prefs (int argc, char *argv[], gboolean do_help); int handle_create (int argc, char *argv[], gboolean do_help); int handle_pack (int argc, char *argv[], gboolean do_help); int handle_install (int argc, char *argv[], gboolean do_help); diff --git a/src/extensions-tool/completion/bash/gnome-extensions b/src/extensions-tool/completion/bash/gnome-extensions index 73b594281..aaff309c0 100644 --- a/src/extensions-tool/completion/bash/gnome-extensions +++ b/src/extensions-tool/completion/bash/gnome-extensions @@ -5,7 +5,7 @@ ################################################################################ __gnome_extensions() { - local commands="version enable disable info install show list create pack" + local commands="version enable disable info install show list create pack prefs" local COMMAND=${COMP_WORDS[1]} _init_completion -s || return @@ -29,7 +29,10 @@ __gnome_extensions() { enable) local list_opt=--disabled ;;& - enable|disable|info|show) + prefs) + local list_opt=--prefs + ;;& + enable|disable|info|show|prefs) COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2")) return 0 ;; diff --git a/src/extensions-tool/main.c b/src/extensions-tool/main.c index 467f49805..ef94abc5f 100644 --- a/src/extensions-tool/main.c +++ b/src/extensions-tool/main.c @@ -186,6 +186,7 @@ usage (void) g_printerr (" list %s\n", _("List extensions")); g_printerr (" info %s\n", _("Show extension info")); g_printerr (" show %s\n", _("Show extension info")); + g_printerr (" prefs %s\n", _("Open extension preferences")); g_printerr (" create %s\n", _("Create extension")); g_printerr (" pack %s\n", _("Package extension")); g_printerr (" install %s\n", _("Install extension bundle")); @@ -252,6 +253,8 @@ main (int argc, char *argv[]) return handle_info (argc, argv, do_help); else if (g_str_equal (command, "show")) return handle_info (argc, argv, do_help); + else if (g_str_equal (command, "prefs")) + return handle_prefs (argc, argv, do_help); else if (g_str_equal (command, "create")) return handle_create (argc, argv, do_help); else if (g_str_equal (command, "pack")) diff --git a/src/extensions-tool/man/gnome-extensions.txt b/src/extensions-tool/man/gnome-extensions.txt index e782103fd..2322f6d31 100644 --- a/src/extensions-tool/man/gnome-extensions.txt +++ b/src/extensions-tool/man/gnome-extensions.txt @@ -25,6 +25,8 @@ SYNOPSIS *gnome-extensions* list ['OPTION'...] +*gnome-extensions* prefs 'UUID' + *gnome-extensions* create ['OPTION'...] *gnome-extensions* pack ['OPTION'...] @@ -88,6 +90,10 @@ Displays a list of installed extensions. *--details*;; Show some extra information for each extension +*prefs* 'UUID':: +Open the preference dialog of the extension identified by 'UUID'. + + *create* ['OPTION'...]:: Creates a new extension from a template. + diff --git a/src/extensions-tool/meson-src.build b/src/extensions-tool/meson-src.build index 7af5365e4..10ca7b42a 100644 --- a/src/extensions-tool/meson-src.build +++ b/src/extensions-tool/meson-src.build @@ -7,6 +7,7 @@ sources = [ 'command-install.c', 'command-list.c', 'command-pack.c', + 'command-prefs.c', 'common.h', 'main.c' ] diff --git a/src/extensions-tool/meson.build b/src/extensions-tool/meson.build index 390227490..ab93e85c8 100644 --- a/src/extensions-tool/meson.build +++ b/src/extensions-tool/meson.build @@ -16,6 +16,7 @@ sources = [ 'command-install.c', 'command-list.c', 'command-pack.c', + 'command-prefs.c', 'main.c' ]