[gnome-software/1344-fedora-3rd-party-repos-updates-for-f35: 21/26] gs-overview-page: Use fedora-third-party cmdline tool to manage 3rd-party infobar
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1344-fedora-3rd-party-repos-updates-for-f35: 21/26] gs-overview-page: Use fedora-third-party cmdline tool to manage 3rd-party infobar
- Date: Fri, 13 Aug 2021 12:18:25 +0000 (UTC)
commit f9c24725832004aeef43f9596faacefda6f64dc6
Author: Milan Crha <mcrha redhat com>
Date: Thu Aug 12 15:21:23 2021 +0200
gs-overview-page: Use fedora-third-party cmdline tool to manage 3rd-party infobar
New Fedora uses fedora-third-party command line tool to manage
the 3rd-party repositories, thus use it to manage the 3rd-party
info bar.
src/gs-overview-page.c | 222 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 163 insertions(+), 59 deletions(-)
---
diff --git a/src/gs-overview-page.c b/src/gs-overview-page.c
index 8277a7709..2f54aa749 100644
--- a/src/gs-overview-page.c
+++ b/src/gs-overview-page.c
@@ -40,7 +40,8 @@ struct _GsOverviewPage
gchar *category_of_day;
GHashTable *category_hash; /* id : GsCategory */
GSettings *settings;
- GsApp *third_party_repo;
+ gchar *third_party_cmdtool;
+ gboolean third_party_needs_question;
GtkWidget *infobar_third_party;
GtkWidget *label_third_party;
@@ -352,47 +353,15 @@ out:
static void
refresh_third_party_repo (GsOverviewPage *self)
{
- /* only show if never prompted and third party repo is available */
+ /* only show if never prompted and needs checking */
if (g_settings_get_boolean (self->settings, "show-nonfree-prompt") &&
- self->third_party_repo != NULL &&
- gs_app_get_state (self->third_party_repo) == GS_APP_STATE_AVAILABLE) {
+ self->third_party_needs_question) {
gtk_widget_set_visible (self->infobar_third_party, TRUE);
} else {
gtk_widget_set_visible (self->infobar_third_party, FALSE);
}
}
-static void
-resolve_third_party_repo_cb (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GsOverviewPage *self)
-{
- g_autoptr(GError) error = NULL;
- g_autoptr(GsAppList) list = NULL;
-
- /* get the results */
- list = gs_plugin_loader_job_process_finish (plugin_loader, res, &error);
- if (list == NULL) {
- if (g_error_matches (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_CANCELLED)) {
- g_debug ("resolve third party repo cancelled");
- return;
- } else {
- g_warning ("failed to resolve third party repo: %s", error->message);
- return;
- }
- }
-
- /* save results for later */
- g_clear_object (&self->third_party_repo);
- if (gs_app_list_length (list) > 0)
- self->third_party_repo = g_object_ref (gs_app_list_index (list, 0));
-
- /* refresh widget */
- refresh_third_party_repo (self);
-}
-
static gboolean
is_fedora (void)
{
@@ -410,11 +379,55 @@ is_fedora (void)
return FALSE;
}
+static void
+fedora_third_party_query_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GsOverviewPage *self = source_object;
+ g_autoptr(GError) error = NULL;
+ gint exit_status = -1;
+ const gchar *args[] = {
+ "", /* executable */
+ "query",
+ "--quiet",
+ NULL
+ };
+
+ g_return_if_fail (self->third_party_cmdtool != NULL);
+
+ args[0] = self->third_party_cmdtool;
+
+ if (g_spawn_sync (NULL, (gchar **) args, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL, &exit_status,
&error))
+ g_task_return_int (task, WEXITSTATUS (exit_status));
+ else
+ g_task_return_error (task, g_steal_pointer (&error));
+}
+
+static void
+fedora_third_party_query_done_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GsOverviewPage *self = GS_OVERVIEW_PAGE (source_object);
+ g_autoptr(GError) error = NULL;
+ gssize exit_status;
+
+ exit_status = g_task_propagate_int (G_TASK (result), &error);
+
+ if (error)
+ g_warning ("Failed to query '%s': %s", self->third_party_cmdtool, error->message);
+ else
+ self->third_party_needs_question = exit_status == 2;
+
+ refresh_third_party_repo (self);
+}
+
static void
reload_third_party_repo (GsOverviewPage *self)
{
- const gchar *third_party_repo_package = "fedora-workstation-repositories";
- g_autoptr(GsPluginJob) plugin_job = NULL;
+ g_autoptr(GTask) task = NULL;
/* only show if never prompted */
if (!g_settings_get_boolean (self->settings, "show-nonfree-prompt"))
@@ -424,15 +437,113 @@ reload_third_party_repo (GsOverviewPage *self)
if (!is_fedora ())
return;
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH_PROVIDES,
- "search", third_party_repo_package,
- "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION |
- GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES,
- NULL);
- gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
- self->cancellable,
- (GAsyncReadyCallback) resolve_third_party_repo_cb,
- self);
+ if (self->third_party_cmdtool == NULL)
+ self->third_party_cmdtool = g_find_program_in_path ("fedora-third-party");
+
+ if (self->third_party_cmdtool == NULL)
+ return;
+
+ task = g_task_new (self, NULL, fedora_third_party_query_done_cb, NULL);
+ g_task_run_in_thread (task, fedora_third_party_query_thread);
+}
+
+static void
+fedora_third_party_enable_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GsOverviewPage *self = source_object;
+ g_autoptr(GError) error = NULL;
+ gint exit_status = -1;
+ const gchar *args[] = {
+ "pkexec",
+ "", /* executable */
+ "enable",
+ NULL
+ };
+
+ g_return_if_fail (self->third_party_cmdtool != NULL);
+
+ args[1] = self->third_party_cmdtool;
+
+ if (g_spawn_sync (NULL, (gchar **) args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
&exit_status, &error))
+ g_task_return_int (task, WEXITSTATUS (exit_status));
+ else
+ g_task_return_error (task, g_steal_pointer (&error));
+}
+
+static void
+fedora_third_party_enable_done_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GsOverviewPage *self = GS_OVERVIEW_PAGE (source_object);
+ g_autoptr(GError) error = NULL;
+
+ g_task_propagate_int (G_TASK (result), &error);
+
+ if (error)
+ g_warning ("Failed to enable '%s': %s", self->third_party_cmdtool, error->message);
+
+ refresh_third_party_repo (self);
+}
+
+static void
+fedora_third_party_enable (GsOverviewPage *self)
+{
+ g_autoptr(GTask) task = NULL;
+
+ task = g_task_new (self, NULL, fedora_third_party_enable_done_cb, NULL);
+ g_task_run_in_thread (task, fedora_third_party_enable_thread);
+}
+
+static void
+fedora_third_party_disable_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GsOverviewPage *self = source_object;
+ g_autoptr(GError) error = NULL;
+ gint exit_status = -1;
+ const gchar *args[] = {
+ "pkexec",
+ "/usr/lib/fedora-third-party/fedora-third-party-opt-out",
+ NULL
+ };
+
+ g_return_if_fail (self->third_party_cmdtool != NULL);
+
+ if (g_spawn_sync (NULL, (gchar **) args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
&exit_status, &error))
+ g_task_return_int (task, WEXITSTATUS (exit_status));
+ else
+ g_task_return_error (task, g_steal_pointer (&error));
+}
+
+static void
+fedora_third_party_disable_done_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GsOverviewPage *self = GS_OVERVIEW_PAGE (source_object);
+ g_autoptr(GError) error = NULL;
+
+ g_task_propagate_int (G_TASK (result), &error);
+
+ if (error)
+ g_warning ("Failed to disable fedora-third-party: %s", error->message);
+
+ refresh_third_party_repo (self);
+}
+
+static void
+fedora_third_party_disable (GsOverviewPage *self)
+{
+ g_autoptr(GTask) task = NULL;
+
+ task = g_task_new (self, NULL, fedora_third_party_disable_done_cb, NULL);
+ g_task_run_in_thread (task, fedora_third_party_disable_thread);
}
static void
@@ -544,19 +655,12 @@ third_party_response_cb (GtkInfoBar *info_bar,
GsOverviewPage *self)
{
g_settings_set_boolean (self->settings, "show-nonfree-prompt", FALSE);
- if (response_id == GTK_RESPONSE_CLOSE) {
- gtk_widget_hide (self->infobar_third_party);
- return;
- }
- if (response_id != GTK_RESPONSE_YES)
- return;
-
- if (gs_app_get_state (self->third_party_repo) == GS_APP_STATE_AVAILABLE) {
- gs_page_install_app (GS_PAGE (self), self->third_party_repo,
- GS_SHELL_INTERACTION_FULL,
- self->cancellable);
- }
+ if (response_id == GTK_RESPONSE_YES)
+ fedora_third_party_enable (self);
+ else
+ fedora_third_party_disable (self);
+ self->third_party_needs_question = FALSE;
refresh_third_party_repo (self);
}
@@ -688,7 +792,7 @@ gs_overview_page_dispose (GObject *object)
g_clear_object (&self->plugin_loader);
g_clear_object (&self->cancellable);
g_clear_object (&self->settings);
- g_clear_object (&self->third_party_repo);
+ g_clear_pointer (&self->third_party_cmdtool, g_free);
g_clear_pointer (&self->category_of_day, g_free);
g_clear_pointer (&self->category_hash, g_hash_table_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]