Browse Source

fix: sync icon is missing

Tienson Qin 3 years ago
parent
commit
3312bfc3b6

+ 2 - 1
src/main/frontend/components/block.cljs

@@ -2757,7 +2757,8 @@
                         (block-handler/on-touch-move event block uuid edit? *show-left-menu? *show-right-menu?))
        :on-touch-end (fn [event]
                        (block-handler/on-touch-end event block uuid *show-left-menu? *show-right-menu?))
-       :on-touch-cancel block-handler/on-touch-cancel
+       :on-touch-cancel (fn [_e]
+                          (block-handler/on-touch-cancel *show-left-menu? *show-right-menu?))
        :on-mouse-over (fn [e]
                         (block-mouse-over e *control-show? block-id doc-mode?))
        :on-mouse-leave (fn [e]

+ 3 - 4
src/main/frontend/components/file_sync.cljs

@@ -379,20 +379,19 @@
                                                         (first @graphs-txid)))))
                                            nil
 
-                                           (and synced-file-graph?
-                                                (second @graphs-txid)
+                                           (and (second @graphs-txid)
                                                 (fs-sync/graph-sync-off? (second @graphs-txid))
                                                 (async/<! (fs-sync/<check-remote-graph-exists (second @graphs-txid))))
                                            (fs-sync/<sync-start)
 
                                            ;; remote graph already has been deleted, clear repos first, then create-remote-graph
-                                           synced-file-graph?  ; <check-remote-graph-exists -> false
+                                           (second @graphs-txid) ; <check-remote-graph-exists -> false
                                            (do (state/set-repos!
                                                 (map (fn [r]
                                                        (if (= (:url r) current-repo)
                                                          (dissoc r :GraphUUID :GraphName :remote?)
                                                          r))
-                                                     (state/get-repos)))
+                                                  (state/get-repos)))
                                                (create-remote-graph-fn))
 
                                            (second @graphs-txid) ; sync not started yet

+ 45 - 39
src/main/frontend/fs/sync.cljs

