Skip to content

Commit

Permalink
Merge pull request #765 from mjakeman/oscfdezdz/fix-comment-dialog-cl…
Browse files Browse the repository at this point in the history
…ose-while-loading

comment-dialog: Fix crash on close while loading
  • Loading branch information
oscfdezdz authored Jan 19, 2025
2 parents 54585fc + 38e2409 commit eaeff64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions build-aux/com.mattjakeman.ExtensionManager.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
{
"type" : "git",
"url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler.git",
"commit" : "8e10fcf8692108b9d4ab78f41086c5d7773ef864",
"tag" : "v0.14.0"
"commit" : "04ef0944db56ab01307a29aaa7303df6067cb3c0",
"tag" : "v0.16.0"
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions build-aux/com.mattjakeman.ExtensionManager.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
{
"type" : "git",
"url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler.git",
"commit" : "8e10fcf8692108b9d4ab78f41086c5d7773ef864",
"tag" : "v0.14.0"
"commit" : "04ef0944db56ab01307a29aaa7303df6067cb3c0",
"tag" : "v0.16.0"
}
]
},
Expand Down Expand Up @@ -70,8 +70,8 @@
{
"type" : "git",
"url" : "https://github.com/mjakeman/extension-manager",
"commit" : "62f3759e10cfd21014c805dc75645947569d48a9",
"tag" : "v0.6.0"
"commit" : "54585fc15c3fe4939f2ba22ebc8808e6ef46c8f4",
"tag" : "v0.6.1"
}
]
}
Expand Down
42 changes: 25 additions & 17 deletions src/exm-comment-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct _ExmCommentDialog

ExmCommentProvider *comment_provider;
GCancellable *cancellable;
gboolean closed;

GtkListBox *list_box;
GtkStack *stack;
Expand Down Expand Up @@ -64,6 +63,16 @@ exm_comment_dialog_new (int web_id)
NULL);
}

static void
exm_comment_dialog_dispose (GObject *object)
{
ExmCommentDialog *self = (ExmCommentDialog *)object;

g_cancellable_cancel (self->cancellable);

G_OBJECT_CLASS (exm_comment_dialog_parent_class)->dispose (object);
}

static void
exm_comment_dialog_get_property (GObject *object,
guint prop_id,
Expand Down Expand Up @@ -105,6 +114,7 @@ exm_comment_dialog_class_init (ExmCommentDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

object_class->dispose = exm_comment_dialog_dispose;
object_class->get_property = exm_comment_dialog_get_property;
object_class->set_property = exm_comment_dialog_set_property;
object_class->constructed = exm_comment_dialog_constructed;
Expand Down Expand Up @@ -143,17 +153,25 @@ comment_factory (ExmComment *comment,
static void
on_get_comments (GObject *source,
GAsyncResult *res,
ExmCommentDialog *self)
gpointer user_data)
{
GListModel *model;
GError *error = NULL;
ExmCommentDialog *self;

if (self->closed)
return;
g_return_if_fail (user_data != NULL);

GListModel *model = exm_comment_provider_get_comments_finish (EXM_COMMENT_PROVIDER (source), res, &error);
model = exm_comment_provider_get_comments_finish (EXM_COMMENT_PROVIDER (source), res, &error);
self = (ExmCommentDialog *) user_data;

if (error && error->code != 404)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
g_clear_error (&error);
return;
}

// Filter 5xx status codes (server errors)
if (error->code / 100 == 5)
adw_status_page_set_description (self->error_status, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later"));
Expand All @@ -162,6 +180,8 @@ on_get_comments (GObject *source,

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

g_clear_error (&error);

return;
}

Expand All @@ -172,20 +192,12 @@ on_get_comments (GObject *source,
g_object_ref (self), g_object_unref);
}

static void
on_dialog_closed (ExmCommentDialog *self)
{
self->closed = TRUE;
}

static void
exm_comment_dialog_constructed (GObject *object)
{
ExmCommentDialog *self = EXM_COMMENT_DIALOG (object);

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

g_cancellable_cancel (self->cancellable);
self->cancellable = g_cancellable_new ();

exm_comment_provider_get_comments_async (self->comment_provider,
Expand All @@ -204,9 +216,5 @@ exm_comment_dialog_init (ExmCommentDialog *self)
gtk_widget_init_template (GTK_WIDGET (self));

self->comment_provider = exm_comment_provider_new ();

self->closed = FALSE;

g_signal_connect (self, "closed", G_CALLBACK (on_dialog_closed), NULL);
}

0 comments on commit eaeff64

Please sign in to comment.