Skip to content

Commit

Permalink
feat: logseq protocol open with file path
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman authored and tiensonqin committed Apr 21, 2022
1 parent c7df6fc commit 644dde0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/electron/electron/url.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/main/electron/listener.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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]
Expand Down

0 comments on commit 644dde0

Please sign in to comment.