From 009851f83c28dbd5f68d9c1778cc718a3b6a067c Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 28 May 2024 17:45:14 +0200 Subject: [PATCH 1/3] gs-shell: Add gs_shell_is_setup() function A helper function, which can determine whether the shell has been already set up or not. To be used to early-exit the application, avoiding unnecessary steps when it'll quit shortly afterwards anyway. --- src/gs-shell.c | 17 +++++++++++++++++ src/gs-shell.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/gs-shell.c b/src/gs-shell.c index 7a6fa362e..2d9dea192 100644 --- a/src/gs-shell.c +++ b/src/gs-shell.c @@ -2196,6 +2196,23 @@ details_page_app_clicked_cb (GsDetailsPage *page, gs_shell_show_app (shell, app); } +/** + * gs_shell_is_running: + * @self: a #GsShell + * + * Check whether the @self has been already set up, which roughly means + * the gs_shell_setup() has been called. + * + * Returns: whether the @self has been already set up + * + * Since: 48 + **/ +gboolean +gs_shell_is_running (GsShell *self) +{ + return self->plugin_loader != NULL; +} + void gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *cancellable) { diff --git a/src/gs-shell.h b/src/gs-shell.h index 896910a45..0b0c41ec0 100644 --- a/src/gs-shell.h +++ b/src/gs-shell.h @@ -79,6 +79,7 @@ void gs_shell_show_extras_search (GsShell *shell, const gchar *ident); void gs_shell_show_uri (GsShell *shell, const gchar *url); +gboolean gs_shell_is_running (GsShell *self); void gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *cancellable); -- GitLab From e97da04e76a3abe5e56b93f338aaa04c755b58ea Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sat, 23 Nov 2024 23:48:16 +0000 Subject: [PATCH 2/3] gs-details-page: Query job manager lazily MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the app isn’t going to change, there’s no need to get the job manager. In particular, this helps when `self->app == app == NULL`, which happens when shutting down early (`gnome-software --quit` when gnome-software isn’t already running). In that situation, the job manager is not set up yet, so getting it fails. Avoid that. Signed-off-by: Philip Withnall Helps: #2579 --- src/gs-details-page.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gs-details-page.c b/src/gs-details-page.c index eabffb047..63a21c8a0 100644 --- a/src/gs-details-page.c +++ b/src/gs-details-page.c @@ -1857,11 +1857,13 @@ gs_details_page_app_refine_cb (GObject *source, static void _set_app (GsDetailsPage *self, GsApp *app) { - GsJobManager *job_manager = gs_plugin_loader_get_job_manager (self->plugin_loader); + GsJobManager *job_manager; if (self->app == app) return; + job_manager = gs_plugin_loader_get_job_manager (self->plugin_loader); + /* do not show all the reviews by default */ self->show_all_reviews = FALSE; -- GitLab From 3bc419c11ce6e0879e3a11f873a411ca18d6c8cd Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 28 May 2024 17:47:49 +0200 Subject: [PATCH 3/3] gs-application: Early exit the application when --quit is provided No need to load and initialize all plugins when the application is asked to quit. This handles the case when no other gnome-software process is running. Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/2579 --- src/gs-application.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gs-application.c b/src/gs-application.c index a4b455006..7655edb0a 100644 --- a/src/gs-application.c +++ b/src/gs-application.c @@ -1290,6 +1290,13 @@ gs_application_handle_local_options (GApplication *app, GVariantDict *options) NULL); } if (g_variant_dict_contains (options, "quit")) { + GsApplication *self = GS_APPLICATION (app); + if (!g_application_get_is_remote (app) && (self->shell == NULL || !gs_shell_is_running (self->shell))) { + g_application_quit (app); + g_debug ("Early exit due to --quit option"); + /* early exit, to not continue with setup, plugin initialization and so on */ + return 0; + } /* The 'quit' command-line option shuts down everything, * including the backend service */ g_action_group_activate_action (G_ACTION_GROUP (app), -- GitLab