From 2d2bb515bb50514a01245680ff937aca4335e787 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Thu, 29 Sep 2016 03:44:37 -0500 Subject: [PATCH] finish moving heartbeat to greeter --- src/greeter.c | 3 +-- src/webkit2-extension.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/greeter.c b/src/greeter.c index 48df32f..af04437 100644 --- a/src/greeter.c +++ b/src/greeter.c @@ -47,7 +47,6 @@ #include #include - #include "gresource/greeter-resources.h" static GtkWidget *web_view; @@ -327,7 +326,7 @@ main(int argc, char **argv) { css_provider = gtk_css_provider_new(); g_resources_register(greeter_resources); - gtk_css_provider_load_from_resource(css_provider, "/com/antergos/lightdm-webkit2-greeter/css"); + gtk_css_provider_load_from_resource(css_provider, "/com/antergos/lightdm-webkit2-greeter/css/style.css"); gtk_style_context_add_provider_for_screen( screen, GTK_STYLE_PROVIDER(css_provider), diff --git a/src/webkit2-extension.c b/src/webkit2-extension.c index bf2b5f7..051add1 100644 --- a/src/webkit2-extension.c +++ b/src/webkit2-extension.c @@ -45,6 +45,7 @@ #include #include +#include "gresource/greeter-resources.h" G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension); @@ -73,6 +74,8 @@ static JSClassRef config_file_class, greeter_util_class; +static GResource *greeter_resources; + /* * Returns either a string or null. @@ -1445,6 +1448,33 @@ static const JSClassDefinition greeter_util_definition = { }; +static void +inject_theme_heartbeat_script(JSGlobalContextRef *jsContext) { + JSStringRef command; + GBytes *resource; + GError *err = NULL; + + greeter_resources = greeter_resources_get_resource(); + resource = g_resource_lookup_data( + greeter_resources, + "/com/antergos/lightdm-webkit2-greeter/js/heartbeat.js", + 0, + &err + ); + + if (NULL != err) { + fprintf(stderr, "Loading heartbeat.js from GResource failed: %s\n", err->message); + g_error_free(err); + } + + command = JSStringCreateWithUTF8CString(resource); + + JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); + + g_object_unref(resource) +} + + static void window_object_cleared_callback(WebKitScriptWorld *world, WebKitWebPage *web_page, @@ -1460,6 +1490,7 @@ window_object_cleared_callback(WebKitScriptWorld *world, greeter_util_object, globalObject; JSStringRef command; + JSStringRef heartbeat_command; gchar *message = "LockHint"; jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world); @@ -1510,6 +1541,12 @@ window_object_cleared_callback(WebKitScriptWorld *world, command = JSStringCreateWithUTF8CString("window.greeterutil = greeter_util;"); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); + /* Inject GreeterThemeHeartbeat class */ + inject_theme_heartbeat_class(jsContext); + + /* Start the heartbeat */ + heartbeat_command = JSStringCreateWithUTF8CString("new GreeterThemeHeartbeat();"); + JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); /* If the greeter was started as a lock-screen, send message to our UI process. */ if (lightdm_greeter_get_lock_hint(greeter)) {