@@ -2753,7 +2753,7 @@
 
   (idle [this]
     (go
-      (let [{:keys [stop remote->local local->remote local->remote-full-sync remote->local-full-sync pause]}
+      (let [{:keys [stop remote->local local->remote local->remote-full-sync remote->local-full-sync pause] :as result}
             (<! ops-chan)]
         (cond
           stop
@@ -3022,43 +3022,6 @@
   (when-let [sm ^SyncManager (state/get-file-sync-manager (state/get-current-file-sync-graph-uuid))]
     (.need-password sm)))
 
-(def app-state-changed-cursor (rum/cursor state/state :mobile/app-state-change))
-
-(def finished-local->remote-chan (chan 1))
-(add-watch app-state-changed-cursor "sync"
-           (fn [_ _ _ {:keys [is-active?]}]
-             (prn "is-active? " is-active?)
-             (cond
-               (mobile-util/native-android?)
-               ;; TODO: support background task on Android
-               (offer! pause-resume-chan is-active?)
-
-               (mobile-util/native-ios?)
-               (let [*task-id (atom nil)]
-                 (if is-active?
-                   (offer! pause-resume-chan is-active?)
-                   (when (state/get-current-file-sync-graph-uuid)
-                     (p/let [task-id (.beforeExit ^js BackgroundTask
-                                                  (fn []
-                                                    (prn "before exit")
-                                                    (go
-                                                      ;; Wait for file watcher events
-                                                      (<! (timeout 2000))
-                                                      (util/drain-chan finished-local->remote-chan)
-                                                      (<! (<sync-local->remote-now))
-                                                      ;; wait at most 20s
-                                                      (async/alts! [finished-local->remote-chan (timeout 20000)])
-                                                      (offer! pause-resume-chan false) ; pause
-                                                      (<! (timeout 5000))
-                                                      (prn "finish task: " @*task-id)
-                                                      (let [opt #js {:taskId @*task-id}]
-                                                        (.finish ^js BackgroundTask opt)))))]
-
-                       (reset! *task-id task-id)))))
-
-               :else
-               nil)))
-
 (defn check-graph-belong-to-current-user
   [current-user-uuid graph-user-uuid]
   (cond
@@ -3123,8 +3086,9 @@
             repo                        (state/get-current-repo)]
         (when-not (instance? ExceptionInfo current-user-uuid)
           (when (and repo
-                     (graph-sync-off? repo) @network-online-cursor
+                     @network-online-cursor
                      user-uuid graph-uuid txid
+                     (graph-sync-off? graph-uuid)
                      (user/logged-in?)
                      (not (config/demo-graph? repo)))
             (try
@@ -3154,6 +3118,48 @@
                 (log/error :exception e)))))
         (reset! *sync-entered? false)))))
 
+(defn- restart-if-stopped!
+  [is-active?]
+  (cond
+    (and is-active? (graph-sync-off? (second @graphs-txid)))
+    (<sync-start)
+
+    :else
+    (offer! pause-resume-chan is-active?)))
+
+(def app-state-changed-cursor (rum/cursor state/state :mobile/app-state-change))
+
+(def finished-local->remote-chan (chan 1))
+
+(add-watch app-state-changed-cursor "sync"
+           (fn [_ _ _ {:keys [is-active?]}]
+             (cond
+               (mobile-util/native-android?)
+               ;; TODO: support background task on Android
+               (restart-if-stopped! is-active?)
+
+               (mobile-util/native-ios?)
+               (let [*task-id (atom nil)]
+                 (restart-if-stopped! is-active?)
+                 (when-not is-active?
+                   (when (state/get-current-file-sync-graph-uuid)
+                     (p/let [task-id (.beforeExit ^js BackgroundTask
+                                                  (fn []
+                                                    (go
+                                                      ;; Wait for file watcher events
+                                                      (<! (timeout 2000))
+                                                      (util/drain-chan finished-local->remote-chan)
+                                                      (<! (<sync-local->remote-now))
+                                                      ;; wait at most 20s
+                                                      (async/alts! [finished-local->remote-chan (timeout 20000)])
+                                                      (prn "finish task: " @*task-id)
+                                                      (let [opt #js {:taskId @*task-id}]
+                                                        (.finish ^js BackgroundTask opt)))))]
+                       (reset! *task-id task-id)))))
+
+               :else
+               nil)))
+
 ;;; ### some add-watches
 
 ;; TOOD: replace this logic by pause/resume state

+ 1 - 1
src/main/frontend/handler/block.cljs

@@ -242,7 +242,7 @@
           (reset! *swipe nil))))))
 
 (defn on-touch-cancel
-  [_event *show-left-menu? *show-right-menu?]
+  [*show-left-menu? *show-right-menu?]
   (reset! *show-left-menu? false)
   (reset! *show-right-menu? false)
   (reset! *swipe nil))

+ 1 - 1
src/main/frontend/idb.cljs

@@ -13,7 +13,7 @@
 ;; To maintain backward compatibility
 
 
-(def store (atom nil))
+(defonce store (atom nil))
 
 (defn clear-idb!
   []

+ 10 - 8
src/main/frontend/state.cljs

@@ -1897,14 +1897,6 @@ Similar to re-frame subscriptions"
   (when v (s/assert :frontend.fs.sync/sync-state v))
   (set-state! [:file-sync/graph-state graph-uuid :file-sync/sync-state] v))
 
-(defn get-file-sync-state
-  [graph-uuid]
-  (get-in @state [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
-
-(defn sub-file-sync-state
-  [graph-uuid]
-  (sub [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
-
 (defn get-current-file-sync-graph-uuid
   []
   (get-in @state [:file-sync/graph-state :current-graph-uuid]))
@@ -1913,6 +1905,16 @@ Similar to re-frame subscriptions"
   []
   (sub [:file-sync/graph-state :current-graph-uuid]))
 
+(defn get-file-sync-state
+  ([]
+   (get-file-sync-state (get-current-file-sync-graph-uuid)))
+  ([graph-uuid]
+   (get-in @state [:file-sync/graph-state graph-uuid :file-sync/sync-state])))
+
+(defn sub-file-sync-state
+  [graph-uuid]
+  (sub [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
+
 (defn reset-parsing-state!
   []
   (set-state! [:graph/parsing-state (get-current-repo)] {}))