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

enhance: wip improve file watcher

Tienson Qin пре 4 година
родитељ
комит
82a4183102
2 измењених фајлова са 12 додато и 5 уклоњено
  1. 9 2
      src/electron/electron/handler.cljs
  2. 3 3
      src/main/frontend/fs/watcher_handler.cljs

+ 9 - 2
src/electron/electron/handler.cljs

@@ -62,8 +62,8 @@
   (or
    (some #(string/starts-with? path (str dir "/" %))
          ["." "assets" "node_modules"])
-   (some #(string/ends-with? path (str dir "/" %))
-         [".swap" ".crswap" ".tmp"])))
+   (some #(string/ends-with? path %)
+         [".swap" ".crswap" ".tmp" ".DS_Store"])))
 
 (defonce allowed-formats
   #{:org :markdown :md :edn :json :css :excalidraw})
@@ -137,6 +137,7 @@
       (send file-watcher-chan
             (bean/->js {:type type :payload payload}))))
 
+(defonce polling-interval 5000)
 (defn watch-dir!
   [win dir]
   (when (fs/existsSync dir)
@@ -144,8 +145,14 @@
                           (clj->js
                            {:ignored (partial ignored-path? dir)
                             :ignoreInitial true
+                            :ignorePermissionErrors true
+                            :interval polling-interval
+                            :binaryInterval polling-interval
                             :persistent true
+                            :disableGlobbing true
+
                             :awaitWriteFinish true}))]
+      ;; TODO: batch sender
       (.on watcher "add"
            (fn [path]
              (send-file-watcher! win "add"

+ 3 - 3
src/main/frontend/fs/watcher_handler.cljs

@@ -21,9 +21,9 @@
         (cond
           (= "add" type)
           (when-not (db/file-exists? repo path)
-              (let [_ (file-handler/alter-file repo path content {:re-render-root? true
-                                                                  :from-disk? true})]
-             (db/set-file-last-modified-at! repo path mtime)))
+            (let [_ (file-handler/alter-file repo path content {:re-render-root? true
+                                                                :from-disk? true})]
+              (db/set-file-last-modified-at! repo path mtime)))
 
           (and (= "change" type)
                (not (db/file-exists? repo path)))