feat: logseq protocol open with file path

This commit is contained in:
Junyi Du
2022-04-19 15:21:54 +08:00
committed by Tienson Qin
parent c7df6fc969
commit 644dde0f24
2 changed files with 11 additions and 5 deletions

View File

@@ -34,7 +34,7 @@
`graph identifier` is the name of the graph to open, e.g. `lambda`"
[^js win parsed-url force-new-window?]
(let [graph-identifier (decode (string/replace (.-pathname parsed-url) "/" ""))
[page-name block-id] (get-URL-decoded-params parsed-url ["page" "block-id"])
[page-name block-id file] (get-URL-decoded-params parsed-url ["page" "block-id" "file"])
graph-name (when graph-identifier (handler/get-graph-name graph-identifier))]
(if graph-name
(p/let [window-on-graph (first (win/get-graph-all-windows (utils/get-graph-dir graph-name)))
@@ -43,11 +43,12 @@
(handler/broadcast-persist-graph! graph-name))]
;; TODO: call open new window on new graph without renderer (remove the reliance on local storage)
;; TODO: allow open new window on specific page, without waiting for `graph ready` ipc then redirect to that page
(when (or page-name block-id)
(when (or page-name block-id file)
(let [redirect-f (fn [win' graph-name']
(when (= graph-name graph-name')
(send-to-renderer win' "redirectWhenExists" {:page-name page-name
:block-id block-id})))]
:block-id block-id
:file file})))]
(if open-new-window?
(state/set-state! :window/once-graph-ready redirect-f)
(do (win/switch-to-window! window-on-graph)

View File

@@ -76,7 +76,7 @@
;; :page-name : the original-name of the page.
;; :block-id : uuid.
(fn [data]
(let [{:keys [page-name block-id]} (bean/->clj data)]
(let [{:keys [page-name block-id file]} (bean/->clj data)]
(cond
page-name
(let [db-page-name (db-model/get-redirect-page-name page-name)]
@@ -88,7 +88,12 @@
block-id
(if (db-model/get-block-by-uuid block-id)
(route-handler/redirect-to-page! block-id)
(notification/show! (str "Open link failed. Block-id `" block-id "` doesn't exist in the graph.") :error false))))))
(notification/show! (str "Open link failed. Block-id `" block-id "` doesn't exist in the graph.") :error false))
file
(if-let [db-page-name (db-model/get-file-page file false)]
(route-handler/redirect-to-page! db-page-name)
(notification/show! (str "Open link failed. File `" file "` doesn't exist in the graph.") :error false))))))
(js/window.apis.on "dbsync"
(fn [data]