From f4e13f1bfc7026d5b68f0360b28fa0bff1fb78c1 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 9 Dec 2022 20:04:31 +0800 Subject: [PATCH] fix: ignore initial watcher events on desktop --- src/electron/electron/fs_watcher.cljs | 2 +- src/main/frontend/fs/sync.cljs | 11 +---------- src/main/frontend/fs/watcher_handler.cljs | 20 ++++++++++++++++++++ src/main/frontend/handler/events.cljs | 7 ++++--- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/electron/electron/fs_watcher.cljs b/src/electron/electron/fs_watcher.cljs index d2c2b6d66c..2fd09d7cf7 100644 --- a/src/electron/electron/fs_watcher.cljs +++ b/src/electron/electron/fs_watcher.cljs @@ -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 diff --git a/src/main/frontend/fs/sync.cljs b/src/main/frontend/fs/sync.cljs index 2c9021826e..91af4b828d 100644 --- a/src/main/frontend/fs/sync.cljs +++ b/src/main/frontend/fs/sync.cljs @@ -2742,16 +2742,7 @@ (let [next-state ( + (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))))))))) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 51908214c8..6f5bb7d98b 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -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