extensions-tool: Move to a subproject
The gnome-extensions tool code is really independent from the rest of the code base, and could be used either as part of the gnome-shell build or as stand-alone project (for example for the extension-ci docker image). We can actually support both cases by moving the code to a subproject. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/877
This commit is contained in:

committed by
Florian Müllner

parent
26dc2a439d
commit
51518d4d96
289
subprojects/extensions-tool/src/command-create.c
Normal file
289
subprojects/extensions-tool/src/command-create.c
Normal file
@ -0,0 +1,289 @@
|
||||
/* command-create.c
|
||||
*
|
||||
* Copyright 2018 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 <gio/gunixinputstream.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
static char *
|
||||
get_shell_version (GError **error)
|
||||
{
|
||||
g_autoptr (GDBusProxy) proxy = NULL;
|
||||
g_autoptr (GVariant) variant = NULL;
|
||||
g_auto (GStrv) split_version = NULL;
|
||||
|
||||
proxy = get_shell_proxy (error);
|
||||
if (proxy == NULL)
|
||||
return NULL;
|
||||
|
||||
variant = g_dbus_proxy_get_cached_property (proxy, "ShellVersion");
|
||||
if (variant == NULL)
|
||||
return NULL;
|
||||
|
||||
split_version = g_strsplit (g_variant_get_string (variant, NULL), ".", 3);
|
||||
if (g_ascii_strtoll (split_version[1], NULL, 10) % 2 == 0)
|
||||
g_clear_pointer (&split_version[2], g_free);
|
||||
|
||||
return g_strjoinv (".", split_version);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
create_metadata (GFile *target_dir,
|
||||
const char *uuid,
|
||||
const char *name,
|
||||
const char *description,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GFile) target = NULL;
|
||||
g_autoptr (GString) json = NULL;
|
||||
g_autofree char *version = NULL;
|
||||
|
||||
version = get_shell_version (error);
|
||||
if (version == NULL)
|
||||
return FALSE;
|
||||
|
||||
json = g_string_new ("{\n");
|
||||
|
||||
g_string_append_printf (json, " \"name\": \"%s\",\n", name);
|
||||
g_string_append_printf (json, " \"description\": \"%s\",\n", description);
|
||||
g_string_append_printf (json, " \"uuid\": \"%s\",\n", uuid);
|
||||
g_string_append_printf (json, " \"shell-version\": [\n");
|
||||
g_string_append_printf (json, " \"%s\"\n", version);
|
||||
g_string_append_printf (json, " ]\n}\n");
|
||||
|
||||
target = g_file_get_child (target_dir, "metadata.json");
|
||||
return g_file_replace_contents (target,
|
||||
json->str,
|
||||
json->len,
|
||||
NULL,
|
||||
FALSE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
error);
|
||||
}
|
||||
|
||||
|
||||
#define TEMPLATE_PATH "/org/gnome/extensions-tool/template"
|
||||
static gboolean
|
||||
copy_extension_template (GFile *target_dir, GError **error)
|
||||
{
|
||||
g_auto (GStrv) templates;
|
||||
char **s;
|
||||
|
||||
templates = g_resources_enumerate_children (TEMPLATE_PATH, 0, NULL);
|
||||
for (s = templates; *s; s++)
|
||||
{
|
||||
g_autoptr (GFile) target = NULL;
|
||||
g_autoptr (GFile) source = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
|
||||
uri = g_strdup_printf ("resource://%s/%s", TEMPLATE_PATH, *s);
|
||||
source = g_file_new_for_uri (uri);
|
||||
target = g_file_get_child (target_dir, *s);
|
||||
|
||||
if (!g_file_copy (source, target, G_FILE_COPY_TARGET_DEFAULT_PERMS, NULL, NULL, NULL, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
launch_extension_source (GFile *dir, GError **error)
|
||||
{
|
||||
g_autoptr (GFile) main_source = NULL;
|
||||
g_autoptr (GAppInfo) handler = NULL;
|
||||
GList l;
|
||||
|
||||
main_source = g_file_get_child (dir, "extension.js");
|
||||
handler = g_file_query_default_handler (main_source, NULL, error);
|
||||
if (handler == NULL)
|
||||
return FALSE;
|
||||
|
||||
l.data = main_source;
|
||||
l.next = l.prev = NULL;
|
||||
|
||||
return g_app_info_launch (handler, &l, NULL, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
create_extension (const char *uuid, const char *name, const char *description)
|
||||
{
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
dir = g_file_new_build_filename (g_get_user_data_dir (),
|
||||
"gnome-shell",
|
||||
"extensions",
|
||||
uuid,
|
||||
NULL);
|
||||
|
||||
if (!g_file_make_directory_with_parents (dir, NULL, &error))
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!create_metadata (dir, uuid, name, description, &error))
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!copy_extension_template (dir, &error))
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!launch_extension_source (dir, &error))
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
prompt_metadata (char **uuid, char **name, char **description)
|
||||
{
|
||||
g_autoptr (GInputStream) stdin = NULL;
|
||||
g_autoptr (GDataInputStream) istream = NULL;
|
||||
|
||||
if ((uuid == NULL || *uuid != NULL) &&
|
||||
(name == NULL || *name != NULL) &&
|
||||
(description == NULL || *description != NULL))
|
||||
return;
|
||||
|
||||
stdin = g_unix_input_stream_new (0, FALSE);
|
||||
istream = g_data_input_stream_new (stdin);
|
||||
|
||||
if (name != NULL && *name == NULL)
|
||||
{
|
||||
char *line;
|
||||
|
||||
g_print (
|
||||
_("Name should be a very short (ideally descriptive) string.\n"
|
||||
"Examples are: %s"),
|
||||
"“Click To Focus”, “Adblock”, “Shell Window Shrinker”\n");
|
||||
g_print ("%s: ", _("Name"));
|
||||
|
||||
line = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL);
|
||||
*name = g_strdelimit (line, "\n", '\0');
|
||||
}
|
||||
|
||||
if (description != NULL && *description == NULL)
|
||||
{
|
||||
char *line;
|
||||
|
||||
g_print (
|
||||
_("Description is a single-sentence explanation of what your extension does.\n"
|
||||
"Examples are: %s"),
|
||||
"“Make windows visible on click”, “Block advertisement popups”, “Animate windows shrinking on minimize”\n");
|
||||
g_print ("%s: ", _("Description"));
|
||||
|
||||
line = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL);
|
||||
*description = g_strdelimit (line, "\n", '\0');
|
||||
}
|
||||
|
||||
if (uuid != NULL && *uuid == NULL)
|
||||
{
|
||||
char *line;
|
||||
|
||||
g_print (
|
||||
_("UUID is a globally-unique identifier for your extension.\n"
|
||||
"This should be in the format of an email address (clicktofocus@janedoe.example.com)\n"));
|
||||
g_print ("UUID: ");
|
||||
|
||||
line = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL);
|
||||
*uuid = g_strdelimit (line, "\n", '\0');
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
handle_create (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
g_autoptr (GOptionContext) context = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autofree char *name = NULL;
|
||||
g_autofree char *description = NULL;
|
||||
g_autofree char *uuid = NULL;
|
||||
gboolean interactive = FALSE;
|
||||
GOptionEntry entries[] = {
|
||||
{ .long_name = "uuid",
|
||||
.arg = G_OPTION_ARG_STRING, .arg_data = &uuid,
|
||||
.arg_description = "UUID",
|
||||
.description = _("The unique identifier of the new extension") },
|
||||
{ .long_name = "name",
|
||||
.arg = G_OPTION_ARG_STRING, .arg_data = &name,
|
||||
.arg_description = _("NAME"),
|
||||
.description = _("The user-visible name of the new extension") },
|
||||
{ .long_name = "description",
|
||||
.arg_description = _("DESCRIPTION"),
|
||||
.arg = G_OPTION_ARG_STRING, .arg_data = &description,
|
||||
.description = _("A short description of what the extension does") },
|
||||
{ .long_name = "interactive", .short_name = 'i',
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &interactive,
|
||||
.description = _("Enter extension information interactively") },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
g_set_prgname ("gnome-extensions create");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Create a new extension"));
|
||||
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 (argc > 1)
|
||||
{
|
||||
show_help (context, _("Unknown arguments"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (interactive)
|
||||
prompt_metadata (&uuid, &name, &description);
|
||||
|
||||
if (uuid == NULL || name == NULL || description == NULL)
|
||||
{
|
||||
show_help (context, _("UUID, name and description are required"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return create_extension (uuid, name, description) ? 0 : 2;
|
||||
}
|
84
subprojects/extensions-tool/src/command-disable.c
Normal file
84
subprojects/extensions-tool/src/command-disable.c
Normal file
@ -0,0 +1,84 @@
|
||||
/* command-disable.c
|
||||
*
|
||||
* Copyright 2018 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
|
||||
disable_extension (const char *uuid)
|
||||
{
|
||||
g_autoptr(GSettings) settings = get_shell_settings ();
|
||||
|
||||
if (settings == NULL)
|
||||
return FALSE;
|
||||
|
||||
return settings_list_remove (settings, "enabled-extensions", uuid) &&
|
||||
settings_list_add (settings, "disabled-extensions", uuid);
|
||||
}
|
||||
|
||||
int
|
||||
handle_disable (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 disable");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Disable an extension"));
|
||||
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 disable_extension (*uuids) ? 0 : 2;
|
||||
}
|
84
subprojects/extensions-tool/src/command-enable.c
Normal file
84
subprojects/extensions-tool/src/command-enable.c
Normal file
@ -0,0 +1,84 @@
|
||||
/* command-enable.c
|
||||
*
|
||||
* Copyright 2018 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
|
||||
enable_extension (const char *uuid)
|
||||
{
|
||||
g_autoptr(GSettings) settings = get_shell_settings ();
|
||||
|
||||
if (settings == NULL)
|
||||
return FALSE;
|
||||
|
||||
return settings_list_add (settings, "enabled-extensions", uuid) &&
|
||||
settings_list_remove (settings, "disabled-extensions", uuid);
|
||||
}
|
||||
|
||||
int
|
||||
handle_enable (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 enable");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Enable an extension"));
|
||||
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 enable_extension (*uuids) ? 0 : 2;
|
||||
}
|
106
subprojects/extensions-tool/src/command-info.c
Normal file
106
subprojects/extensions-tool/src/command-info.c
Normal file
@ -0,0 +1,106 @@
|
||||
/* commands-info.c
|
||||
*
|
||||
* Copyright 2018 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
|
||||
show_extension_info (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;
|
||||
|
||||
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;
|
||||
|
||||
print_extension_info (info, DISPLAY_DETAILED);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
handle_info (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 info");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Show extensions info"));
|
||||
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 show_extension_info (*uuids) ? 0 : 2;
|
||||
}
|
212
subprojects/extensions-tool/src/command-install.c
Normal file
212
subprojects/extensions-tool/src/command-install.c
Normal file
@ -0,0 +1,212 @@
|
||||
/* command-install.c
|
||||
*
|
||||
* Copyright 2018 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 <gnome-autoar/gnome-autoar.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
static JsonObject *
|
||||
load_metadata (GFile *dir,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (JsonParser) parser = NULL;
|
||||
g_autoptr (GInputStream) stream = NULL;
|
||||
g_autoptr (GFile) file = NULL;
|
||||
|
||||
file = g_file_get_child (dir, "metadata.json");
|
||||
stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
||||
parser = json_parser_new_immutable ();
|
||||
if (!json_parser_load_from_stream (parser, stream, NULL, error))
|
||||
return NULL;
|
||||
|
||||
return json_node_dup_object (json_parser_get_root (parser));
|
||||
}
|
||||
|
||||
static void
|
||||
on_error (AutoarExtractor *extractor,
|
||||
GError *error,
|
||||
gpointer data)
|
||||
{
|
||||
*((GError **)data) = g_error_copy (error);
|
||||
}
|
||||
|
||||
static GFile *
|
||||
on_decide_destination (AutoarExtractor *extractor,
|
||||
GFile *dest,
|
||||
GList *files,
|
||||
gpointer data)
|
||||
{
|
||||
g_autofree char *dest_path = NULL;
|
||||
GFile *new_dest;
|
||||
int copy = 1;
|
||||
|
||||
dest_path = g_file_get_path (dest);
|
||||
new_dest = g_object_ref (dest);
|
||||
|
||||
while (g_file_query_exists (new_dest, NULL))
|
||||
{
|
||||
g_autofree char *new_path = g_strdup_printf ("%s (%d)", dest_path, copy);
|
||||
|
||||
g_object_unref (new_dest);
|
||||
new_dest = g_file_new_for_path (new_path);
|
||||
|
||||
copy++;
|
||||
}
|
||||
|
||||
*((GFile **)data) = g_object_ref (new_dest);
|
||||
|
||||
return new_dest;
|
||||
}
|
||||
|
||||
static int
|
||||
install_extension (const char *bundle,
|
||||
gboolean force)
|
||||
{
|
||||
g_autoptr (AutoarExtractor) extractor = NULL;
|
||||
g_autoptr (JsonObject) metadata = NULL;
|
||||
g_autoptr (GFile) cachedir = NULL;
|
||||
g_autoptr (GFile) tmpdir = NULL;
|
||||
g_autoptr (GFile) src = NULL;
|
||||
g_autoptr (GFile) dst = NULL;
|
||||
g_autoptr (GFile) dstdir = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autofree char *cwd = NULL;
|
||||
const char *uuid;
|
||||
|
||||
cwd = g_get_current_dir ();
|
||||
src = g_file_new_for_commandline_arg_and_cwd (bundle, cwd);
|
||||
cachedir = g_file_new_for_path (g_get_user_cache_dir ());
|
||||
|
||||
extractor = autoar_extractor_new (src, cachedir);
|
||||
|
||||
g_signal_connect (extractor, "error", G_CALLBACK (on_error), &error);
|
||||
g_signal_connect (extractor, "decide-destination", G_CALLBACK (on_decide_destination), &tmpdir);
|
||||
|
||||
autoar_extractor_start (extractor, NULL);
|
||||
|
||||
if (error != NULL)
|
||||
goto err;
|
||||
|
||||
metadata = load_metadata (tmpdir, &error);
|
||||
if (metadata == NULL)
|
||||
goto err;
|
||||
|
||||
dstdir = g_file_new_build_filename (g_get_user_data_dir (),
|
||||
"gnome-shell", "extensions", NULL);
|
||||
|
||||
if (!g_file_make_directory_with_parents (dstdir, NULL, &error))
|
||||
{
|
||||
if (error->code == G_IO_ERROR_EXISTS)
|
||||
g_clear_error (&error);
|
||||
else
|
||||
goto err;
|
||||
}
|
||||
|
||||
uuid = json_object_get_string_member (metadata, "uuid");
|
||||
dst = g_file_get_child (dstdir, uuid);
|
||||
|
||||
if (g_file_query_exists (dst, NULL))
|
||||
{
|
||||
if (!force)
|
||||
{
|
||||
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_EXISTS,
|
||||
"%s exists and --force was not specified", uuid);
|
||||
goto err;
|
||||
}
|
||||
else if (!file_delete_recursively (dst, &error))
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_file_move (tmpdir, dst, G_FILE_COPY_NONE, NULL, NULL, NULL, &error))
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
if (error != NULL)
|
||||
g_printerr ("%s\n", error->message);
|
||||
|
||||
if (tmpdir != NULL)
|
||||
file_delete_recursively (tmpdir, NULL);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int
|
||||
handle_install (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
g_autoptr (GOptionContext) context = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_auto (GStrv) filenames = NULL;
|
||||
gboolean force = FALSE;
|
||||
GOptionEntry entries[] = {
|
||||
{ .long_name = "force", .short_name = 'f',
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &force,
|
||||
.description = _("Overwrite an existing extension") },
|
||||
{ .long_name = G_OPTION_REMAINING,
|
||||
.arg_description =_("EXTENSION_BUNDLE"),
|
||||
.arg = G_OPTION_ARG_FILENAME_ARRAY, .arg_data = &filenames },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
g_set_prgname ("gnome-extensions install");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Install an extension bundle"));
|
||||
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 (filenames == NULL)
|
||||
{
|
||||
show_help (context, _("No extension bundle specified"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_strv_length (filenames) > 1)
|
||||
{
|
||||
show_help (context, _("More than one extension bundle specified"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return install_extension (*filenames, force);
|
||||
}
|
179
subprojects/extensions-tool/src/command-list.c
Normal file
179
subprojects/extensions-tool/src/command-list.c
Normal file
@ -0,0 +1,179 @@
|
||||
/* command-list.c
|
||||
*
|
||||
* Copyright 2018 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"
|
||||
|
||||
|
||||
typedef enum {
|
||||
LIST_FLAGS_NONE = 0,
|
||||
LIST_FLAGS_USER = 1 << 0,
|
||||
LIST_FLAGS_SYSTEM = 1 << 1,
|
||||
LIST_FLAGS_ENABLED = 1 << 2,
|
||||
LIST_FLAGS_DISABLED = 1 << 3,
|
||||
LIST_FLAGS_NO_PREFS = 1 << 4
|
||||
} ListFilterFlags;
|
||||
|
||||
static gboolean
|
||||
list_extensions (ListFilterFlags filter, DisplayFormat format)
|
||||
{
|
||||
g_autoptr (GDBusProxy) proxy = NULL;
|
||||
g_autoptr (GVariant) response = NULL;
|
||||
g_autoptr (GVariant) extensions = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
gboolean needs_newline = FALSE;
|
||||
GVariantIter iter;
|
||||
GVariant *value;
|
||||
char *uuid;
|
||||
|
||||
proxy = get_shell_proxy (&error);
|
||||
if (proxy == NULL)
|
||||
return FALSE;
|
||||
|
||||
response = g_dbus_proxy_call_sync (proxy,
|
||||
"ListExtensions",
|
||||
NULL,
|
||||
0,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (response == NULL)
|
||||
return FALSE;
|
||||
|
||||
extensions = g_variant_get_child_value (response, 0);
|
||||
|
||||
g_variant_iter_init (&iter, extensions);
|
||||
while (g_variant_iter_loop (&iter, "{s@a{sv}}", &uuid, &value))
|
||||
{
|
||||
g_autoptr (GVariantDict) info = NULL;
|
||||
double type, state;
|
||||
gboolean has_prefs;
|
||||
|
||||
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, "hasPrefs", "b", &has_prefs);
|
||||
|
||||
if (type == TYPE_USER && (filter & LIST_FLAGS_USER) == 0)
|
||||
continue;
|
||||
|
||||
if (type == TYPE_SYSTEM && (filter & LIST_FLAGS_SYSTEM) == 0)
|
||||
continue;
|
||||
|
||||
if (state == STATE_ENABLED && (filter & LIST_FLAGS_ENABLED) == 0)
|
||||
continue;
|
||||
|
||||
if (state != STATE_ENABLED && (filter & LIST_FLAGS_DISABLED) == 0)
|
||||
continue;
|
||||
|
||||
if (!has_prefs && (filter & LIST_FLAGS_NO_PREFS) == 0)
|
||||
continue;
|
||||
|
||||
if (needs_newline)
|
||||
g_print ("\n");
|
||||
|
||||
print_extension_info (info, format);
|
||||
needs_newline = (format != DISPLAY_ONELINE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
handle_list (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
g_autoptr (GOptionContext) context = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
int flags = LIST_FLAGS_NONE;
|
||||
gboolean details = FALSE;
|
||||
gboolean user = FALSE;
|
||||
gboolean system = FALSE;
|
||||
gboolean enabled = FALSE;
|
||||
gboolean disabled = FALSE;
|
||||
gboolean has_prefs = FALSE;
|
||||
GOptionEntry entries[] = {
|
||||
{ .long_name = "user",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &user,
|
||||
.description = _("Show user-installed extensions") },
|
||||
{ .long_name = "system",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &system,
|
||||
.description = _("Show system-installed extensions") },
|
||||
{ .long_name = "enabled",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &enabled,
|
||||
.description = _("Show enabled extensions") },
|
||||
{ .long_name = "disabled",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &disabled,
|
||||
.description = _("Show disabled extensions") },
|
||||
{ .long_name = "prefs",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &has_prefs,
|
||||
.description = _("Show extensions with preferences") },
|
||||
{ .long_name = "details", .short_name = 'd',
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &details,
|
||||
.description = _("Print extension details") },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
g_set_prgname ("gnome-extensions list");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("List installed extensions"));
|
||||
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 (argc > 1)
|
||||
{
|
||||
show_help (context, _("Unknown arguments"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (user || !system)
|
||||
flags |= LIST_FLAGS_USER;
|
||||
|
||||
if (system || !user)
|
||||
flags |= LIST_FLAGS_SYSTEM;
|
||||
|
||||
if (enabled || !disabled)
|
||||
flags |= LIST_FLAGS_ENABLED;
|
||||
|
||||
if (disabled || !enabled)
|
||||
flags |= LIST_FLAGS_DISABLED;
|
||||
|
||||
if (!has_prefs)
|
||||
flags |= LIST_FLAGS_NO_PREFS;
|
||||
|
||||
return list_extensions (flags, details ? DISPLAY_DETAILED
|
||||
: DISPLAY_ONELINE) ? 0 : 2;
|
||||
}
|
515
subprojects/extensions-tool/src/command-pack.c
Normal file
515
subprojects/extensions-tool/src/command-pack.c
Normal file
@ -0,0 +1,515 @@
|
||||
/* command-pack.c
|
||||
*
|
||||
* Copyright 2018 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 <gnome-autoar/gnome-autoar.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
typedef struct _ExtensionPack {
|
||||
GHashTable *files;
|
||||
JsonObject *metadata;
|
||||
GFile *tmpdir;
|
||||
char *srcdir;
|
||||
} ExtensionPack;
|
||||
|
||||
static void extension_pack_free (ExtensionPack *);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ExtensionPack, extension_pack_free);
|
||||
|
||||
static ExtensionPack *
|
||||
extension_pack_new (const char *srcdir)
|
||||
{
|
||||
ExtensionPack *pack = g_new0 (ExtensionPack, 1);
|
||||
pack->srcdir = g_strdup (srcdir);
|
||||
pack->files = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_object_unref);
|
||||
return pack;
|
||||
}
|
||||
|
||||
static void
|
||||
extension_pack_free (ExtensionPack *pack)
|
||||
{
|
||||
if (pack->tmpdir)
|
||||
file_delete_recursively (pack->tmpdir, NULL);
|
||||
|
||||
g_clear_pointer (&pack->files, g_hash_table_destroy);
|
||||
g_clear_pointer (&pack->metadata, json_object_unref);
|
||||
g_clear_pointer (&pack->srcdir, g_free);
|
||||
g_clear_object (&pack->tmpdir);
|
||||
g_free (pack);
|
||||
}
|
||||
|
||||
static void
|
||||
extension_pack_add_source (ExtensionPack *pack,
|
||||
const char *filename)
|
||||
{
|
||||
g_autoptr (GFile) file = NULL;
|
||||
file = g_file_new_for_commandline_arg_and_cwd (filename, pack->srcdir);
|
||||
if (g_file_query_exists (file, NULL))
|
||||
g_hash_table_insert (pack->files,
|
||||
g_path_get_basename (filename), g_steal_pointer (&file));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
extension_pack_check_required_file (ExtensionPack *pack,
|
||||
const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
if (!g_hash_table_contains (pack->files, filename))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Missing %s in extension pack", filename);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ensure_tmpdir (ExtensionPack *pack,
|
||||
GError **error)
|
||||
{
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
if (pack->tmpdir != NULL)
|
||||
return TRUE;
|
||||
|
||||
path = g_dir_make_tmp ("gnome-extensions.XXXXXX", error);
|
||||
if (path != NULL)
|
||||
pack->tmpdir = g_file_new_for_path (path);
|
||||
|
||||
return pack->tmpdir != NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ensure_metadata (ExtensionPack *pack,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (JsonParser) parser = NULL;
|
||||
g_autoptr (GInputStream) stream = NULL;
|
||||
GFile *file = NULL;
|
||||
|
||||
if (pack->metadata != NULL)
|
||||
return TRUE;
|
||||
|
||||
if (!extension_pack_check_required_file (pack, "metadata.json", error))
|
||||
return FALSE;
|
||||
|
||||
file = g_hash_table_lookup (pack->files, "metadata.json");
|
||||
stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
|
||||
|
||||
if (stream == NULL)
|
||||
return FALSE;
|
||||
|
||||
parser = json_parser_new_immutable ();
|
||||
|
||||
if (!json_parser_load_from_stream (parser, stream, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
pack->metadata = json_node_dup_object (json_parser_get_root (parser));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
extension_pack_add_schemas (ExtensionPack *pack,
|
||||
char **schemas,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GSubprocess) proc = NULL;
|
||||
g_autoptr (GFile) dstdir = NULL;
|
||||
g_autofree char *dstpath = NULL;
|
||||
char **s;
|
||||
|
||||
if (!ensure_tmpdir (pack, error))
|
||||
return FALSE;
|
||||
|
||||
dstdir = g_file_get_child (pack->tmpdir, "schemas");
|
||||
if (!g_file_make_directory (dstdir, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
for (s = schemas; s && *s; s++)
|
||||
{
|
||||
g_autoptr (GFile) src = NULL;
|
||||
g_autoptr (GFile) dst = NULL;
|
||||
g_autofree char *basename = NULL;
|
||||
|
||||
src = g_file_new_for_commandline_arg_and_cwd (*s, pack->srcdir);
|
||||
|
||||
basename = g_file_get_basename (src);
|
||||
dst = g_file_get_child (dstdir, basename);
|
||||
|
||||
if (!g_file_copy (src, dst, G_FILE_COPY_NONE, NULL, NULL, NULL, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dstpath = g_file_get_path (dstdir);
|
||||
proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_SILENCE, error,
|
||||
"glib-compile-schemas", "--strict", dstpath, NULL);
|
||||
|
||||
if (!g_subprocess_wait_check (proc, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
g_hash_table_insert (pack->files,
|
||||
g_strdup ("schemas"), g_steal_pointer (&dstdir));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
extension_pack_add_locales (ExtensionPack *pack,
|
||||
const char *podir,
|
||||
const char *gettext_domain,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GFile) dstdir = NULL;
|
||||
g_autoptr (GFile) srcdir = NULL;
|
||||
g_autoptr (GFileEnumerator) file_enum = NULL;
|
||||
g_autofree char *dstpath = NULL;
|
||||
g_autofree char *moname = NULL;
|
||||
GFile *child;
|
||||
GFileInfo *info;
|
||||
|
||||
if (!ensure_tmpdir (pack, error))
|
||||
return FALSE;
|
||||
|
||||
dstdir = g_file_get_child (pack->tmpdir, "locale");
|
||||
if (!g_file_make_directory (dstdir, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
srcdir = g_file_new_for_commandline_arg_and_cwd (podir, pack->srcdir);
|
||||
file_enum = g_file_enumerate_children (srcdir,
|
||||
G_FILE_ATTRIBUTE_STANDARD_NAME,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL,
|
||||
error);
|
||||
if (file_enum == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (gettext_domain == NULL)
|
||||
{
|
||||
if (!ensure_metadata (pack, error))
|
||||
return FALSE;
|
||||
|
||||
if (json_object_has_member (pack->metadata, "gettext-domain"))
|
||||
gettext_domain = json_object_get_string_member (pack->metadata,
|
||||
"gettext-domain");
|
||||
else
|
||||
gettext_domain = json_object_get_string_member (pack->metadata,
|
||||
"uuid");
|
||||
}
|
||||
|
||||
dstpath = g_file_get_path (dstdir);
|
||||
moname = g_strdup_printf ("%s.mo", gettext_domain);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
g_autoptr (GSubprocess) proc = NULL;
|
||||
g_autoptr (GFile) modir = NULL;
|
||||
g_autofree char *popath = NULL;
|
||||
g_autofree char *mopath = NULL;
|
||||
g_autofree char *lang = NULL;
|
||||
const char *name;
|
||||
|
||||
if (!g_file_enumerator_iterate (file_enum, &info, &child, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
if (info == NULL)
|
||||
break;
|
||||
|
||||
name = g_file_info_get_name (info);
|
||||
if (!g_str_has_suffix (name, ".po"))
|
||||
continue;
|
||||
|
||||
lang = g_strndup (name, strlen (name) - 3 /* strlen (".po") */);
|
||||
modir = g_file_new_build_filename (dstpath, lang, "LC_MESSAGES", NULL);
|
||||
if (!g_file_make_directory_with_parents (modir, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
mopath = g_build_filename (dstpath, lang, "LC_MESSAGES", moname, NULL);
|
||||
popath = g_file_get_path (child);
|
||||
|
||||
proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_SILENCE, error,
|
||||
"msgfmt", "-o", mopath, popath, NULL);
|
||||
|
||||
if (!g_subprocess_wait_check (proc, NULL, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_hash_table_insert (pack->files,
|
||||
g_strdup ("locale"), g_steal_pointer (&dstdir));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_error (AutoarCompressor *compressor,
|
||||
GError *error,
|
||||
gpointer data)
|
||||
{
|
||||
*((GError **)data) = g_error_copy (error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
extension_pack_compress (ExtensionPack *pack,
|
||||
const char *outdir,
|
||||
gboolean overwrite,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (AutoarCompressor) compressor = NULL;
|
||||
g_autoptr (GError) err = NULL;
|
||||
g_autoptr (GFile) outfile = NULL;
|
||||
g_autofree char *name = NULL;
|
||||
const char *uuid;
|
||||
|
||||
if (!ensure_metadata (pack, error))
|
||||
return FALSE;
|
||||
|
||||
uuid = json_object_get_string_member (pack->metadata, "uuid");
|
||||
name = g_strdup_printf ("%s.shell-extension.zip", uuid);
|
||||
outfile = g_file_new_for_commandline_arg_and_cwd (name, outdir);
|
||||
|
||||
if (g_file_query_exists (outfile, NULL))
|
||||
{
|
||||
if (!overwrite)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
|
||||
"%s exists and --force was not specified", name);
|
||||
return FALSE;
|
||||
}
|
||||
else if (!g_file_delete (outfile, NULL, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
compressor = autoar_compressor_new (g_hash_table_get_values (pack->files),
|
||||
outfile,
|
||||
AUTOAR_FORMAT_ZIP,
|
||||
AUTOAR_FILTER_NONE,
|
||||
FALSE);
|
||||
autoar_compressor_set_output_is_dest (compressor, TRUE);
|
||||
|
||||
g_signal_connect (compressor, "error", G_CALLBACK (on_error), err);
|
||||
|
||||
autoar_compressor_start (compressor, NULL);
|
||||
|
||||
if (err != NULL)
|
||||
{
|
||||
g_propagate_error (error, err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static char **
|
||||
find_schemas (const char *basepath,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GFile) basedir = NULL;
|
||||
g_autoptr (GFile) schemadir = NULL;
|
||||
g_autoptr (GFileEnumerator) file_enum = NULL;
|
||||
g_autoptr (GPtrArray) schemas = NULL;
|
||||
GFile *child;
|
||||
GFileInfo *info;
|
||||
|
||||
basedir = g_file_new_for_path (basepath);
|
||||
schemadir = g_file_get_child (basedir, "schemas");
|
||||
file_enum = g_file_enumerate_children (schemadir,
|
||||
G_FILE_ATTRIBUTE_STANDARD_NAME,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, error);
|
||||
|
||||
if (error && *error)
|
||||
{
|
||||
if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) ||
|
||||
g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY))
|
||||
g_clear_error (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
schemas = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!g_file_enumerator_iterate (file_enum, &info, &child, NULL, error))
|
||||
return NULL;
|
||||
|
||||
if (child == NULL)
|
||||
break;
|
||||
|
||||
if (!g_str_has_suffix (g_file_info_get_name (info), ".gschema.xml"))
|
||||
continue;
|
||||
|
||||
g_ptr_array_add (schemas, g_file_get_relative_path (basedir, child));
|
||||
}
|
||||
g_ptr_array_add (schemas, NULL);
|
||||
|
||||
return (char **)g_ptr_array_free (g_ptr_array_ref (schemas), FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
pack_extension (char *srcdir,
|
||||
char *dstdir,
|
||||
gboolean force,
|
||||
char **extra_sources,
|
||||
char **schemas,
|
||||
char *podir,
|
||||
char *gettext_domain)
|
||||
{
|
||||
g_autoptr (ExtensionPack) pack = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
char **s;
|
||||
|
||||
pack = extension_pack_new (srcdir);
|
||||
extension_pack_add_source (pack, "extension.js");
|
||||
extension_pack_add_source (pack, "metadata.json");
|
||||
extension_pack_add_source (pack, "stylesheet.css");
|
||||
extension_pack_add_source (pack, "prefs.js");
|
||||
|
||||
for (s = extra_sources; s && *s; s++)
|
||||
extension_pack_add_source (pack, *s);
|
||||
|
||||
if (!extension_pack_check_required_file (pack, "extension.js", &error))
|
||||
goto err;
|
||||
|
||||
if (!extension_pack_check_required_file (pack, "metadata.json", &error))
|
||||
goto err;
|
||||
|
||||
if (schemas == NULL)
|
||||
schemas = find_schemas (srcdir, &error);
|
||||
|
||||
if (schemas != NULL)
|
||||
extension_pack_add_schemas (pack, schemas, &error);
|
||||
|
||||
if (error)
|
||||
goto err;
|
||||
|
||||
if (podir == NULL)
|
||||
{
|
||||
g_autoptr (GFile) dir = NULL;
|
||||
|
||||
dir = g_file_new_for_commandline_arg_and_cwd ("po", srcdir);
|
||||
if (g_file_query_exists (dir, NULL))
|
||||
podir = (char *)"po";
|
||||
}
|
||||
|
||||
if (podir != NULL)
|
||||
extension_pack_add_locales (pack, podir, gettext_domain, &error);
|
||||
|
||||
if (error)
|
||||
goto err;
|
||||
|
||||
extension_pack_compress (pack, dstdir, force, &error);
|
||||
|
||||
err:
|
||||
if (error)
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
handle_pack (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
g_autoptr (GOptionContext) context = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_auto(GStrv) extra_sources = NULL;
|
||||
g_auto(GStrv) schemas = NULL;
|
||||
g_auto(GStrv) srcdirs = NULL;
|
||||
g_autofree char *podir = NULL;
|
||||
g_autofree char *srcdir = NULL;
|
||||
g_autofree char *dstdir = NULL;
|
||||
g_autofree char *gettext_domain = NULL;
|
||||
gboolean force = FALSE;
|
||||
GOptionEntry entries[] = {
|
||||
{ .long_name = "extra-source",
|
||||
.arg = G_OPTION_ARG_FILENAME_ARRAY, .arg_data = &extra_sources,
|
||||
.arg_description = _("FILE"),
|
||||
.description = _("Additional source to include in the bundle") },
|
||||
{ .long_name = "schema",
|
||||
.arg = G_OPTION_ARG_FILENAME_ARRAY, .arg_data = &schemas,
|
||||
.arg_description = _("SCHEMA"),
|
||||
.description = _("A GSettings schema that should be included") },
|
||||
{ .long_name = "podir",
|
||||
.arg_description = _("DIRECTORY"),
|
||||
.arg = G_OPTION_ARG_FILENAME, .arg_data = &podir,
|
||||
.description = _("The directory where translations are found") },
|
||||
{ .long_name = "gettext-domain",
|
||||
.arg_description = _("DOMAIN"),
|
||||
.arg = G_OPTION_ARG_STRING, .arg_data = &gettext_domain,
|
||||
.description = _("The gettext domain to use for translations") },
|
||||
{ .long_name = "force", .short_name = 'f',
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &force,
|
||||
.description = _("Overwrite an existing pack") },
|
||||
{ .long_name = "out-dir", .short_name = 'o',
|
||||
.arg_description = _("DIRECTORY"),
|
||||
.arg = G_OPTION_ARG_FILENAME, .arg_data = &dstdir,
|
||||
.description = _("The directory where the pack should be created") },
|
||||
{ .long_name = G_OPTION_REMAINING,
|
||||
.arg_description =_("SOURCE_DIRECTORY"),
|
||||
.arg = G_OPTION_ARG_FILENAME_ARRAY, .arg_data = &srcdirs },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
g_set_prgname ("gnome-extensions pack");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Create an extension bundle"));
|
||||
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 (srcdirs)
|
||||
{
|
||||
if (g_strv_length (srcdirs) > 1)
|
||||
{
|
||||
show_help (context, _("More than one source directory specified"));
|
||||
return 1;
|
||||
}
|
||||
srcdir = g_strdup (*srcdirs);
|
||||
}
|
||||
else
|
||||
{
|
||||
srcdir = g_get_current_dir ();
|
||||
}
|
||||
|
||||
if (dstdir == NULL)
|
||||
dstdir = g_get_current_dir ();
|
||||
|
||||
return pack_extension (srcdir, dstdir, force,
|
||||
extra_sources, schemas, podir, gettext_domain);
|
||||
}
|
117
subprojects/extensions-tool/src/command-prefs.c
Normal file
117
subprojects/extensions-tool/src/command-prefs.c
Normal 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;
|
||||
}
|
84
subprojects/extensions-tool/src/command-reset.c
Normal file
84
subprojects/extensions-tool/src/command-reset.c
Normal file
@ -0,0 +1,84 @@
|
||||
/* command-reset.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
|
||||
reset_extension (const char *uuid)
|
||||
{
|
||||
g_autoptr(GSettings) settings = get_shell_settings();
|
||||
|
||||
if (settings == NULL)
|
||||
return FALSE;
|
||||
|
||||
return settings_list_remove (settings, "enabled-extensions", uuid) &&
|
||||
settings_list_remove (settings, "disabled-extensions", uuid);
|
||||
}
|
||||
|
||||
int
|
||||
handle_reset (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 reset");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Reset an extension"));
|
||||
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 reset_extension (*uuids) ? 0 : 2;
|
||||
}
|
99
subprojects/extensions-tool/src/command-uninstall.c
Normal file
99
subprojects/extensions-tool/src/command-uninstall.c
Normal file
@ -0,0 +1,99 @@
|
||||
/* commands-uninstall.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
|
||||
uninstall_extension (const char *uuid)
|
||||
{
|
||||
g_autoptr (GDBusProxy) proxy = NULL;
|
||||
g_autoptr (GVariant) response = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
gboolean success = FALSE;
|
||||
|
||||
proxy = get_shell_proxy (&error);
|
||||
if (proxy == NULL)
|
||||
return FALSE;
|
||||
|
||||
response = g_dbus_proxy_call_sync (proxy,
|
||||
"UninstallExtension",
|
||||
g_variant_new ("(s)", uuid),
|
||||
0,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (response == NULL)
|
||||
return FALSE;
|
||||
|
||||
g_variant_get (response, "(b)", &success);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
int
|
||||
handle_uninstall (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 uninstall");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Uninstall an extension"));
|
||||
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 uninstall_extension (*uuids) ? 0 : 2;
|
||||
}
|
38
subprojects/extensions-tool/src/commands.h
Normal file
38
subprojects/extensions-tool/src/commands.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* commands.h
|
||||
*
|
||||
* Copyright 2018 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
int handle_enable (int argc, char *argv[], gboolean do_help);
|
||||
int handle_disable (int argc, char *argv[], gboolean do_help);
|
||||
int handle_reset (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);
|
||||
int handle_uninstall (int argc, char *argv[], gboolean do_help);
|
||||
|
||||
G_END_DECLS
|
67
subprojects/extensions-tool/src/common.h
Normal file
67
subprojects/extensions-tool/src/common.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* common.h
|
||||
*
|
||||
* Copyright 2018 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
TYPE_SYSTEM = 1,
|
||||
TYPE_USER
|
||||
} ExtensionType;
|
||||
|
||||
typedef enum {
|
||||
STATE_ENABLED = 1,
|
||||
STATE_DISABLED,
|
||||
STATE_ERROR,
|
||||
STATE_OUT_OF_DATE,
|
||||
STATE_DOWNLOADING,
|
||||
STATE_INITIALIZED,
|
||||
|
||||
STATE_UNINSTALLED = 99
|
||||
} ExtensionState;
|
||||
|
||||
typedef enum {
|
||||
DISPLAY_ONELINE,
|
||||
DISPLAY_DETAILED
|
||||
} DisplayFormat;
|
||||
|
||||
void show_help (GOptionContext *context,
|
||||
const char *message);
|
||||
|
||||
void print_extension_info (GVariantDict *info,
|
||||
DisplayFormat format);
|
||||
|
||||
GDBusProxy *get_shell_proxy (GError **error);
|
||||
GSettings *get_shell_settings (void);
|
||||
|
||||
gboolean settings_list_add (GSettings *settings,
|
||||
const char *key,
|
||||
const char *value);
|
||||
gboolean settings_list_remove (GSettings *settings,
|
||||
const char *key,
|
||||
const char *value);
|
||||
|
||||
gboolean file_delete_recursively (GFile *file,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/gnome/extensions-tool">
|
||||
<file>template/extension.js</file>
|
||||
<file>template/stylesheet.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
340
subprojects/extensions-tool/src/main.c
Normal file
340
subprojects/extensions-tool/src/main.c
Normal file
@ -0,0 +1,340 @@
|
||||
/* main.c
|
||||
*
|
||||
* Copyright 2018 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 <gio/gio.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "commands.h"
|
||||
#include "common.h"
|
||||
|
||||
static const char *
|
||||
extension_state_to_string (ExtensionState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case STATE_ENABLED:
|
||||
return "ENABLED";
|
||||
case STATE_DISABLED:
|
||||
return "DISABLED";
|
||||
case STATE_ERROR:
|
||||
return "ERROR";
|
||||
case STATE_OUT_OF_DATE:
|
||||
return "OUT OF DATE";
|
||||
case STATE_DOWNLOADING:
|
||||
return "DOWNLOADING";
|
||||
case STATE_INITIALIZED:
|
||||
return "INITIALIZED";
|
||||
case STATE_UNINSTALLED:
|
||||
return "UNINSTALLED";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
void
|
||||
show_help (GOptionContext *context, const char *message)
|
||||
{
|
||||
g_autofree char *help = NULL;
|
||||
|
||||
if (message)
|
||||
g_printerr ("gnome-extensions: %s\n\n", message);
|
||||
|
||||
help = g_option_context_get_help (context, TRUE, NULL);
|
||||
g_printerr ("%s", help);
|
||||
}
|
||||
|
||||
GDBusProxy *
|
||||
get_shell_proxy (GError **error)
|
||||
{
|
||||
return g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.gnome.Shell",
|
||||
"/org/gnome/Shell",
|
||||
"org.gnome.Shell.Extensions",
|
||||
NULL,
|
||||
error);
|
||||
}
|
||||
|
||||
GSettings *
|
||||
get_shell_settings (void)
|
||||
{
|
||||
g_autoptr (GSettingsSchema) schema = NULL;
|
||||
GSettingsSchemaSource *schema_source;
|
||||
|
||||
schema_source = g_settings_schema_source_get_default ();
|
||||
schema = g_settings_schema_source_lookup (schema_source,
|
||||
"org.gnome.shell",
|
||||
TRUE);
|
||||
|
||||
if (schema == NULL)
|
||||
return NULL;
|
||||
|
||||
return g_settings_new_full (schema, NULL, NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
settings_list_add (GSettings *settings,
|
||||
const char *key,
|
||||
const char *value)
|
||||
{
|
||||
g_auto(GStrv) list = NULL;
|
||||
g_auto(GStrv) new_value = NULL;
|
||||
guint n_values;
|
||||
int i;
|
||||
|
||||
if (!g_settings_is_writable (settings, key))
|
||||
return FALSE;
|
||||
|
||||
list = g_settings_get_strv (settings, key);
|
||||
|
||||
if (g_strv_contains ((const char **)list, value))
|
||||
return TRUE;
|
||||
|
||||
n_values = g_strv_length (list);
|
||||
new_value = g_new0 (char *, n_values + 2);
|
||||
for (i = 0; i < n_values; i++)
|
||||
new_value[i] = g_strdup (list[i]);
|
||||
new_value[i] = g_strdup (value);
|
||||
|
||||
g_settings_set_strv (settings, key, (const char **)new_value);
|
||||
g_settings_sync ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
settings_list_remove (GSettings *settings,
|
||||
const char *key,
|
||||
const char *value)
|
||||
{
|
||||
g_auto(GStrv) list = NULL;
|
||||
g_auto(GStrv) new_value = NULL;
|
||||
const char **s;
|
||||
guint n_values;
|
||||
int i;
|
||||
|
||||
if (!g_settings_is_writable (settings, key))
|
||||
return FALSE;
|
||||
|
||||
list = g_settings_get_strv (settings, key);
|
||||
|
||||
if (!g_strv_contains ((const char **)list, value))
|
||||
return TRUE;
|
||||
|
||||
n_values = g_strv_length (list);
|
||||
new_value = g_new0 (char *, n_values);
|
||||
i = 0;
|
||||
for (s = (const char **)list; *s != NULL; s++)
|
||||
if (!g_str_equal (*s, value))
|
||||
new_value[i++] = g_strdup (*s);
|
||||
|
||||
g_settings_set_strv (settings, key, (const char **)new_value);
|
||||
g_settings_sync ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
print_extension_info (GVariantDict *info,
|
||||
DisplayFormat format)
|
||||
{
|
||||
const char *uuid, *name, *desc, *path, *url, *author;
|
||||
double state, version;
|
||||
|
||||
g_variant_dict_lookup (info, "uuid", "&s", &uuid);
|
||||
g_print ("%s\n", uuid);
|
||||
|
||||
if (format == DISPLAY_ONELINE)
|
||||
return;
|
||||
|
||||
g_variant_dict_lookup (info, "name", "&s", &name);
|
||||
g_print (" %s: %s\n", _("Name"), name);
|
||||
|
||||
g_variant_dict_lookup (info, "description", "&s", &desc);
|
||||
g_print (" %s: %s\n", _("Description"), desc);
|
||||
|
||||
g_variant_dict_lookup (info, "path", "&s", &path);
|
||||
g_print (" %s: %s\n", _("Path"), path);
|
||||
|
||||
if (g_variant_dict_lookup (info, "url", "&s", &url))
|
||||
g_print (" %s: %s\n", _("URL"), url);
|
||||
|
||||
if (g_variant_dict_lookup (info, "original-author", "&s", &author))
|
||||
g_print (" %s: %s\n", _("Original author"), author);
|
||||
|
||||
if (g_variant_dict_lookup (info, "version", "d", &version))
|
||||
g_print (" %s: %.0f\n", _("Version"), version);
|
||||
|
||||
g_variant_dict_lookup (info, "state", "d", &state);
|
||||
g_print (" %s: %s\n", _("State"), extension_state_to_string (state));
|
||||
}
|
||||
|
||||
gboolean
|
||||
file_delete_recursively (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GFileEnumerator) file_enum = NULL;
|
||||
GFile *child;
|
||||
|
||||
file_enum = g_file_enumerate_children (file, NULL, 0, NULL, NULL);
|
||||
if (file_enum)
|
||||
while (TRUE)
|
||||
{
|
||||
if (!g_file_enumerator_iterate (file_enum, NULL, &child, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
if (child == NULL)
|
||||
break;
|
||||
|
||||
if (!file_delete_recursively (child, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return g_file_delete (file, NULL, error);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
handle_version (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
if (do_help || argc > 1)
|
||||
{
|
||||
if (!do_help)
|
||||
g_printerr ("gnome-extensions: %s\n\n", _("“version” takes no arguments"));
|
||||
|
||||
g_printerr ("%s\n", _("Usage:"));
|
||||
g_printerr (" gnome-extensions version\n");
|
||||
g_printerr ("\n");
|
||||
g_printerr ("%s\n", _("Print version information and exit."));
|
||||
|
||||
return do_help ? 0 : 2;
|
||||
}
|
||||
|
||||
g_print ("%s\n", VERSION);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usage (void)
|
||||
{
|
||||
g_autofree char *help_command = NULL;
|
||||
|
||||
help_command = g_strdup_printf ("gnome-extensions help %s", _("COMMAND"));
|
||||
|
||||
g_printerr ("%s\n", _("Usage:"));
|
||||
g_printerr (" gnome-extensions %s %s\n", _("COMMAND"), _("[ARGS…]"));
|
||||
g_printerr ("\n");
|
||||
g_printerr ("%s\n", _("Commands:"));
|
||||
g_printerr (" help %s\n", _("Print help"));
|
||||
g_printerr (" version %s\n", _("Print version"));
|
||||
g_printerr (" enable %s\n", _("Enable extension"));
|
||||
g_printerr (" disable %s\n", _("Disable extension"));
|
||||
g_printerr (" reset %s\n", _("Reset extension"));
|
||||
g_printerr (" uninstall %s\n", _("Uninstall extension"));
|
||||
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"));
|
||||
g_printerr ("\n");
|
||||
g_printerr (_("Use “%s” to get detailed help.\n"), help_command);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
const char *command;
|
||||
gboolean do_help = FALSE;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
|
||||
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
#endif
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
usage ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
command = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (g_str_equal (command, "help"))
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
usage ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
command = argv[1];
|
||||
do_help = TRUE;
|
||||
}
|
||||
}
|
||||
else if (g_str_equal (command, "--help"))
|
||||
{
|
||||
usage ();
|
||||
return 0;
|
||||
}
|
||||
else if (g_str_equal (command, "--version"))
|
||||
{
|
||||
command = "version";
|
||||
}
|
||||
|
||||
if (g_str_equal (command, "version"))
|
||||
return handle_version (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "enable"))
|
||||
return handle_enable (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "disable"))
|
||||
return handle_disable (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "reset"))
|
||||
return handle_reset (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "list"))
|
||||
return handle_list (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "info"))
|
||||
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"))
|
||||
return handle_pack (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "install"))
|
||||
return handle_install (argc, argv, do_help);
|
||||
else if (g_str_equal (command, "uninstall"))
|
||||
return handle_uninstall (argc, argv, do_help);
|
||||
else
|
||||
usage ();
|
||||
|
||||
return 1;
|
||||
}
|
34
subprojects/extensions-tool/src/meson.build
Normal file
34
subprojects/extensions-tool/src/meson.build
Normal file
@ -0,0 +1,34 @@
|
||||
config_h = configuration_data()
|
||||
config_h.set_quoted('GETTEXT_PACKAGE', package_name)
|
||||
config_h.set_quoted('VERSION', meson.project_version())
|
||||
config_h.set_quoted('LOCALEDIR', localedir)
|
||||
config_h.set('HAVE_BIND_TEXTDOMAIN_CODESET', cc.has_function('bind_textdomain_codeset'))
|
||||
configure_file(
|
||||
output: 'config.h',
|
||||
configuration: config_h,
|
||||
)
|
||||
|
||||
sources = [
|
||||
'command-create.c',
|
||||
'command-disable.c',
|
||||
'command-enable.c',
|
||||
'command-info.c',
|
||||
'command-install.c',
|
||||
'command-list.c',
|
||||
'command-pack.c',
|
||||
'command-prefs.c',
|
||||
'command-reset.c',
|
||||
'command-uninstall.c',
|
||||
'main.c'
|
||||
]
|
||||
|
||||
resources = gnome.compile_resources('resources',
|
||||
'gnome-extensions-tool.gresource.xml',
|
||||
source_dir: '.'
|
||||
)
|
||||
|
||||
executable('gnome-extensions',
|
||||
sources, resources,
|
||||
dependencies: [gio_dep, gio_unix_dep, autoar_dep, json_dep],
|
||||
install: true
|
||||
)
|
34
subprojects/extensions-tool/src/template/extension.js
Normal file
34
subprojects/extensions-tool/src/template/extension.js
Normal file
@ -0,0 +1,34 @@
|
||||
/* extension.js
|
||||
*
|
||||
* 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 2 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-2.0-or-later
|
||||
*/
|
||||
|
||||
/* exported init */
|
||||
|
||||
class Extension {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
enable() {
|
||||
}
|
||||
|
||||
disable() {
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
return new Extension();
|
||||
}
|
1
subprojects/extensions-tool/src/template/stylesheet.css
Normal file
1
subprojects/extensions-tool/src/template/stylesheet.css
Normal file
@ -0,0 +1 @@
|
||||
/* Add your custom extension styling here */
|
Reference in New Issue
Block a user