Browse Source

first part of the fix for #91

sisyphus
Dustin Falgout 8 years ago
parent
commit
3be24ee76d
  1. 35
      src/greeter.c
  2. 25
      src/gresource/js/Greeter.js
  3. 38
      src/gresource/js/GreeterConfig.js
  4. 3
      src/gresource/js/ThemeHeartbeat.js
  5. 39
      src/gresource/js/ThemeUtils.js

35
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);

25
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 );

38
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;

3
src/gresource/js/ThemeHeartbeat.js

@ -80,6 +80,3 @@ class ThemeHeartbeat {
window.webkit.messageHandlers.GreeterBridge.postMessage('Heartbeat');
}
}
new ThemeHeartbeat();

39
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;
} );

Loading…
Cancel
Save