mirror of
https://github.com/logseq/logseq.git
synced 2026-06-02 11:21:22 +00:00
feat(mobile): deeplink support
This commit is contained in:
@@ -102,10 +102,11 @@
|
||||
{:title (t :page/open-with-default-app)
|
||||
:options {:on-click #(js/window.apis.openPath file-path)}}])
|
||||
|
||||
(when (util/electron?)
|
||||
(when (or (util/electron?)
|
||||
(mobile-util/native-ios?))
|
||||
{:title (t :page/copy-page-url)
|
||||
:options {:on-click #(util/copy-to-clipboard!
|
||||
(url-util/get-logseq-graph-page-url nil repo page-original-name))}})
|
||||
:options {:on-click #(util/copy-to-clipboard!
|
||||
(url-util/get-logseq-graph-page-url nil repo page-original-name))}})
|
||||
|
||||
(when-not contents?
|
||||
{:title (t :page/delete)
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
(ns frontend.mobile.core
|
||||
(:require [frontend.mobile.util :as mobile-util]
|
||||
[frontend.state :as state]
|
||||
["@capacitor/app" :refer [^js App]]
|
||||
;; ["@capacitor/keyboard" :refer [^js Keyboard]]
|
||||
#_:clj-kondo/ignore
|
||||
["@capacitor/status-bar" :refer [^js StatusBar]]
|
||||
[frontend.mobile.intent :as intent]
|
||||
(:require ["@capacitor/app" :refer [^js App]]
|
||||
[clojure.string :as string]
|
||||
[frontend.fs.capacitor-fs :as fs]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.user :as user-handler]
|
||||
[frontend.mobile.deeplink :as deeplink]
|
||||
[frontend.mobile.intent :as intent]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]))
|
||||
|
||||
(defn- ios-init
|
||||
@@ -55,11 +52,7 @@
|
||||
(.addListener App "appUrlOpen"
|
||||
(fn [^js data]
|
||||
(when-let [url (.-url data)]
|
||||
;; TODO: handler other logseq:// URLs
|
||||
(when (string/starts-with? url "logseq://auth-callback")
|
||||
(let [parsed-url (js/URL. url)
|
||||
code (.get (.-searchParams parsed-url) "code")]
|
||||
(user-handler/login-callback code))))))
|
||||
(deeplink/deeplink url))))
|
||||
|
||||
(.addListener mobile-util/file-sync "debug"
|
||||
(fn [event]
|
||||
|
||||
52
src/main/frontend/mobile/deeplink.cljs
Normal file
52
src/main/frontend/mobile/deeplink.cljs
Normal file
@@ -0,0 +1,52 @@
|
||||
(ns frontend.mobile.deeplink
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.route :as route-handler]
|
||||
[frontend.handler.user :as user-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.text :as text]))
|
||||
|
||||
(defn deeplink [url]
|
||||
(let [parsed-url (js/URL. url)
|
||||
hostname (.-hostname parsed-url)
|
||||
pathname (.-pathname parsed-url)
|
||||
search-params (.-searchParams parsed-url)
|
||||
current-repo-url (state/get-current-repo)
|
||||
current-graph-name (-> (text/get-graph-name-from-path current-repo-url)
|
||||
(string/split "/")
|
||||
last
|
||||
string/lower-case)]
|
||||
|
||||
(cond
|
||||
(= hostname "auth-callback")
|
||||
(when-let [code (.get search-params "code")]
|
||||
(user-handler/login-callback code))
|
||||
|
||||
(= hostname "graph")
|
||||
(let [graph-name (some-> pathname
|
||||
(string/replace "/" "")
|
||||
string/lower-case)
|
||||
[page-name block-uuid] (map #(.get search-params %)
|
||||
["page" "block-id"])]
|
||||
|
||||
(when-not (string/blank? graph-name)
|
||||
(if (= graph-name current-graph-name)
|
||||
(cond
|
||||
page-name
|
||||
(let [db-page-name (db-model/get-redirect-page-name page-name)]
|
||||
(editor-handler/insert-first-page-block-if-not-exists! db-page-name))
|
||||
|
||||
block-uuid
|
||||
(if (db-model/get-block-by-uuid block-uuid)
|
||||
(route-handler/redirect-to-page! block-uuid)
|
||||
(notification/show! (str "Open link failed. Block-id `" block-uuid "` doesn't exist in the graph.") :error false))
|
||||
|
||||
:else
|
||||
(notification/show! (str "Opening File link is not supported on mobile.") :error false))
|
||||
(notification/show! (str "The SCHEME across graphs has not been supported yet.") :error false))))
|
||||
|
||||
:else
|
||||
(notification/show! (str "The url has not been supported yet.") :error false))))
|
||||
Reference in New Issue
Block a user