diff --git a/src/main/electron/listener.cljs b/src/main/electron/listener.cljs index 0c9a225afd..c8b7f2283a 100644 --- a/src/main/electron/listener.cljs +++ b/src/main/electron/listener.cljs @@ -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] diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index aaf0c607b3..b512b42d66 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -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 diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index 453cc9702d..76a792b029 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -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)) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index c4386ad14b..fe19457aef 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -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.")) diff --git a/src/main/frontend/handler/ui.cljs b/src/main/frontend/handler/ui.cljs index af03bf14ee..f3ee76548b 100644 --- a/src/main/frontend/handler/ui.cljs +++ b/src/main/frontend/handler/ui.cljs @@ -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"))))) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 7b6520133b..8445e10246 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -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 diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index cbda8d631b..62e1827b7b 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -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 "]]"))))) \ No newline at end of file + (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))))