Commit 5f84aec7 authored by Amos Wenger's avatar Amos Wenger

Implement navigate + open inspector on Linux

parent a94e2f24
Pipeline #14969 failed with stages
in 3 minutes and 5 seconds
......@@ -77,5 +77,6 @@ fn start() {
});
win.title("itch lite");
win.navigate("http://itch-lite/index.html");
// win.navigate("http://itch-lite/index.html");
win.load(include_str!("./resources/index.html"));
}
{
"C_Cpp.default.includePath": [
"/usr/include/gtk-3.0",
"/usr/include/pango-1.0",
"/usr/include/glib-2.0",
"/usr/lib/glib-2.0/include",
"/usr/lib/libffi-3.2.1/include",
"/usr/include/harfbuzz",
"/usr/include/fribidi",
"/usr/include/freetype2",
"/usr/include/libpng16",
"/usr/include/uuid",
"/usr/include/cairo",
"/usr/include/pixman-1",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/libmount",
"/usr/include/blkid",
"/usr/include/gio-unix-2.0",
"/usr/include/atk-1.0",
"/usr/include/at-spi2-atk/2.0",
"/usr/include/at-spi-2.0",
"/usr/include/dbus-1.0",
"/usr/lib/dbus-1.0/include",
"/usr/include/webkitgtk-4.0",
"/usr/include/libsoup-2.4",
"/usr/include/libxml2"
]
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
// ===============
struct _tether {
tether_options opts;
GtkWindow *window;
WebKitWebView *webview;
void *data;
......@@ -39,6 +40,25 @@ static void message_received(WebKitUserContentManager *manager, WebKitJavascript
g_free(message);
}
static void webview_loaded(WebKitWebView *webview, WebKitLoadEvent load_event, void *data) {
switch (load_event) {
case WEBKIT_LOAD_COMMITTED: {
// good enough to show inspector!
WebKitWebInspector *inspector = webkit_web_view_get_inspector(webview);
if (inspector) {
webkit_web_inspector_detach(inspector);
webkit_web_inspector_show(inspector);
fprintf(stderr, "Inspector should be visible!\n");
} else {
fprintf(stderr, "Could not show inspector (is nil) :(\n");
}
break;
}
default:
break;
}
}
static void handler_free(void *ctx, GClosure *closure) {
(void)closure;
free(ctx);
......@@ -92,6 +112,7 @@ gboolean context_menu(WebKitWebView *wv, WebKitContextMenu *cm, GdkEvent *e, Web
case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY:
case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE:
case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE:
case WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI:
case WEBKIT_CONTEXT_MENU_ACTION_CUSTOM:
break;
case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW:
......@@ -144,6 +165,7 @@ void tether_exit(void) {
tether tether_new(tether_options opts) {
tether self = malloc(sizeof *self);
memcpy(&self->opts, &opts, sizeof opts);
self->data = opts.data;
self->closed = opts.closed;
......@@ -168,7 +190,16 @@ tether tether_new(tether_options opts) {
WebKitWebView *webview = self->webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
WebKitSettings *settings = webkit_web_view_get_settings(webview);
WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager(webview);
if (opts.debug) webkit_settings_set_enable_developer_extras(settings, TRUE);
if (opts.debug) {
webkit_settings_set_enable_developer_extras(settings, TRUE);
g_signal_connect(
webview,
"load-changed",
G_CALLBACK(webview_loaded),
NULL
);
}
// Listen for messages.
struct handler *handler = malloc(sizeof *handler);
......@@ -216,6 +247,10 @@ void tether_load(tether self, const char *html) {
webkit_web_view_load_html(self->webview, html, NULL);
}
void tether_navigate(tether self, const char *uri) {
webkit_web_view_load_uri(self->webview, uri);
}
void tether_title(tether self, const char *title) {
gtk_window_set_title(self->window, title);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment