fix: open desktop deep links

fix https://github.com/logseq/db-test/issues/878
This commit is contained in:
Tienson Qin
2026-05-15 16:44:10 +08:00
parent aef715a525
commit a8d1f04734
3 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
(ns electron.link)
(def shell-open-protocols
#{"https:" "http:" "mailto:" "logseq:"})
(defn shell-open-url?
[^js/URL parsed-url]
(contains? shell-open-protocols (.-protocol parsed-url)))

View File

@@ -9,6 +9,7 @@
[electron.context-menu :as context-menu]
[electron.db-worker :as db-worker]
[electron.i18n :refer [t]]
[electron.link :as link]
[electron.logger :as logger]
[electron.spell-check :as spell-check]
[electron.state :as state]
@@ -126,7 +127,7 @@
(let [URL (.-URL URL)
parsed-url (try (URL. url) (catch :default _ nil))]
(when parsed-url
(if (contains? #{"https:" "http:" "mailto:"} (.-protocol parsed-url))
(if (link/shell-open-url? parsed-url)
(.openExternal shell url)
(when-let [^js res (and (fn? default-open)
(.showMessageBoxSync dialog

View File

@@ -0,0 +1,10 @@
(ns electron.link-test
(:require [cljs.test :refer [deftest is]]
[electron.link :as link]))
(deftest logseq-links-open-through-electron-shell
(is (true?
(link/shell-open-url?
(js/URL. "logseq://graph/demo?block-id=00000000-0000-0000-0000-000000000001"))))
(is (true? (link/shell-open-url? (js/URL. "https://logseq.com"))))
(is (false? (link/shell-open-url? (js/URL. "file:///tmp/graph.edn")))))