commit: f09c15a89e7c20d23d658d26eec707a064895ee8
parent: b0f2245f36918199503a1c5493abb7de19c8532e
author: Chris Noxz <chris@noxz.tech>
date: Tue, 4 Apr 2023 16:58:34 +0200
fix for error when canceling finished download
Due to recent changes in webkit_download_cancel, cancellation of finished
downloads result in a segmentation fault in webkit_download_cancel. To mitigate
this, a quick fix for tracking the condition of downloads have been implemented
to determine if a download is finished or not.
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/browser.c b/browser.c
@@ -821,6 +821,7 @@ prepare_download(WebKitDownload *d,
*u = NULL; /* uri */
GtkWidget *b; /* button */
int i;
+ static gboolean c = FALSE; /* condition, TRUE=finished */
/* make suggested filename safe, by replacing directory separators */
for (i = 0; s[i]; i++)
@@ -851,6 +852,8 @@ prepare_download(WebKitDownload *d,
gtk_box_reorder_child(GTK_BOX(mw.dbx), b, 0);
gtk_widget_show_all(mw.dbx);
+ g_object_set_data(G_OBJECT(b), __NAME__"-finished", (gpointer)&c);
+
CB(d, "notify::estimated-progress", cb_download_changed_progress, b);
CB(d, "finished", cb_download_finished, b);
g_object_ref(d);
diff --git a/browser.h b/browser.h
@@ -296,7 +296,8 @@ void
cb_download_cancel(GtkWidget *btn,
gpointer data)
{
- webkit_download_cancel(WEBKIT_DOWNLOAD(data));
+ if (!(*((gboolean*)g_object_get_data(G_OBJECT(btn), __NAME__"-finished"))))
+ webkit_download_cancel(WEBKIT_DOWNLOAD(data));
g_object_unref(WEBKIT_DOWNLOAD(data));
gtk_widget_destroy(btn);
}
@@ -318,6 +319,8 @@ cb_download_finished(GObject *obj,
if (!GTK_IS_BUTTON(data))
return;
+ (*((gboolean*)g_object_get_data(data, __NAME__"-finished"))) = TRUE;
+
update_download_button(WEBKIT_DOWNLOAD(obj), GTK_BUTTON(data), TRUE);
gtk_button_set_image(
GTK_BUTTON(data),