Skip to content

Commit 3092622

Browse files
committed
Fix TypeError for non-http links in html-link-activate
- Fixed 'globalThis.application is not a function' error - Fixed logic to properly detect http/https links (case-insensitive check) - http/https links now open directly without warning dialog - Non-http/https links (mailto, etc) show warning dialog before opening - Fixed dialog parenting using global-widgets state with GTK fallback - Alert dialog now properly attached to parent window (no independent movement)
1 parent 6b20c56 commit 3092622

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/main/lobjur/widgets/shared.cljs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns lobjur.widgets.shared
22
(:require
33
["gjs.gi.Gtk" :as Gtk]
4-
["gjs.gi.Adw" :as Adw]))
4+
["gjs.gi.Adw" :as Adw]
5+
[clojure.string :as str]
6+
[lobjur.state :as state]))
57

68
(defn upvote-btn [score]
79
[Gtk/Box
@@ -82,17 +84,20 @@
8284
(let [url (js/URL. href)]
8385
(.-protocol url))
8486
(catch :default _
85-
nil))]
87+
nil))
88+
safe-http-link? (or (str/starts-with? (str/lower-case href) "http://")
89+
(str/starts-with? (str/lower-case href) "https://"))]
8690
(cond
8791
;; Safe schemes: open directly
88-
(or (= scheme "https:")
92+
(or safe-http-link?
93+
(= scheme "https:")
8994
(= scheme "http:"))
9095
(do (Gtk/show_uri nil href 0) true)
9196

9297
;; Unsafe/unknown schemes: show warning dialog
9398
:else
94-
(let [window (some-> (js/globalThis.application)
95-
(.-active_window))
99+
(let [window (or (:main-window @state/global-widgets)
100+
(some-> (Gtk/Application.get_default) (.get_active_window)))
96101
dialog (Adw/AlertDialog.
97102
#js {:heading "Suspicious Link"
98103
:body (str "This link uses a potentially dangerous scheme:\n\n" href "\n\nOpening it may be unsafe.")

0 commit comments

Comments
 (0)