mirror of
https://github.com/logseq/logseq.git
synced 2026-05-27 22:24:09 +00:00
wip: open a different graph in another tab
This commit is contained in:
@@ -164,7 +164,7 @@
|
||||
;; Handle open new window in renderer, until the destination graph doesn't rely on setting local storage
|
||||
;; No db cache persisting ensured. Should be handled by the caller
|
||||
(fn [repo]
|
||||
(ui-handler/open-new-window! repo)))
|
||||
(ui-handler/open-new-window-or-tab! nil repo)))
|
||||
|
||||
(safe-api-call "invokeLogseqAPI"
|
||||
(fn [^js data]
|
||||
|
||||
@@ -188,14 +188,9 @@
|
||||
reindex-link {:title (t :re-index)
|
||||
:hover-detail (t :re-index-detail)
|
||||
:options (cond->
|
||||
{:on-click
|
||||
(fn []
|
||||
(state/pub-event! [:graph/ask-for-re-index *multiple-windows? nil]))})}
|
||||
new-window-link (when (and (util/electron?)
|
||||
;; New Window button in menu bar of macOS is available.
|
||||
(not util/mac?))
|
||||
{:title (t :open-new-window)
|
||||
:options {:on-click #(state/pub-event! [:graph/open-new-window nil])}})]
|
||||
{:on-click
|
||||
(fn []
|
||||
(state/pub-event! [:graph/ask-for-re-index *multiple-windows? nil]))})}]
|
||||
(->>
|
||||
(concat repo-links
|
||||
[(when (seq repo-links) {:hr true})
|
||||
@@ -204,12 +199,11 @@
|
||||
{:title (t :new-graph) :options {:href (rfe/href :repos)}}) ;; Brings to the repos page for showing fallback message
|
||||
(when config/db-graph-enabled?
|
||||
{:title (str (t :new-graph) " - DB version")
|
||||
:options {:on-click #(state/pub-event! [:graph/new-db-graph])}})
|
||||
:options {:on-click #(state/pub-event! [:graph/new-db-graph])}})
|
||||
{:title (t :all-graphs) :options {:href (rfe/href :repos)}}
|
||||
refresh-link
|
||||
(when-not (config/db-based-graph? current-repo)
|
||||
reindex-link)
|
||||
new-window-link])
|
||||
reindex-link)])
|
||||
(remove nil?))))
|
||||
|
||||
(rum/defcs repos-dropdown < rum/reactive
|
||||
|
||||
@@ -100,6 +100,12 @@
|
||||
"http://localhost:3000"
|
||||
(util/format "https://%s.com" app-name)))
|
||||
|
||||
;; FIXME:
|
||||
(def app-website
|
||||
(if dev?
|
||||
"http://localhost:3001"
|
||||
(util/format "https://%s.com" app-name)))
|
||||
|
||||
(def asset-domain (util/format "https://asset.%s.com"
|
||||
app-name))
|
||||
|
||||
|
||||
@@ -241,15 +241,9 @@
|
||||
(file-sync/pick-page-histories-panel graph-uuid page-name)
|
||||
{:id :page-histories :label "modal-page-histories"}))
|
||||
|
||||
(defmethod handle :graph/open-new-window [[_ev repo]]
|
||||
(p/let [current-repo (state/get-current-repo)
|
||||
target-repo (or repo current-repo)
|
||||
_ (when (config/local-file-based-graph? current-repo)
|
||||
(repo-handler/persist-db! current-repo persist-db-noti-m)) ;; FIXME: redundant when opening non-current-graph window
|
||||
_ (when-not (= current-repo target-repo)
|
||||
(when (config/local-file-based-graph? current-repo)
|
||||
(repo-handler/broadcast-persist-db! repo)))]
|
||||
(ui-handler/open-new-window! repo)))
|
||||
(defmethod handle :graph/open-new-window [[_ev target-repo]]
|
||||
(p/let [current-repo (state/get-current-repo)]
|
||||
(ui-handler/open-new-window-or-tab! current-repo target-repo)))
|
||||
|
||||
(defmethod handle :graph/migrated [[_ _repo]]
|
||||
(js/alert "Graph migrated."))
|
||||
|
||||
@@ -293,14 +293,11 @@
|
||||
(state/close-modal!)
|
||||
(state/pub-event! [:modal/show-cards])))
|
||||
|
||||
(defn open-new-window!
|
||||
"Open a new Electron window.
|
||||
No db cache persisting ensured. Should be handled by the caller."
|
||||
([]
|
||||
(open-new-window! nil))
|
||||
([repo]
|
||||
;; TODO: find out a better way to open a new window with a different repo path. Using local storage for now
|
||||
;; TODO: also write local storage with the current repo state, to make behavior consistent
|
||||
;; then we can remove the `openNewWindowOfGraph` ipcMain call
|
||||
(when (string? repo) (storage/set :git/current-repo repo))
|
||||
(ipc/ipc "openNewWindow")))
|
||||
(defn open-new-window-or-tab!
|
||||
"Open a new Electron window."
|
||||
[repo target-repo]
|
||||
(when-not (= repo target-repo) ; TODO: remove this once we support multi-tabs OPFS access
|
||||
(when target-repo
|
||||
(if (util/electron?)
|
||||
(ipc/ipc "openNewWindow" target-repo)
|
||||
(js/window.open (str config/app-website "?graph=" target-repo) "_blank")))))
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
;; Stores main application state
|
||||
(defonce ^:large-vars/data-var state
|
||||
(let [document-mode? (or (storage/get :document/mode?) false)
|
||||
current-graph (let [graph (storage/get :git/current-repo)]
|
||||
current-graph (let [url-graph (:graph (util/parse-params))
|
||||
graph (or url-graph (storage/get :git/current-repo))]
|
||||
(when graph (ipc/ipc "setCurrentGraph" graph))
|
||||
graph)]
|
||||
(atom
|
||||
|
||||
@@ -1549,4 +1549,16 @@ Arg *stop: atom, reset to true to stop the loop"
|
||||
(or
|
||||
(not (string/includes? s " "))
|
||||
(string/starts-with? s "#[[")
|
||||
(string/ends-with? s "]]")))))
|
||||
(string/ends-with? s "]]")))))
|
||||
#?(:cljs
|
||||
(defn parse-params
|
||||
"Parse URL parameters into a hashmap"
|
||||
[]
|
||||
(->> js/window
|
||||
(.-location)
|
||||
(.-search)
|
||||
(new js/URLSearchParams)
|
||||
(seq)
|
||||
(js->clj)
|
||||
(into {})
|
||||
(walk/keywordize-keys))))
|
||||
|
||||
Reference in New Issue
Block a user