From c072f198bc5c1af3aac48754b72da085306d0fac Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 16 May 2022 13:40:57 +0000 Subject: [PATCH 1/3] Add auto retry on interval --- core/cog-webkit-utils.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/cog-webkit-utils.c b/core/cog-webkit-utils.c index 8b7137d8..bd26ffed 100644 --- a/core/cog-webkit-utils.c +++ b/core/cog-webkit-utils.c @@ -19,11 +19,13 @@ static const char error_message_template[] = " margin-left: 0.75em; margin-top: 0 }\n" ".try-again { text-align: center; font-size: 1em; \n" " height: 100%; margin: 1em; }\n" - "\n" + "\n" + "\n" "

%s

\n" "

%s

\n" "

%s

\n" - "" + "" ""; gboolean @@ -34,7 +36,7 @@ load_error_page (WebKitWebView *web_view, { g_warning ("<%s> %s: %s", failing_uri, title, message); - g_autofree char *html = g_strdup_printf(error_message_template, title, title, failing_uri, message, failing_uri); + g_autofree char *html = g_strdup_printf(error_message_template, title, failing_uri, title, failing_uri, message); webkit_web_view_load_alternate_html (web_view, html, failing_uri, From a0aa65394f3806f6b7785583921f1e211f9af3a8 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 16 May 2022 13:58:52 +0000 Subject: [PATCH 2/3] Apply code style --- core/cog-webkit-utils.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/core/cog-webkit-utils.c b/core/cog-webkit-utils.c index bd26ffed..88e56b41 100644 --- a/core/cog-webkit-utils.c +++ b/core/cog-webkit-utils.c @@ -9,24 +9,23 @@ #include #include -static const char error_message_template[] = - "%s\n" - "\n" - "

%s

\n" - "

%s

\n" - "

%s

\n" - "" - ""; +static const char error_message_template[] = "%s\n" + "\n" + "

%s

\n" + "

%s

\n" + "

%s

\n" + "" + ""; gboolean load_error_page (WebKitWebView *web_view, From 13e73d0a8cbc95a06f70bd0b5344d2f6c02bd936 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Tue, 31 May 2022 13:29:31 +0000 Subject: [PATCH 3/3] Add config to enable auto retry on page load failure --- core/cog-webkit-utils.c | 18 +++++++++++------- core/cog-webkit-utils.h | 2 ++ launcher/cog-launcher.c | 6 +++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/cog-webkit-utils.c b/core/cog-webkit-utils.c index 88e56b41..b24794f1 100644 --- a/core/cog-webkit-utils.c +++ b/core/cog-webkit-utils.c @@ -9,6 +9,8 @@ #include #include +static bool autoRetry = false; + static const char error_message_template[] = "%s\n" "\n" + "if (%s) setTimeout(retry, 5000);\n\n" "

%s

\n" "

%s

\n" "

%s

\n" "" ""; +void +cog_set_auto_retry_on_failure(bool value) { + autoRetry = value; +} + gboolean -load_error_page (WebKitWebView *web_view, - const char *failing_uri, - const char *title, - const char *message) +load_error_page(WebKitWebView *web_view, const char *failing_uri, const char *title, const char *message) { g_warning ("<%s> %s: %s", failing_uri, title, message); - - g_autofree char *html = g_strdup_printf(error_message_template, title, failing_uri, title, failing_uri, message); + + g_autofree char *html = g_strdup_printf(error_message_template, title, autoRetry ? "true" : "false", failing_uri, title, failing_uri, message); webkit_web_view_load_alternate_html (web_view, html, failing_uri, diff --git a/core/cog-webkit-utils.h b/core/cog-webkit-utils.h index 825eed6e..2968733b 100644 --- a/core/cog-webkit-utils.h +++ b/core/cog-webkit-utils.h @@ -19,6 +19,8 @@ G_BEGIN_DECLS +void cog_set_auto_retry_on_failure(bool value); + gboolean cog_handle_web_view_load_failed (WebKitWebView *web_view, WebKitLoadEvent load_event, char *failing_uri, diff --git a/launcher/cog-launcher.c b/launcher/cog-launcher.c index 8e4499b7..d44ec45f 100644 --- a/launcher/cog-launcher.c +++ b/launcher/cog-launcher.c @@ -53,6 +53,7 @@ static struct { gboolean ignore_tls_errors; gboolean enable_sandbox; gboolean automation; + gboolean auto_retry_on_failure; } s_options = { .scale_factor = 1.0, .device_scale_factor = 1.0, @@ -324,6 +325,7 @@ cog_launcher_create_view(CogLauncher *self, CogShell *shell) cog_web_view_connect_default_progress_handlers(web_view); cog_web_view_connect_default_error_handlers(web_view); + cog_set_auto_retry_on_failure(s_options.auto_retry_on_failure); webkit_web_view_load_uri(web_view, s_options.home_uri); g_clear_pointer(&s_options.home_uri, g_free); @@ -1014,7 +1016,9 @@ static GOptionEntry s_cli_options[] = { {"automation", '\0', 0, G_OPTION_ARG_NONE, &s_options.automation, "Enable automation mode (default: disabled).", NULL}, {G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &s_options.arguments, "", "[URL]"}, - {NULL}}; + {NULL}, + {"auto-retry-on-failure", '\0', 0, G_OPTION_ARG_NONE, &s_options.auto_retry_on_failure, + "Automatically retry page load on failure with 5 second interval.", NULL}}; static void cog_launcher_constructed(GObject *object)