feat: integrate libre_redirect code into rose.c

This commit is contained in:
NunoSempere 2022-12-17 20:54:27 +01:00
parent 6ff86dcc44
commit 98abdb39c4

44
rose.c
View File

@ -9,10 +9,12 @@
* *
* @author: fenze <contact@fenze.dev> * @author: fenze <contact@fenze.dev>
*/ */
#include <string.h>
#include <stdbool.h>
#include <webkit2/webkit2.h>
#include "config.h" #include "config.h"
#include "plugins/libre_redirect/libre_redirect.h"
#include <webkit2/webkit2.h>
#define CACHE \ #define CACHE \
"base-cache-directory", CACHE_DIR, \ "base-cache-directory", CACHE_DIR, \
@ -78,15 +80,43 @@ void load_uri(WebKitWebView *view, const char *uri)
} }
} }
void redirect_if_annoying(WebKitWebView *view, const char *uri){
int l = LIBRE_N + strlen(uri) + 1;
char uri_filtered[l];
str_init(uri_filtered, l);
int check = libre_redirect(uri, uri_filtered);
if(check == 2){
webkit_web_view_load_uri(view, uri_filtered);
}
}
void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook) void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook)
{ {
if (load_event == WEBKIT_LOAD_FINISHED) { switch (load_event) {
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self), /* see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html> */
webkit_web_view_get_title(self)); case WEBKIT_LOAD_STARTED:
gtk_widget_hide(GTK_WIDGET(bar)); redirect_if_annoying(self, webkit_web_view_get_uri(self));
} break;
case WEBKIT_LOAD_REDIRECTED:
redirect_if_annoying(self, webkit_web_view_get_uri(self));
break;
case WEBKIT_LOAD_COMMITTED:
redirect_if_annoying(self, webkit_web_view_get_uri(self));
break;
case WEBKIT_LOAD_FINISHED:
{
const char* title = webkit_web_view_get_title(self);
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
title == NULL ? "" : title );
// gtk_widget_hide(GTK_WIDGET(bar));
break;
}
}
} }
void notebook_append(GtkNotebook *notebook, const char *uri) void notebook_append(GtkNotebook *notebook, const char *uri)
{ {
GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(window)); GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(window));