diff --git a/lib/gs-app.c b/lib/gs-app.c index 29898765b7d36f4428cd8c0dbee67d2db1b36b4c..d7f8be279538bd6ced72bde4df28dcafee10c73c 100644 --- a/lib/gs-app.c +++ b/lib/gs-app.c @@ -6656,3 +6656,35 @@ gs_app_set_has_translations (GsApp *app, priv->has_translations = has_translations; gs_app_queue_notify (app, obj_props[PROP_HAS_TRANSLATIONS]); } + +/** + * gs_app_is_downloaded: + * @app: a #GsApp + * + * Returns whether the @app is downloaded for updates or not, + * considering also its dependencies. + * + * Returns: %TRUE, when the @app is downloaded, %FALSE otherwise + * + * Since: 43 + **/ +gboolean +gs_app_is_downloaded (GsApp *app) +{ + GsSizeType size_type; + guint64 size_bytes = 0; + + g_return_val_if_fail (GS_IS_APP (app), FALSE); + + if (!gs_app_has_quirk (app, GS_APP_QUIRK_IS_PROXY)) { + size_type = gs_app_get_size_download (app, &size_bytes); + if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0) + return FALSE; + } + + size_type = gs_app_get_size_download_dependencies (app, &size_bytes); + if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0) + return FALSE; + + return TRUE; +} diff --git a/lib/gs-app.h b/lib/gs-app.h index d78503c3e0f068764d9c8c8aab042b3cf7504195..a053299f2b8bd0c435bb821aa5160658915037e2 100644 --- a/lib/gs-app.h +++ b/lib/gs-app.h @@ -516,5 +516,6 @@ void gs_app_set_relations (GsApp *app, gboolean gs_app_get_has_translations (GsApp *app); void gs_app_set_has_translations (GsApp *app, gboolean has_translations); +gboolean gs_app_is_downloaded (GsApp *app); G_END_DECLS diff --git a/lib/gs-plugin-job-refresh-metadata.c b/lib/gs-plugin-job-refresh-metadata.c index a57b194bc970a8daa87db6f08cbf8dd9c3776ed6..8d0b95b5d5749304bc45bc955cfc8f15ae14d520 100644 --- a/lib/gs-plugin-job-refresh-metadata.c +++ b/lib/gs-plugin-job-refresh-metadata.c @@ -387,7 +387,6 @@ finish_op (GTask *task, GError *error) { GsPluginJobRefreshMetadata *self = g_task_get_source_object (task); - GsPluginLoader *plugin_loader = g_task_get_task_data (task); g_autoptr(GError) error_owned = g_steal_pointer (&error); g_autofree gchar *job_debug = NULL; @@ -408,10 +407,6 @@ finish_op (GTask *task, progress_cb (self); g_source_destroy (self->progress_source); - /* If any plugin emitted updates-changed, actually schedule it to be - * emitted now (even if the overall operation failed). */ - gs_plugin_loader_hint_job_finished (plugin_loader); - /* Get the results of the parallel ops. */ if (self->saved_error != NULL) { g_task_return_error (task, g_steal_pointer (&self->saved_error)); diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c index a7f86d5f22dd0417d64fd64a4319acf7b9224f9d..c0e711477f361e1550b68fd7161eea682f7ba2dd 100644 --- a/lib/gs-plugin-loader.c +++ b/lib/gs-plugin-loader.c @@ -56,6 +56,7 @@ struct _GsPluginLoader GsAppList *pending_apps; /* (nullable) (owned) */ GThreadPool *queued_ops_pool; + gint active_jobs; GSettings *settings; @@ -1759,7 +1760,7 @@ gs_plugin_loader_ask_untrusted_cb (GsPlugin *plugin, } static gboolean -gs_plugin_loader_job_actions_changed_delay_cb (gpointer user_data) +gs_plugin_loader_job_updates_changed_delay_cb (gpointer user_data) { GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (user_data); @@ -1769,25 +1770,34 @@ gs_plugin_loader_job_actions_changed_delay_cb (gpointer user_data) plugin_loader->updates_changed_id = 0; plugin_loader->updates_changed_cnt = 0; - g_object_unref (plugin_loader); return FALSE; } -static void -gs_plugin_loader_job_actions_changed_cb (GsPlugin *plugin, GsPluginLoader *plugin_loader) -{ - plugin_loader->updates_changed_cnt++; -} - static void gs_plugin_loader_updates_changed (GsPluginLoader *plugin_loader) { if (plugin_loader->updates_changed_id != 0) return; plugin_loader->updates_changed_id = - g_timeout_add_seconds (GS_PLUGIN_LOADER_UPDATES_CHANGED_DELAY, - gs_plugin_loader_job_actions_changed_delay_cb, - g_object_ref (plugin_loader)); + g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, + GS_PLUGIN_LOADER_UPDATES_CHANGED_DELAY, + gs_plugin_loader_job_updates_changed_delay_cb, + g_object_ref (plugin_loader), + g_object_unref); +} + +static void +gs_plugin_loader_job_updates_changed_cb (GsPlugin *plugin, + GsPluginLoader *plugin_loader) +{ + plugin_loader->updates_changed_cnt++; + + /* Schedule emit of updates changed when no job is active. + This helps to avoid a race condition when a plugin calls + updates-changed at the end of the job, but the job is + finished before the callback gets called in the main thread. */ + if (!g_atomic_int_get (&plugin_loader->active_jobs)) + gs_plugin_loader_updates_changed (plugin_loader); } static gboolean @@ -1848,7 +1858,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader, return; } g_signal_connect (plugin, "updates-changed", - G_CALLBACK (gs_plugin_loader_job_actions_changed_cb), + G_CALLBACK (gs_plugin_loader_job_updates_changed_cb), plugin_loader); g_signal_connect (plugin, "reload", G_CALLBACK (gs_plugin_loader_reload_cb), @@ -3675,9 +3685,6 @@ gs_plugin_loader_process_thread_cb (GTask *task, /* sort these again as the refine may have added useful metadata */ gs_plugin_loader_job_sorted_truncation_again (helper->plugin_job, list); - /* Hint that the job has finished. */ - gs_plugin_loader_hint_job_finished (plugin_loader); - #ifdef HAVE_SYSPROF if (plugin_loader->sysprof_writer != NULL) { g_autofree gchar *sysprof_name = g_strconcat ("process-thread:", gs_plugin_action_to_string (action), NULL); @@ -3848,9 +3855,6 @@ run_job_cb (GObject *source_object, } #endif /* HAVE_SYSPROF */ - /* Hint that the job has finished. */ - gs_plugin_loader_hint_job_finished (plugin_loader); - /* FIXME: This will eventually go away when * gs_plugin_loader_job_process_finish() is removed. */ job_class = GS_PLUGIN_JOB_GET_CLASS (plugin_job); @@ -3911,6 +3915,19 @@ cancellable_data_free (CancellableData *data) G_DEFINE_AUTOPTR_CLEANUP_FUNC (CancellableData, cancellable_data_free) +static void +plugin_loader_task_freed_cb (gpointer user_data, + GObject *freed_object) +{ + g_autoptr(GsPluginLoader) plugin_loader = user_data; + if (g_atomic_int_dec_and_test (&plugin_loader->active_jobs)) { + /* if the plugin used updates-changed during its job, actually schedule + * the signal emission now */ + if (plugin_loader->updates_changed_cnt > 0) + gs_plugin_loader_updates_changed (plugin_loader); + } +} + static gboolean job_process_setup_complete_cb (GCancellable *cancellable, gpointer user_data); static void job_process_cb (GTask *task); @@ -3977,6 +3994,10 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader, g_task_set_name (task, task_name); g_task_set_task_data (task, g_object_ref (plugin_job), (GDestroyNotify) g_object_unref); + g_atomic_int_inc (&plugin_loader->active_jobs); + g_object_weak_ref (G_OBJECT (task), + plugin_loader_task_freed_cb, g_object_ref (plugin_loader)); + /* Wait until the plugin has finished setting up. * * Do this using a #GCancellable. While we’re not using the #GCancellable @@ -4443,23 +4464,24 @@ gs_plugin_loader_get_category_manager (GsPluginLoader *plugin_loader) } /** - * gs_plugin_loader_hint_job_finished: - * @plugin_loader: a #GsPluginLoader - * - * Hint to the @plugin_loader that the set of changes caused by the current - * #GsPluginJob is likely to be finished. + * gs_plugin_loader_emit_updates_changed: + * @self: a #GsPluginLoader * - * The @plugin_loader may emit queued-up signals as a result. + * Emits the #GsPluginLoader:updates-changed signal in the nearest + * idle in the main thread. * - * Since: 42 - */ + * Since: 43 + **/ void -gs_plugin_loader_hint_job_finished (GsPluginLoader *plugin_loader) +gs_plugin_loader_emit_updates_changed (GsPluginLoader *self) { - g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader)); + g_return_if_fail (GS_IS_PLUGIN_LOADER (self)); - /* if the plugin used updates-changed during its job, actually schedule - * the signal emission now */ - if (plugin_loader->updates_changed_cnt > 0) - gs_plugin_loader_updates_changed (plugin_loader); + if (self->updates_changed_id != 0) + g_source_remove (self->updates_changed_id); + + self->updates_changed_id = + g_idle_add_full (G_PRIORITY_HIGH_IDLE, + gs_plugin_loader_job_updates_changed_delay_cb, + g_object_ref (self), g_object_unref); } diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h index 0d2035bfd027fb438d6b1e75a06049b205bf9941..91c5f643c633dc420007cec17cf71237bc261b81 100644 --- a/lib/gs-plugin-loader.h +++ b/lib/gs-plugin-loader.h @@ -125,7 +125,6 @@ gboolean gs_plugin_loader_app_is_compatible (GsPluginLoader *plugin_loader, void gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list); - -void gs_plugin_loader_hint_job_finished (GsPluginLoader *plugin_loader); +void gs_plugin_loader_emit_updates_changed (GsPluginLoader *self); G_END_DECLS diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c index 324ff4d3edfe9583f568791867e95b61d7f9e725..292d2bc4bce5cb9c1d0637a4c43adaea2637fbd1 100644 --- a/src/gs-update-monitor.c +++ b/src/gs-update-monitor.c @@ -109,43 +109,33 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(WithAppData, with_app_data_free); static void check_updates_kind (GsAppList *apps, gboolean *out_has_important, - gboolean *out_any_important_downloaded, gboolean *out_all_downloaded, gboolean *out_any_downloaded) { - gboolean has_important, any_important_downloaded, all_downloaded, any_downloaded; + gboolean has_important, all_downloaded, any_downloaded; guint ii, len; GsApp *app; len = gs_app_list_length (apps); has_important = FALSE; - any_important_downloaded = FALSE; all_downloaded = len > 0; any_downloaded = FALSE; for (ii = 0; ii < len && (!has_important || all_downloaded || !any_downloaded); ii++) { gboolean is_important; - guint64 size_download_bytes; app = gs_app_list_index (apps, ii); is_important = gs_app_get_update_urgency (app) == AS_URGENCY_KIND_CRITICAL; has_important = has_important || is_important; - /* took from gs-updates-section.c: _all_offline_updates_downloaded(); - the app is considered downloaded, when its download size is 0 */ - if (gs_app_get_size_download (app, &size_download_bytes) != GS_SIZE_TYPE_VALID || - size_download_bytes != 0) { - all_downloaded = FALSE; - } else { + if (gs_app_is_downloaded (app)) any_downloaded = TRUE; - if (is_important) - any_important_downloaded = TRUE; - } + else + all_downloaded = FALSE; } *out_has_important = has_important; - *out_any_important_downloaded = any_important_downloaded; *out_all_downloaded = all_downloaded; *out_any_downloaded = any_downloaded; } @@ -197,14 +187,15 @@ should_download_updates (GsUpdateMonitor *monitor) #endif } -/* The days below are discussed at https://gitlab.gnome.org/GNOME/gnome-software/-/issues/947 */ +/* The days below are discussed at https://gitlab.gnome.org/GNOME/gnome-software/-/issues/947 + and https://wiki.gnome.org/Design/Apps/Software/Updates#Tentative_Design */ static gboolean should_notify_about_pending_updates (GsUpdateMonitor *monitor, GsAppList *apps, const gchar **out_title, const gchar **out_body) { - gboolean has_important = FALSE, any_important_downloaded = FALSE, all_downloaded = FALSE, any_downloaded = FALSE; + gboolean has_important = FALSE, all_downloaded = FALSE, any_downloaded = FALSE; gboolean should_download, res = FALSE; gint64 timestamp_days; @@ -214,7 +205,7 @@ should_notify_about_pending_updates (GsUpdateMonitor *monitor, } should_download = should_download_updates (monitor); - check_updates_kind (apps, &has_important, &any_important_downloaded, &all_downloaded, &any_downloaded); + check_updates_kind (apps, &has_important, &all_downloaded, &any_downloaded); if (!gs_app_list_length (apps)) { /* Notify only when the download is disabled and it's the 4th day or it's more than 7 days */ @@ -225,7 +216,7 @@ should_notify_about_pending_updates (GsUpdateMonitor *monitor, } } else if (has_important) { if (timestamp_days >= 1) { - if (any_important_downloaded) { + if (all_downloaded) { *out_title = _("Critical Software Update Ready to Install"); *out_body = _("An important software update is ready to be installed."); res = TRUE; @@ -235,24 +226,23 @@ should_notify_about_pending_updates (GsUpdateMonitor *monitor, res = TRUE; } } - /* When automatic updates are on and there are things ready to be installed, then rather claim - * about things to be installed, than things to be downloaded. */ - } else if (all_downloaded || (any_downloaded && should_download)) { + } else if (all_downloaded) { if (timestamp_days >= 3) { *out_title = _("Software Updates Ready to Install"); *out_body = _("Software updates are waiting and ready to be installed."); res = TRUE; } - /* To not hide downloaded updates for 14 days when new updates were discovered meanwhile */ - } else if (timestamp_days >= (any_downloaded ? 3 : 14)) { + /* To not hide downloaded updates for 14 days when new updates were discovered meanwhile. + Never show "Available to Download" when it's supposed to download the updates. */ + } else if (!should_download && timestamp_days >= 14) { *out_title = _("Software Updates Available to Download"); *out_body = _("Please download waiting software updates."); res = TRUE; } - g_debug ("%s: last_test_days:%" G_GINT64_FORMAT " n-apps:%u should_download:%d has_important:%d any_important_downloaded:%d " + g_debug ("%s: last_test_days:%" G_GINT64_FORMAT " n-apps:%u should_download:%d has_important:%d " "all_downloaded:%d any_downloaded:%d res:%d%s%s%s%s", G_STRFUNC, - timestamp_days, gs_app_list_length (apps), should_download, has_important, any_important_downloaded, + timestamp_days, gs_app_list_length (apps), should_download, has_important, all_downloaded, any_downloaded, res, res ? " reason:" : "", res ? *out_title : "", @@ -292,6 +282,10 @@ notify_about_pending_updates (GsUpdateMonitor *monitor, return; } + /* To force reload of the Updates page, thus it reflects what + the update-monitor notifies about */ + gs_plugin_loader_emit_updates_changed (monitor->plugin_loader); + monitor->last_notification_time_usec = g_get_real_time (); g_debug ("Notify about update: '%s'", title); diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c index ca39e6fab8ae88ef5d62c4a8561fc440ce1766bd..69e083984f86034e8638b2b74ced108f7c1c3f5d 100644 --- a/src/gs-updates-section.c +++ b/src/gs-updates-section.c @@ -288,15 +288,7 @@ _all_offline_updates_downloaded (GsUpdatesSection *self) /* use the download size to figure out what is downloaded and what not */ for (guint i = 0; i < gs_app_list_length (self->list); i++) { GsApp *app = gs_app_list_index (self->list, i); - GsSizeType size_type; - guint64 size_bytes; - - size_type = gs_app_get_size_download (app, &size_bytes); - if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0) - return FALSE; - - size_type = gs_app_get_size_download_dependencies (app, &size_bytes); - if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0) + if (!gs_app_is_downloaded (app)) return FALSE; }