fix: deleted remote graph

This can happens when switching between different graphs,
`frontend.fs.sync/graphs-txid` might not be loaded before starting
sync.
pull/6613/head
Tienson Qin 2022-09-06 14:35:10 +08:00
parent 358c352e27
commit 00c325ff35
2 changed files with 29 additions and 22 deletions

View File

@ -1,5 +1,7 @@
(ns frontend.components.file-sync (ns frontend.components.file-sync
(:require [cljs.core.async :as async] (:require [cljs.core.async :as async]
[cljs.core.async.interop :refer [p->c]]
[frontend.util.persist-var :as persist-var]
[clojure.string :as string] [clojure.string :as string]
[electron.ipc :as ipc] [electron.ipc :as ipc]
[frontend.components.lazy-editor :as lazy-editor] [frontend.components.lazy-editor :as lazy-editor]
@ -197,6 +199,7 @@
(state/set-modal! confirm-fn {:center? true :close-btn? false}))) (state/set-modal! confirm-fn {:center? true :close-btn? false})))
turn-on #(async/go turn-on #(async/go
(async/<! (p->c (persist-var/-load fs-sync/graphs-txid)))
(cond (cond
@*beta-unavailable? @*beta-unavailable?
(state/pub-event! [:file-sync/onboarding-tip :unavailable]) (state/pub-event! [:file-sync/onboarding-tip :unavailable])

View File

@ -173,6 +173,7 @@
(def ws-addr config/WS-URL) (def ws-addr config/WS-URL)
;; Warning: make sure to `persist-var/-load` graphs-txid before using it.
(def graphs-txid (persist-var/persist-var nil "graphs-txid")) (def graphs-txid (persist-var/persist-var nil "graphs-txid"))
(declare assert-local-txid<=remote-txid) (declare assert-local-txid<=remote-txid)
@ -2732,13 +2733,16 @@
result))) result)))
(defn sync-start [] (defn sync-start []
(let [[user-uuid graph-uuid txid] @graphs-txid (let [*sync-state (atom (sync-state))
*sync-state (atom (sync-state))
current-user-uuid (user/user-uuid) current-user-uuid (user/user-uuid)
repo (state/get-current-repo)] repo (state/get-current-repo)]
(go (go
;; stop previous sync ;; stop previous sync
(<! (<sync-stop)) (<! (<sync-stop))
(<! (p->c (persist-var/-load graphs-txid)))
(let [[user-uuid graph-uuid txid] @graphs-txid]
(when (and user-uuid graph-uuid txid (when (and user-uuid graph-uuid txid
(user/logged-in?) (user/logged-in?)
repo repo
@ -2761,7 +2765,7 @@
(.start sm) (.start sm)
(offer! remote->local-full-sync-chan true) (offer! remote->local-full-sync-chan true)
(offer! full-sync-chan true))))))))) (offer! full-sync-chan true))))))))))
;;; ### some add-watches ;;; ### some add-watches