Commit e069537a authored by Vanadiae's avatar Vanadiae
Browse files

gui: Check for dependencies updates when opening project

In line with the previous commits, now plug the dependency updaters to
the UI.
parent 35958dd7
Pipeline #259563 passed with stage
in 57 minutes and 5 seconds
......@@ -118,6 +118,7 @@ ide_primary_workspace_actions_update_dependencies (GSimpleAction *action,
IdePrimaryWorkspace *self = user_data;
g_autoptr(PeasExtensionSet) set = NULL;
g_autoptr(IdeNotification) notif = NULL;
IdeNotifications *notifs = NULL;
g_autoptr(IdeTask) task = NULL;
UpdateDependencies *state;
IdeContext *context;
......@@ -136,6 +137,15 @@ ide_primary_workspace_actions_update_dependencies (GSimpleAction *action,
ide_notification_set_progress_is_imprecise (notif, TRUE);
ide_notification_attach (notif, IDE_OBJECT (context));
notifs = ide_context_peek_child_typed (context, IDE_TYPE_NOTIFICATIONS);
if (notifs)
{
g_autoptr(IdeNotification) update_available_notif = NULL;
if ((update_available_notif = ide_notifications_find_by_id (notifs, "deps-updates-available-notif")))
ide_notification_withdraw (update_available_notif);
}
state = g_slice_new0 (UpdateDependencies);
state->n_active = 0;
state->notif = g_object_ref (notif);
......
......@@ -966,6 +966,147 @@ ide_workbench_project_loaded_foreach_cb (PeasExtensionSet *set,
ide_workbench_addin_project_loaded (addin, self->project_info);
}
typedef struct
{
GStrvBuilder *deps_names_builder;
gint n_active;
} UpdatesCheck;
static void
updates_check_free (UpdatesCheck *uc)
{
g_strv_builder_unref (uc->deps_names_builder);
g_slice_free (UpdatesCheck, uc);
}
static void
on_dependencies_updates_checked_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)object;
g_autoptr(IdeTask) task = user_data;
g_autoptr(GError) error = NULL;
g_auto(GStrv) deps = NULL;
UpdatesCheck *uc;
IdeContext *context;
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (IDE_IS_TASK (task));
context = ide_task_get_source_object (task);
deps = ide_dependency_updater_check_for_updates_finish (updater, result, &error);
if (error)
/* TODO: I think adding the cause of the error message and type name (e.g. GbpFlatpakDependencyUpdater) useful to debug and to know what happened. Should this be used too in update_dependencies_cb() in ide-primary-workspace-actions.c (in a separate commit/MR)? */
ide_context_warning (context, "Could not check for updates with %s: %s", G_OBJECT_TYPE_NAME (updater), error->message);
ide_object_destroy (IDE_OBJECT (updater));
uc = ide_task_get_task_data (task);
uc->n_active--;
if (deps && *deps != NULL)
{
for (GStrv dep = deps; *dep != NULL; dep++)
g_strv_builder_add (uc->deps_names_builder, *dep);
}
if (uc->n_active == 0)
{
g_auto(GStrv) deps_names = g_strv_builder_end (uc->deps_names_builder);
/* FIXME: not sure if this way of presenting the list of deps will always work for all languages… Maybe there's a better way? */
g_autofree char *joined_deps_names = g_strjoinv (", ", deps_names);
if (g_strv_length (deps_names) > 0)
{
IdeNotification *notif = ide_notification_new ();
ide_notification_set_title (notif, _("Dependencies Updates Available"));
ide_notification_set_body (notif, joined_deps_names);
ide_notification_set_icon_name (notif, "software-update-available-symbolic");
ide_notification_set_urgent (notif, TRUE);
ide_notification_add_button (notif, _("Update Dependencies"), NULL, "win.update-dependencies");
/* Attribute an ID to the notification so it can be removed when clicking one of the
* Update Dependencies button (either the notification one or the build popover one), in
* the primary workspace action handler.
*/
ide_notification_set_id (notif, "deps-updates-available-notif");
ide_notification_attach (notif, IDE_OBJECT (context));
}
ide_task_return_boolean (task, TRUE);
}
}
static void
foreach_check_dependencies_updates_cb (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
PeasExtension *exten,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)exten;
UpdatesCheck *uc;
IdeContext *context;
IdeTask *task = user_data;
g_assert (PEAS_IS_EXTENSION_SET (set));
g_assert (plugin_info != NULL);
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
g_assert (IDE_IS_TASK (task));
context = ide_task_get_source_object (task);
ide_object_append (IDE_OBJECT (context), IDE_OBJECT (updater));
uc = ide_task_get_task_data (task);
uc->n_active++;
ide_dependency_updater_check_for_updates_async (updater,
NULL,
on_dependencies_updates_checked_cb,
g_object_ref (task));
}
static void
ide_primary_workspace_actions_check_dependencies_updates (IdeContext *context)
{
g_autoptr(PeasExtensionSet) set = NULL;
g_autoptr(IdeTask) task = NULL;
UpdatesCheck *uc;
GNetworkMonitor *net_monitor;
g_assert (IDE_IS_MAIN_THREAD ());
net_monitor = g_network_monitor_get_default ();
if (g_network_monitor_get_network_metered (net_monitor))
{
g_autoptr(GSettings) settings = g_settings_new ("org.gnome.builder.build");
if (!g_settings_get_boolean (settings, "allow-network-when-metered"))
return;
}
uc = g_slice_new0 (UpdatesCheck);
uc->n_active = 0;
uc->deps_names_builder = g_strv_builder_new ();
task = ide_task_new (context, NULL, NULL, NULL);
ide_task_set_source_tag (task, ide_primary_workspace_actions_check_dependencies_updates);
ide_task_set_task_data (task, uc, updates_check_free);
set = peas_extension_set_new (peas_engine_get_default (),
IDE_TYPE_DEPENDENCY_UPDATER,
NULL);
peas_extension_set_foreach (set,
foreach_check_dependencies_updates_cb,
task);
if (uc->n_active == 0)
ide_task_return_boolean (task, TRUE);
}
static void
ide_workbench_session_restore_cb (GObject *object,
GAsyncResult *result,
......@@ -1050,6 +1191,8 @@ ide_workbench_load_project_completed (IdeWorkbench *self,
build_manager = ide_build_manager_from_context (self->context);
_ide_build_manager_start (build_manager);
ide_primary_workspace_actions_check_dependencies_updates (self->context);
ide_task_return_boolean (task, TRUE);
}
......
......@@ -157,7 +157,7 @@ on_update_available_cb (GbpUpdateManagerAppAddin *self,
self->update_notif = ide_notification_new ();
ide_notification_set_id (self->update_notif, "org.gnome.builder.update-available");
ide_notification_set_icon_name (self->update_notif, "software-update-available-symbolic");
ide_notification_set_title (self->update_notif, _("Update Available"));
ide_notification_set_title (self->update_notif, _("Builder Update Available"));
ide_notification_set_body (self->update_notif, _("An update to Builder is available. Builder can download and install it for you."));
ide_notification_set_urgent (self->update_notif, TRUE);
ide_notification_add_button (self->update_notif, _("Update"), NULL, "app.update-builder");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment