Skip to content

Commit

Permalink
enhance: wip improve file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 16, 2021
1 parent 23cc57e commit 82a4183
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -137,15 +137,22 @@
(send file-watcher-chan
(bean/->js {:type type :payload payload}))))

(defonce polling-interval 5000)
(defn watch-dir!
[win dir]
(when (fs/existsSync dir)
(let [watcher (.watch watcher dir
(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"
Expand Down
6 changes: 3 additions & 3 deletions src/main/frontend/fs/watcher_handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 82a4183

Please sign in to comment.