From 975d24cfeb043a418857faaf9c1d3f64d0ef6919 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Mon, 18 Apr 2016 02:27:39 -0500 Subject: [PATCH] added theme heartbeat that will hopefully allow us to detect when script execution is broken in the web process so we can fallback to the simple theme (so the user isn't stuck on a broken login screen) --- data/lightdm-webkit2-greeter.conf | 2 +- src/lightdm-webkit2-greeter-ext.c | 1 - src/lightdm-webkit2-greeter.c | 66 ++++++++++++++++++++++++++++--- themes/antergos/js/greeter.js | 12 ++++++ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/data/lightdm-webkit2-greeter.conf b/data/lightdm-webkit2-greeter.conf index a1c1f0c..133f7ce 100644 --- a/data/lightdm-webkit2-greeter.conf +++ b/data/lightdm-webkit2-greeter.conf @@ -2,7 +2,7 @@ # [greeter] # webkit-theme = Webkit theme to use. (Default: antergos) # debug_mode = Greeter theme debug mode. (Default: false) -# screensaver-timeout = Blank the screen after this many seconds of inactivity. +# screensaver-timeout = Blank the screen after this many seconds of inactivity. (Default: 300) # [greeter] diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 3ad111c..c3aa6bc 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -60,7 +60,6 @@ GKeyFile *keyfile; /* * Put all our translatable strings up top */ - #define EXPECTSTRING _("Expected a string") #define ARGNOTSUPPLIED _("Argument(s) not supplied") diff --git a/src/lightdm-webkit2-greeter.c b/src/lightdm-webkit2-greeter.c index c18c7d2..c69de0a 100644 --- a/src/lightdm-webkit2-greeter.c +++ b/src/lightdm-webkit2-greeter.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -56,9 +57,10 @@ static GdkDisplay *default_display; /* Screensaver values */ static int timeout, interval, prefer_blanking, allow_exposures; + static gint config_timeout; -static gboolean debug_mode; +static gboolean debug_mode, heartbeat; static GdkFilterReturn wm_window_filter(GdkXEvent *gxevent, GdkEvent *event, gpointer data) { @@ -105,6 +107,7 @@ create_new_webkit_settings_object(void) { "javascript-can-open-windows-automatically", TRUE, "allow-file-access-from-file-urls", TRUE, "enable-write-console-messages-to-stdout", TRUE, + "allow-universal-access-from-file-urls", TRUE, NULL ); } @@ -125,6 +128,45 @@ context_menu_cb(WebKitWebView *view, } +/** + * Callback for Theme Heartbeat. Themes start the heartbeat by sending a post message + * via JavaScript. Once started, the heartbeat will schedule a check to ensure that the + * theme has sent a subsequent heartbeat message. If heartbeat message was not received, + * we assume that there has been an error in the web process and fallback to the simple theme. + */ +static void +theme_heartbeat_cb(void) { + if (! heartbeat) { + /* Setup g_timeout callback for theme heartbeat check */ + g_timeout_add_seconds(G_PRIORITY_DEFAULT, 8, (GSourceFunc) check_theme_heartbeat_cb, NULL); + heartbeat = TRUE; + } +} + + +static gboolean +check_theme_heartbeat_cb(void) { + if (! heartbeat) { + /* Theme heartbeat not received. We assume that an error has occured + * which broke script execution. We will fallback to the simple theme + * so the user won't be stuck with a broken login screen. + */ + g_print('%s%s', + '[ERROR] :: A problem was detected with the current theme. ', + 'Falling back to simple theme...' + ); + webkit_web_view_load_uri( + WEBKIT_WEB_VIEW(web_view), + g_strdup_printf("file://%s/simple/index.html", THEME_DIR) + ); + } + + heartbeat = FALSE; + + return heartbeat; +} + + /** * Lock Hint enabled handler. * @@ -156,11 +198,23 @@ message_received_cb(WebKitUserContentManager *manager, WebKitJavascriptResult *message, gpointer user_data) { - /* TODO: - * Abstract this by using JSON for exchanging messages so the handler can - * be used for more than one task/event. - */ - lock_hint_enabled_handler(); + gchar *message_str, *lock_hint_str, *heartbeat_str; + + message_str = get_js_result_as_string(message); + lock_hint_str = "LockHint"; + heartbeat_str = "Heartbeat"; + + switch(message_str) { + case lock_hint_str : + lock_hint_enabled_handler(); + break; + + case heartbeat_str : + theme_heartbeat_cb(); + break; + } + + g_free(message_str); g_free(lock_hint_str); g_free(heartbeat_str); } diff --git a/themes/antergos/js/greeter.js b/themes/antergos/js/greeter.js index b0003dc..006bcb7 100644 --- a/themes/antergos/js/greeter.js +++ b/themes/antergos/js/greeter.js @@ -60,12 +60,15 @@ class AntergosThemeUtils { } _util = this; + this.initialize_theme_heartbeat(); + this.debug = false; this.lang = window.navigator.language.split( '-' )[ 0 ].toLowerCase(); this.translations = window.ant_translations; this.$log_container = $('#logArea'); this.recursion = 0; this.cache_backend = ''; + this.heartbeat = ''; if ( 'undefined' === typeof window.navigator.languages ) { window.navigator.languages = [ window.navigator.language ]; @@ -78,6 +81,14 @@ class AntergosThemeUtils { } + initialize_theme_heartbeat() { + this.log('Initializing theme heartbeat.'); + this.heartbeat = setInterval(() => { + window.webkit.messageHandlers.GreeterBridge.postMessage('Heartbeat'); + }, 5000); + } + + setup_cache_backend() { // Do we have access to localStorage? try { @@ -101,6 +112,7 @@ class AntergosThemeUtils { if ('' === this.cache_backend) { this.cache_backend = 'Cookies'; } + console.log(`this.cache_backend is: ${this.cache_backend}`); }