dev: distinguishing () and

pull/4656/head
Junyi Du 2022-03-18 00:58:26 +08:00 committed by Tienson Qin
parent 2b9c995d69
commit 49f96cd71e
4 changed files with 13 additions and 7 deletions

View File

@ -368,7 +368,8 @@
:tx-data tx-data})))))
(defmethod handle :graphHasOtherWindow [^js win [_ graph]]
(win/graph-has-other-windows? win graph))
(let [dir (utils/get-graph-dir graph)]
(win/graph-has-other-windows? win dir)))
(defmethod handle :graphHasMultipleWindows [^js _win [_ graph]]
(let [dir (utils/get-graph-dir graph)
@ -377,6 +378,7 @@
(> (count windows) 1)))
(defmethod handle :addDirWatcher [^js window [_ dir]]
;; receive dir path (not repo / graph) from frontend
;; Windows on same dir share the same watcher
;; Only close file watcher when:
;; 1. there is no one window on the same dir (TODO: check this on a window is closed)

View File

@ -89,14 +89,13 @@
(.getAllWindows BrowserWindow))
(defn get-graph-all-windows
[graph-path]
[graph-path] ;; graph-path == dir
(->> (group-by second (:window/graph @state/state))
(#(get % graph-path))
(map first)))
(defn graph-has-other-windows? [win graph]
(let [dir (utils/get-graph-dir graph)
windows (get-graph-all-windows dir)]
(defn graph-has-other-windows? [win dir]
(let [windows (get-graph-all-windows dir)]
;; windows (filter #(.isVisible %) windows) ;; for mac .hide windows. such windows should also included
(boolean (some (fn [^js window] (not= (.-id win) (.-id window))) windows))))

View File

@ -93,7 +93,10 @@
(srs/update-cards-due-count!)
(state/pub-event! [:graph/ready graph]))
(defn- graph-switch-on-persisted [graph]
(defn- graph-switch-on-persisted
"Logic for keeping db sync when switching graphs
Only works for electron"
[graph]
(p/let [;; save current db
_ (repo-handler/persist-db!)
;; ask other windows to persist the targeting db

View File

@ -684,7 +684,9 @@
(on-error)))))))
(defn persist-otherwindow-db!
"Call backend to handle persisting a specific db on other window
"Only works for electron
Call backend to handle persisting a specific db on other window
Skip persisting if no other windows is open (controlled by electron)
step 1. [In HERE] a window --persistGraph-----> electron
step 2. electron --persistGraph-----> window holds the graph
step 3. window w/ graph --persistGraphDone-> electron