From 6b0cbb7076967ac3f22dbda78dedca0ab6c88ffd Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 27 Oct 2021 15:38:41 +0200 Subject: [PATCH] packagekit: Workaround PkControl main context assignment The PkControl has signals for the repository changes and update changes, which the plugin connects to, but those are never delivered, because the main context used for the D-Bus signal delivery is not the main context, but one pushed as a thread default from the pk-control-sync.c. It's even worse, because the GDBusProxy under the PkControl is created on demand, with no way to create it. --- plugins/packagekit/gs-plugin-packagekit.c | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c index 71c8307ed..c7c879b39 100644 --- a/plugins/packagekit/gs-plugin-packagekit.c +++ b/plugins/packagekit/gs-plugin-packagekit.c @@ -1710,10 +1710,25 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict) gs_app_set_install_date (app, timestamp); } +static void +gs_plugin_packagekit_get_properties_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr(GError) error = NULL; + gboolean *pdone = user_data; + if (!pk_control_get_properties_finish (PK_CONTROL (source_object), result, &error)) + g_debug ("Failed to get properties: %s", error->message); + + *pdone = TRUE; + g_main_context_wakeup (NULL); +} + gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginPackagekit *self = GS_PLUGIN_PACKAGEKIT (plugin); + gboolean done = FALSE; self->connection_history = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, @@ -1723,6 +1738,16 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) return FALSE; } + g_mutex_lock (&self->client_mutex_refine); + + /* Only to initialize connection to the D-Bus daemon with the correct GMainContext */ + pk_control_get_properties_async (self->control_refine, cancellable, + gs_plugin_packagekit_get_properties_cb, &done); + while (!done) + g_main_context_iteration (NULL, TRUE); + + g_mutex_unlock (&self->client_mutex_refine); + reload_proxy_settings (self, cancellable); return TRUE; -- GitLab