diff --git a/just/just.fnl b/just/just.fnl index 950e8ec..86bf9ce 100644 --- a/just/just.fnl +++ b/just/just.fnl @@ -135,7 +135,7 @@ progress, trough { container (Gtk.Box { :orientation Gtk.Orientation.VERTICAL }) - viewplex (Viewplex.new) + viewplex (Viewplex.new {:content-filter-store content-filter-store}) navbar (Navbar.new viewplex) progress-bar (Gtk.ProgressBar { :orientation Gtk.Orientation.HORIZONTAL @@ -154,11 +154,12 @@ progress, trough { (if (. arg 1) (each [_ url (ipairs arg)] - (let [v (Webview.new)] + (let [v (Webview.new {:content-filter-store content-filter-store} )] (v:visit url) (viewplex:add-view v))) (viewplex:add-view - (doto (Webview.new) (: :visit "about:blank")))) + (doto (Webview.new {:content-filter-store content-filter-store}) + (: :visit "about:blank")))) (window:add container) (window:show_all)) diff --git a/just/viewplex.fnl b/just/viewplex.fnl index 3d6b1c5..b020789 100644 --- a/just/viewplex.fnl +++ b/just/viewplex.fnl @@ -59,7 +59,8 @@ :height 200 :on_clicked (fn [] (self:add-view - (doto (Webview.new) + (doto (Webview.new + {:content-filter-store self.content-filter-store}) (: :visit "about:blank")))) }) false false 5) @@ -71,7 +72,7 @@ { :new - (fn [] + (fn [{: content-filter-store}] (var foreground-view nil) (let [listeners (Listeners.new) relay-events [] @@ -87,6 +88,7 @@ (listeners:notify event-name $1)))) views {}] { + :content-filter-store content-filter-store :listen (fn [_ name fun] (if (not (. relay-events name)) (each [_ v (pairs views)] diff --git a/just/webview.fnl b/just/webview.fnl index b138f29..26815b7 100644 --- a/just/webview.fnl +++ b/just/webview.fnl @@ -1,7 +1,33 @@ -(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi)) +(local { : Gtk : Gdk : WebKit2 : cairo : GLib } (require :lgi)) (local Listeners (require :listeners)) +(fn load-easylist-json [store cb] + (print "loading easylist from json") + (with-open [f (io.open "easylist_min_content_blocker.json" "r")] + (let [blocks (f:read "*a")] + (store:save "easylist" + (GLib.Bytes blocks) + nil + (fn [self res] + (cb (store:save_finish res))))))) + +(fn load-adblocks [content-manager store] + (store:fetch_identifiers + nil + (fn [self res] + (let [ids (store:fetch_identifiers_finish res) + found (icollect [_ id (pairs ids)] (= id "easylist"))] + (if (> (# found) 0) + (store:load "easylist" nil + (fn [self res] + (content-manager:add_filter + (store:load_finish res)))) + (load-easylist-json + store + (fn [filter] + (content-manager:add_filter filter)))))))) + (fn scale-surface [source image-width image-height] (let [scaled (cairo.ImageSurface.create cairo.Format.ARGB32 @@ -34,29 +60,31 @@ { :new - #(let [listeners (Listeners.new) - props {} - widget (WebKit2.WebView { - :on_notify - (fn [self pspec] - (when (not (= pspec.name :parent)) - (let [val (. self pspec.name)] - (tset props pspec.name val) - (listeners:notify pspec.name val)))) - })] - ;;(load-adblocks webview.user_content_manager content-filter-store) - { - :listen #(listeners:add $2 $3) - :visit (fn [self url] - (widget:load_uri url)) - :stop-loading #(widget:stop_loading) - :refresh #(widget:reload) - :go-back #(and (widget:can_go_back) (widget:go_back)) + (fn [{: content-filter-store}] + (let [listeners (Listeners.new) + props {} + widget (WebKit2.WebView { + :on_notify + (fn [self pspec] + (when (not (= pspec.name :parent)) + (let [val (. self pspec.name)] + (tset props pspec.name val) + (listeners:notify pspec.name val)))) + })] + (when content-filter-store + (load-adblocks widget.user_content_manager content-filter-store)) + { + :listen #(listeners:add $2 $3) + :visit (fn [self url] + (widget:load_uri url)) + :stop-loading #(widget:stop_loading) + :refresh #(widget:reload) + :go-back #(and (widget:can_go_back) (widget:go_back)) - :thumbnail-image (fn [self width height fun] - (thumbnail-image widget width height fun)) + :thumbnail-image (fn [self width height fun] + (thumbnail-image widget width height fun)) - :properties props - :widget widget - }) + :properties props + :widget widget + })) }