diff --git a/src/main/frontend/fs/sync.cljs b/src/main/frontend/fs/sync.cljs index 7f5a1222ce..065269c8f9 100644 --- a/src/main/frontend/fs/sync.cljs +++ b/src/main/frontend/fs/sync.cljs @@ -52,7 +52,12 @@ ;; and re-produce a new same-file-delete diff. ;;; ### specs -(s/def ::state #{::idle +(s/def ::state #{;; do following jobs when ::starting: + ;; - wait seconds for file-change-events from file-watcher + ;; - drop redundant file-change-events + ;; - setup states in `frontend.state` + ::starting + ::idle ;; sync local-changed files ::local->remote ;; sync remote latest-transactions @@ -847,7 +852,7 @@ "create a new sync-state" [] {:post [(s/valid? ::sync-state %)]} - {:state ::idle + {:state ::starting :current-local->remote-files #{} :current-remote->local-files #{} :queued-local->remote-files #{} @@ -1417,24 +1422,34 @@ ;; 1. if remote graph has been deleted, clear graphs-txid.edn ;; 2. if graphs-txid.edn's content isn't [user-uuid graph-uuid txid], clear it (if (not= 3 (count @graphs-txid)) - (clear-graphs-txid! repo) + (do (clear-graphs-txid! repo) + (state/set-file-sync-state nil)) (when (check-graph-belong-to-current-user current-user-uuid user-uuid) (if-not (local-sync-chan) + ;; update global state when *sync-state changes (add-watch *sync-state ::update-global-state (fn [_ _ _ n] (state/set-file-sync-state n))) (.start sm) - (state/set-file-sync-manager sm) + (offer! remote->local-sync-chan true) (offer! full-sync-chan true) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 50f1681168..f700dcb547 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -59,8 +59,8 @@ (defn- file-sync-stop-when-switch-graph [] (p/do! (persist-var/load-vars) (sync/sync-stop) - ;; trigger rerender file-sync-header - (state/set-file-sync-state nil))) + (sync/sync-start) +)) (defn- graph-switch [graph] (state/set-current-repo! graph) @@ -98,7 +98,6 @@ (graph-switch graph)))) (defmethod handle :graph/switch [[_ graph]] - (file-sync-stop-when-switch-graph) (if (outliner-file/writes-finished?) (graph-switch-on-persisted graph) (notification/show! diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 8f335fb2ed..31b08ca9c7 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -1668,6 +1668,7 @@ (defn get-file-sync-manager [] (:file-sync/sync-manager @state)) + (defn get-file-sync-state [] (:file-sync/sync-state @state))