Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto retry on interval #439

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions core/cog-webkit-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@
#include <stdlib.h>
#include <string.h>

static const char error_message_template[] =
"<!DOCTYPE html><html><head><title>%s</title><style type='text/css'>\n"
"html { background: #fffafa; color: #0f0f0f; }\n"
"h3 { font-weight: 600; color: #fffafa; background: #555;\n"
" border-radius: 3px; padding: 0.15em 0.5em; margin-bottom: 0.25em }\n"
"p { margin-left: 0.5em; margin-right: 0.5em }\n"
"p.uri { size: 70%%; font-family: monospace; color: #888;\n"
" margin-left: 0.75em; margin-top: 0 }\n"
".try-again { text-align: center; font-size: 1em; \n"
" height: 100%; margin: 1em; }\n"
"</style></head><body>\n"
" <h3>%s</h3>\n"
" <p class='uri'>%s</p>\n"
" <p>%s</p>\n"
"<button onclick=\"window.location.href = '%s'\" class=\"try-again\">Try again</button>"
"</body></html>";
static bool autoRetry = false;

static const char error_message_template[] = "<!DOCTYPE html><html><head><title>%s</title><style type='text/css'>\n"
"html { background: #fffafa; color: #0f0f0f; }\n"
"h3 { font-weight: 600; color: #fffafa; background: #555;\n"
" border-radius: 3px; padding: 0.15em 0.5em; margin-bottom: 0.25em }\n"
"p { margin-left: 0.5em; margin-right: 0.5em }\n"
"p.uri { size: 70%%; font-family: monospace; color: #888;\n"
" margin-left: 0.75em; margin-top: 0 }\n"
".try-again { text-align: center; font-size: 1em; \n"
" height: 100%; margin: 1em; }\n"
"</style>\n"
"<script>\nfunction retry() { window.location.href = '%s' }\n"
"if (%s) setTimeout(retry, 5000);\n</script></head><body>\n"
" <h3>%s</h3>\n"
" <p class='uri'>%s</p>\n"
" <p>%s</p>\n"
"<button onclick=\"retry()\" class=\"try-again\">Try again</button>"
"</body></html>";

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, title, failing_uri, message, failing_uri);
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,
Expand Down
2 changes: 2 additions & 0 deletions core/cog-webkit-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion launcher/cog-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down