Browse Source

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)

sisyphus
Dustin Falgout 9 years ago
parent
commit
975d24cfeb
  1. 2
      data/lightdm-webkit2-greeter.conf
  2. 1
      src/lightdm-webkit2-greeter-ext.c
  3. 66
      src/lightdm-webkit2-greeter.c
  4. 12
      themes/antergos/js/greeter.js

2
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]

1
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")

66
src/lightdm-webkit2-greeter.c

@ -36,6 +36,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <glib-unix.h>
#include <gtk/gtkx.h>
#include <webkit2/webkit2.h>
@ -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);
}

12
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}`);
}

Loading…
Cancel
Save