From 35f6111ec9b2590d79e66224edd9aae0d8520ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 21 Dec 2023 23:16:18 +0100 Subject: [PATCH] extensions-tool/list: Allow filtering by (in)active state This brings back the filtering that the `--enable`/`--disable` flags used to do, which can be useful as well. For instance $ gnome-extensions list --active to show all extensions currently in use, or $ gnome-extensions list --enabled --inactive for extensions that are inactive despite being enabled. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7004 Part-of: --- .../extensions-tool/man/gnome-extensions.txt | 6 ++++ .../extensions-tool/src/command-list.c | 29 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/subprojects/extensions-tool/man/gnome-extensions.txt b/subprojects/extensions-tool/man/gnome-extensions.txt index 7fcc3811e..20d5fd415 100644 --- a/subprojects/extensions-tool/man/gnome-extensions.txt +++ b/subprojects/extensions-tool/man/gnome-extensions.txt @@ -100,6 +100,12 @@ Displays a list of installed extensions. *--disabled*;; Include disabled extensions + *--active*;; + Only include extensions in active state + + *--inactive*;; + Only include extensions in inactive state + *--prefs*;; Only include extensions with preferences diff --git a/subprojects/extensions-tool/src/command-list.c b/subprojects/extensions-tool/src/command-list.c index e5e4b8b95..db6e81aed 100644 --- a/subprojects/extensions-tool/src/command-list.c +++ b/subprojects/extensions-tool/src/command-list.c @@ -32,8 +32,10 @@ typedef enum { LIST_FLAGS_SYSTEM = 1 << 1, LIST_FLAGS_ENABLED = 1 << 2, LIST_FLAGS_DISABLED = 1 << 3, - LIST_FLAGS_NO_PREFS = 1 << 4, - LIST_FLAGS_NO_UPDATES = 1 << 5, + LIST_FLAGS_ACTIVE = 1 << 4, + LIST_FLAGS_INACTIVE = 1 << 5, + LIST_FLAGS_NO_PREFS = 1 << 6, + LIST_FLAGS_NO_UPDATES = 1 << 7, } ListFilterFlags; static gboolean @@ -71,13 +73,14 @@ list_extensions (ListFilterFlags filter, DisplayFormat format) while (g_variant_iter_loop (&iter, "{s@a{sv}}", &uuid, &value)) { g_autoptr (GVariantDict) info = NULL; - double type; + double type, state; gboolean has_prefs; gboolean has_update; gboolean enabled; info = g_variant_dict_new (value); g_variant_dict_lookup (info, "type", "d", &type); + g_variant_dict_lookup (info, "state", "d", &state); g_variant_dict_lookup (info, "enabled", "b", &enabled); g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs); g_variant_dict_lookup (info, "hasUpdate", "b", &has_update); @@ -94,6 +97,12 @@ list_extensions (ListFilterFlags filter, DisplayFormat format) if (!enabled && (filter & LIST_FLAGS_DISABLED) == 0) continue; + if (state == STATE_ACTIVE && (filter & LIST_FLAGS_ACTIVE) == 0) + continue; + + if (state != STATE_ACTIVE && (filter & LIST_FLAGS_INACTIVE) == 0) + continue; + if (!has_prefs && (filter & LIST_FLAGS_NO_PREFS) == 0) continue; @@ -121,6 +130,8 @@ handle_list (int argc, char *argv[], gboolean do_help) gboolean system = FALSE; gboolean enabled = FALSE; gboolean disabled = FALSE; + gboolean active = FALSE; + gboolean inactive = FALSE; gboolean has_prefs = FALSE; gboolean has_updates = FALSE; GOptionEntry entries[] = { @@ -136,6 +147,12 @@ handle_list (int argc, char *argv[], gboolean do_help) { .long_name = "disabled", .arg = G_OPTION_ARG_NONE, .arg_data = &disabled, .description = _("Show disabled extensions") }, + { .long_name = "active", + .arg = G_OPTION_ARG_NONE, .arg_data = &active, + .description = _("Show extensions in active state") }, + { .long_name = "inactive", + .arg = G_OPTION_ARG_NONE, .arg_data = &inactive, + .description = _("Show extensions in inactive state") }, { .long_name = "prefs", .arg = G_OPTION_ARG_NONE, .arg_data = &has_prefs, .description = _("Show extensions with preferences") }, @@ -186,6 +203,12 @@ handle_list (int argc, char *argv[], gboolean do_help) if (disabled || !enabled) flags |= LIST_FLAGS_DISABLED; + if (active || !inactive) + flags |= LIST_FLAGS_ACTIVE; + + if (inactive || !active) + flags |= LIST_FLAGS_INACTIVE; + if (!has_prefs) flags |= LIST_FLAGS_NO_PREFS;