From 3be24ee76d37b4593132d2274acbea71bf88ff62 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Thu, 1 Dec 2016 00:31:28 -0600 Subject: [PATCH] first part of the fix for #91 --- src/greeter.c | 35 +++++++++++++++++++++++++-- src/gresource/js/Greeter.js | 25 ++++++++++++++++++- src/gresource/js/GreeterConfig.js | 38 ++++++++++++++++++++++++----- src/gresource/js/ThemeHeartbeat.js | 3 --- src/gresource/js/ThemeUtils.js | 39 +++++++++++++++++++++++++----- 5 files changed, 122 insertions(+), 18 deletions(-) diff --git a/src/greeter.c b/src/greeter.c index fcad649..46236bb 100644 --- a/src/greeter.c +++ b/src/greeter.c @@ -58,6 +58,7 @@ static GtkWidget *window; static WebKitSettings *webkit_settings; static GdkDisplay *default_display; static GResource *greeter_resources; +static WebKitUserContentManager *manager; /* Screensaver values */ static int @@ -207,7 +208,7 @@ load_script(char *script) { static void greeter_loaded_handler(void) { - load_script(GRESOURCE_PATH "/js/bundle.js"); + //load_script(GRESOURCE_PATH "/js/bundle.js"); } @@ -287,6 +288,35 @@ rtrim_comments(gchar *str) { } +static void +javascript_bundle_injection_setup() { + WebKitUserScript *bundle; + GBytes *data; + guint8 *data_as_guint; + gchar *script; + + data = g_resource_lookup_data( + greeter_resources, + GRESOURCE_PATH "/js/bundle.js", + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL + ); + + data_as_guint = g_byte_array_free(g_bytes_unref_to_array(data), FALSE); + script = g_strdup_printf("%s", data_as_guint); + + bundle = webkit_user_script_new( + script, + WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, + WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, + NULL, /* URL whitelist pattern */ + NULL /* URL blacklist pattern */ + ); + + webkit_user_content_manager_add_script(WEBKIT_USER_CONTENT_MANAGER(manager), bundle); +} + + int main(int argc, char **argv) { GdkScreen *screen; @@ -296,7 +326,6 @@ main(int argc, char **argv) { gchar *theme; GError *err = NULL; GdkRGBA bg_color; - WebKitUserContentManager *manager; WebKitWebContext *context; GtkCssProvider *css_provider; WebKitCookieManager *cookie_manager; @@ -421,6 +450,8 @@ main(int argc, char **argv) { g_signal_connect(manager, "script-message-received::GreeterBridge", G_CALLBACK(message_received_cb), NULL); webkit_user_content_manager_register_script_message_handler(manager, "GreeterBridge"); + javascript_bundle_injection_setup(); + /* Create the web_view */ web_view = webkit_web_view_new_with_user_content_manager(manager); diff --git a/src/gresource/js/Greeter.js b/src/gresource/js/Greeter.js index 40948f4..783e5f0 100644 --- a/src/gresource/js/Greeter.js +++ b/src/gresource/js/Greeter.js @@ -297,10 +297,33 @@ class Greeter { } +const __lightdm = new Promise( (resolve, reject) => { + let waiting = 0; + + const check_window_prop = () => { + if ( waiting > 15000 ) { + return reject( 'Timeout Reached!'); + } + + setTimeout( () => { + waiting += 1; + + if ( '__LightDMGreeter' in window ) { + return resolve( window.__LightDMGreeter ); + } + + check_window_prop(); + }, 1 ); + }; + + check_window_prop(); +}); + + /** * @memberOf window * @type {LightDM.Greeter} */ -window.lightdm = __LightDMGreeter; +__lightdm.then( result => window.lightdm = result ); diff --git a/src/gresource/js/GreeterConfig.js b/src/gresource/js/GreeterConfig.js index 8763864..3d466e5 100644 --- a/src/gresource/js/GreeterConfig.js +++ b/src/gresource/js/GreeterConfig.js @@ -151,16 +151,42 @@ class GreeterConfig { } } +const __greeter_config = new Promise( (resolve, reject) => { + let waiting = 0; + + const check_window_prop = () => { + if ( waiting > 15000 ) { + return reject( 'Timeout Reached!'); + } + + setTimeout( () => { + waiting += 1; + + if ( '__GreeterConfig' in window ) { + return resolve( (() => new GreeterConfig())() ); + } + + check_window_prop(); + }, 1 ); + }; + + check_window_prop(); +}); + /** * @memberOf window * @type {LightDM.GreeterConfig} */ -window.greeter_config = new GreeterConfig(); +__greeter_config.then( result => { + window.greeter_config = result; + + /** + * @deprecated + * @type {LightDM.GreeterConfig} + */ + window.config = window.greeter_config; +} ); + -/** - * @deprecated - * @type {LightDM.GreeterConfig} - */ -window.config = window.greeter_config; diff --git a/src/gresource/js/ThemeHeartbeat.js b/src/gresource/js/ThemeHeartbeat.js index 29c393b..1939fe4 100644 --- a/src/gresource/js/ThemeHeartbeat.js +++ b/src/gresource/js/ThemeHeartbeat.js @@ -80,6 +80,3 @@ class ThemeHeartbeat { window.webkit.messageHandlers.GreeterBridge.postMessage('Heartbeat'); } } - - -new ThemeHeartbeat(); diff --git a/src/gresource/js/ThemeUtils.js b/src/gresource/js/ThemeUtils.js index b86baa2..5594974 100644 --- a/src/gresource/js/ThemeUtils.js +++ b/src/gresource/js/ThemeUtils.js @@ -197,14 +197,41 @@ class ThemeUtils { } +const __theme_utils = new Promise( (resolve, reject) => { + let waiting = 0; + + const check_window_prop = () => { + if ( waiting > 15000 ) { + return reject( 'Timeout Reached!'); + } + + setTimeout( () => { + waiting += 1; + + if ( '__ThemeUtils' in window ) { + return resolve( (() => new ThemeUtils())() ); + } + + check_window_prop(); + }, 1 ); + }; + + check_window_prop(); +}); + + /** * @memberOf window * @type {LightDM.ThemeUtils} */ -window.theme_utils = new ThemeUtils(); +__theme_utils.then( result => { + window.theme_utils = result; -/** - * @deprecated - * @type {LightDM.ThemeUtils} - */ -window.greeterutil = window.theme_utils; + new ThemeHeartbeat(); + + /** + * @deprecated + * @type {LightDM.ThemeUtils} + */ + window.greeterutil = window.theme_utils; +} );