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
This commit is contained in:
Florian Müllner 2019-01-11 12:03:17 +01:00
parent d9fa389079
commit 653e6c85bb
7 changed files with 134 additions and 2 deletions

View File

@ -0,0 +1,117 @@
/* commands-prefs.c
*
* Copyright 2019 Florian Müllner <fmuellner@gnome.org>
*
* 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 <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <glib/gi18n.h>
#include <gio/gio.h>
#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;
}

View File

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

View File

@ -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
;;

View File

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

View File

@ -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.
+

View File

@ -7,6 +7,7 @@ sources = [
'command-install.c',
'command-list.c',
'command-pack.c',
'command-prefs.c',
'common.h',
'main.c'
]

View File

@ -16,6 +16,7 @@ sources = [
'command-install.c',
'command-list.c',
'command-pack.c',
'command-prefs.c',
'main.c'
]