Преглед изворни кода

dev: distinguishing () and

Junyi Du пре 3 година
родитељ
комит
49f96cd71e

+ 3 - 1
src/electron/electron/handler.cljs

@@ -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)

+ 3 - 4
src/electron/electron/window.cljs

@@ -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))))
 

+ 4 - 1
src/main/frontend/handler/events.cljs

@@ -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

+ 3 - 1
src/main/frontend/handler/repo.cljs

@@ -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