Просмотр исходного кода

fix: unwatch the current listened dir first when refreshing

Tienson Qin 3 лет назад
Родитель
Сommit
fa7611bbae

+ 4 - 0
src/electron/electron/handler.cljs

@@ -400,6 +400,10 @@
   (when dir
     (watcher/watch-dir! dir)))
 
+(defmethod handle :unwatchDir [^js _window [_ dir]]
+  (when dir
+    (watcher/close-watcher! dir)))
+
 (defn open-new-window!
   "Persist db first before calling! Or may break db persistency"
   []

+ 4 - 0
src/main/frontend/fs.cljs

@@ -167,6 +167,10 @@
   [dir]
   (protocol/watch-dir! (get-record) dir))
 
+(defn unwatch-dir!
+  [dir]
+  (protocol/unwatch-dir! (get-record) dir))
+
 (defn mkdir-if-not-exists
   [dir]
   (->

+ 2 - 0
src/main/frontend/fs/bfs.cljs

@@ -35,4 +35,6 @@
   (get-files [_this _path-or-handle _ok-handler]
     nil)
   (watch-dir! [_this _dir]
+    nil)
+  (unwatch-dir! [_this _dir]
     nil))

+ 3 - 1
src/main/frontend/fs/capacitor_fs.cljs

@@ -298,4 +298,6 @@
   (watch-dir! [_this dir]
     (p/do!
      (.unwatch mobile-util/fs-watcher)
-     (.watch mobile-util/fs-watcher #js {:path dir}))))
+     (.watch mobile-util/fs-watcher #js {:path dir})))
+  (unwatch-dir! [_this _dir]
+    (.unwatch mobile-util/fs-watcher)))

+ 3 - 1
src/main/frontend/fs/node.cljs

@@ -127,4 +127,6 @@
   (get-files [_this path-or-handle _ok-handler]
     (ipc/ipc "getFiles" path-or-handle))
   (watch-dir! [_this dir]
-    (ipc/ipc "addDirWatcher" dir)))
+    (ipc/ipc "addDirWatcher" dir))
+  (unwatch-dir! [_this dir]
+    (ipc/ipc "unwatchDir" dir)))

+ 2 - 1
src/main/frontend/fs/protocol.cljs

@@ -15,7 +15,8 @@
   (stat [this dir path])
   (open-dir [this ok-handler])
   (get-files [this path-or-handle ok-handler])
-  (watch-dir! [this dir]) 
+  (watch-dir! [this dir])
+  (unwatch-dir! [this dir])
   ;; Ensure the dir is watched, window agnostic.
   ;; Implementation should handle the actual watcher's construction / destruction.
   ;; So shouldn't consider `unwatch-dir!`.

+ 1 - 0
src/main/frontend/handler/file.cljs

@@ -260,6 +260,7 @@
   []
   (when-let [repo (state/get-current-repo)]
     (when-let [dir (config/get-repo-dir repo)]
+      (fs/unwatch-dir! dir)
       (fs/watch-dir! dir))))
 
 (defn create-metadata-file