Skip to content

Commit

Permalink
upgrade-assistant: Improve network error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
oscfdezdz committed Oct 25, 2024
1 parent f2efbd3 commit e6257f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/exm-upgrade-assistant.blp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ template $ExmUpgradeAssistant: Adw.Dialog {
};
}

Gtk.StackPage error {
name: "error";

child: Adw.StatusPage error_status {
icon-name: "offline-symbolic";
title: _("Connection Error");
};
}

Gtk.StackPage results {
name: "results";

Expand Down
44 changes: 26 additions & 18 deletions src/exm-upgrade-assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ struct _ExmUpgradeAssistant
// Waiting Page
GtkLabel *counter;

// Error Page
AdwStatusPage *error_status;

// Results Page
GtkListBox *user_list_box;
GtkListBox *system_list_box;
Expand All @@ -84,14 +87,6 @@ exm_upgrade_assistant_new (ExmManager *manager)
NULL);
}

static void
exm_upgrade_assistant_finalize (GObject *object)
{
ExmUpgradeAssistant *self = (ExmUpgradeAssistant *)object;

G_OBJECT_CLASS (exm_upgrade_assistant_parent_class)->finalize (object);
}

static void
exm_upgrade_assistant_get_property (GObject *object,
guint prop_id,
Expand Down Expand Up @@ -250,7 +245,7 @@ print_list_model (GListModel *model,
num_extensions = g_list_model_get_n_items (model);
for (i = 0; i < num_extensions; i++) {
ExmUpgradeResult *result;
const gchar *name, *creator, *uuid, *url, *supported_text;
const gchar *name, *creator, *uuid, *supported_text;
SupportStatus supported;

result = g_list_model_get_item (model, i);
Expand Down Expand Up @@ -344,15 +339,13 @@ display_extension_result (ExmUpgradeAssistant *self,
ExmUpgradeResult *result,
gboolean is_user)
{
if (get_support_status (result, self->target_shell_version) == STATUS_SUPPORTED) {
if (get_support_status (result, self->target_shell_version) == STATUS_SUPPORTED)
self->number_supported++;
}

g_list_store_append (is_user ? self->user_results_store : self->system_results_store, result);

if (self->waiting_on_tasks && self->number_checked == self->total_extensions) {
if (self->waiting_on_tasks && self->number_checked == self->total_extensions)
display_results (self);
}
}

static void
Expand All @@ -362,25 +355,40 @@ on_extension_processed (GObject *source,
{
ExmSearchResult *web_info;
GError *error = NULL;
ExmUpgradeAssistant *self;
ExtensionCheckData *data;
ExmUpgradeAssistant *self;
ExmUpgradeResult *result;

g_return_if_fail (user_data != NULL);

web_info = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), async_result, &error);
data = (ExtensionCheckData *) user_data;
self = EXM_UPGRADE_ASSISTANT (data->assistant);

if (error)
{
// 4xx and 5xx status codes return error codes greater than zero.
if (error->code)
adw_status_page_set_description (self->error_status, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure</a> status and try again"));
else
adw_status_page_set_description (self->error_status, _("Check your network status and try again"));

gtk_stack_set_visible_child_name (self->stack, "error");

g_clear_error (&error);
free_check_data (data);

return;
}

self->number_checked++;
update_checked_count (self);

result = exm_upgrade_result_new ();
exm_upgrade_result_set_local_data (result, data->local_data);

if ((web_info = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), async_result, &error)) != FALSE)
{
if (EXM_IS_SEARCH_RESULT (web_info))
exm_upgrade_result_set_web_data (result, web_info);
}

display_extension_result (self, result, data->is_user);
free_check_data (data);
Expand Down Expand Up @@ -612,7 +620,6 @@ exm_upgrade_assistant_class_init (ExmUpgradeAssistantClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

object_class->finalize = exm_upgrade_assistant_finalize;
object_class->get_property = exm_upgrade_assistant_get_property;
object_class->set_property = exm_upgrade_assistant_set_property;

Expand All @@ -635,6 +642,7 @@ exm_upgrade_assistant_class_init (ExmUpgradeAssistantClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, description);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, stack);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, counter);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, error_status);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, progress_bar);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, summary);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, copy_details);
Expand Down

0 comments on commit e6257f8

Please sign in to comment.