fix: ignore initial watcher events on desktop

pull/7682/head
Tienson Qin 2022-12-09 20:04:31 +08:00
parent 10f6d64f04
commit f4e13f1bfc
4 changed files with 26 additions and 14 deletions

View File

@ -62,7 +62,7 @@
(let [watcher-opts (clj->js
{:ignored (fn [path]
(utils/ignored-path? dir path))
:ignoreInitial false
:ignoreInitial true
:ignorePermissionErrors true
:interval polling-interval
:binaryInterval polling-interval

View File

@ -2742,16 +2742,7 @@
(let [next-state (<! (<loop-ensure-pwd&keys graph-uuid (state/get-current-repo) *stopped?))]
(assert (s/valid? ::state next-state) next-state)
(when (= next-state ::idle)
(<! (<ensure-set-env&keys graph-uuid *stopped?))
;; wait seconds to receive all file change events,
;; and then drop all of them.
;; WHY: when opening a graph(or switching to another graph),
;; file-watcher will send a lot of file-change-events,
;; actually, each file corresponds to a file-change-event,
;; we need to ignore all of them.
(<! (timeout 3000))
(println :drain-local-changes-chan-at-starting
(count (util/drain-chan local-changes-revised-chan))))
(<! (<ensure-set-env&keys graph-uuid *stopped?)))
(if @*stopped?
(.schedule this ::stop nil nil)
(.schedule this next-state nil nil)))))

View File

@ -113,3 +113,23 @@
;; return nil, otherwise the entire db will be transfered by ipc
nil)))
(defn load-graph-files!
[graph]
(when graph
(let [dir (config/get-repo-dir graph)]
(p/let [files (fs/readdir dir :path-only? true)]
(doseq [file files]
(->
(p/let [content (fs/read-file dir file)
stat (fs/stat dir file)
type (if (db/file-exists? graph file)
"change"
"add")]
(handle-changed! type
{:dir dir
:path file
:content content
:stat stat}))
(p/catch (fn [error]
(js/console.dir error)))))))))

View File

@ -139,11 +139,11 @@
(repo-config-handler/restore-repo-config! graph)
(when-not (= :draw (state/get-current-route))
(route-handler/redirect-to-home!))
(when-let [dir-name (config/get-repo-dir graph)]
(fs/watch-dir! dir-name))
(srs/update-cards-due-count!)
(state/pub-event! [:graph/ready graph])
(file-sync-restart!)))))
(file-sync-restart!)
(when-let [dir-name (config/get-repo-dir graph)]
(fs/watch-dir! dir-name))))))
;; Parameters for the `persist-db` function, to show the notification messages
(def persist-db-noti-m
@ -366,6 +366,7 @@
(state/pub-event! [:graph/dir-gone dir]))))
;; FIXME: an ugly implementation for redirecting to page on new window is restored
(repo-handler/graph-ready! repo)
(fs-watcher/load-graph-files! repo)
;; TODO: Notify user to update filename format when the UX is smooth enough
;; (when-not config/test?
;; (js/setTimeout