Forráskód Böngészése

feat(sync): allow cancel all request

Andelf 3 éve
szülő
commit
b73829da05

+ 3 - 0
src/electron/electron/file_sync_rsapi.cljs

@@ -47,6 +47,9 @@
 (defn decrypt-with-passphrase [passphrase data]
   (rsapi/ageDecryptWithPassphrase passphrase data))
 
+(defn cancel-all-requests []
+  (rsapi/cancelAllRequests))
+
 (defonce progress-notify-chan "file-sync-progress")
 (set-progress-callback (fn [error progress-info]
                          (when-not error

+ 3 - 0
src/electron/electron/handler.cljs

@@ -579,6 +579,9 @@
 (defmethod handle :decrypt-with-passphrase [_ args]
   (apply rsapi/decrypt-with-passphrase (rest args)))
 
+(defmethod handle :cancel-all-requests [_ args]
+  (apply rsapi/cancel-all-requests (rest args)))
+
 (defmethod handle :default [args]
   (logger/error "Error: no ipc handler for:" args))
 

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

@@ -500,6 +500,9 @@
           ;; options
           {:outer-header
            [:<>
+            (ui/button "stop syncing"
+                       :on-click (fn []
+                                   (fs-sync/rsapi-cancel-all-requests)))
             (when (util/electron?)
               (indicator-progress-pane
                sync-state sync-progress

+ 28 - 19
src/main/frontend/fs/sync.cljs

@@ -657,7 +657,8 @@
   (<update-remote-files [this graph-uuid base-path filepaths local-txid] "local -> remote, return err or txid")
   (<delete-remote-files [this graph-uuid base-path filepaths local-txid] "return err or txid")
   (<encrypt-fnames [this graph-uuid fnames])
-  (<decrypt-fnames [this graph-uuid fnames]))
+  (<decrypt-fnames [this graph-uuid fnames])
+  (<cancel-all-requests [this]))
 
 (defprotocol IRemoteAPI
   (<user-info [this] "user info")
@@ -794,10 +795,12 @@
           #(p->c (ipc/ipc "delete-remote-files" graph-uuid base-path filepaths local-txid token)))))))
   (<encrypt-fnames [_ graph-uuid fnames] (go (js->clj (<! (p->c (ipc/ipc "encrypt-fnames" graph-uuid fnames))))))
   (<decrypt-fnames [_ graph-uuid fnames] (go
-                                (let [r (<! (p->c (ipc/ipc "decrypt-fnames" graph-uuid fnames)))]
-                                  (if (instance? ExceptionInfo r)
-                                    (ex-info "decrypt-failed" {:fnames fnames} (ex-cause r))
-                                    (js->clj r))))))
+                                           (let [r (<! (p->c (ipc/ipc "decrypt-fnames" graph-uuid fnames)))]
+                                             (if (instance? ExceptionInfo r)
+                                               (ex-info "decrypt-failed" {:fnames fnames} (ex-cause r))
+                                               (js->clj r)))))
+  (<cancel-all-requests [_] (go
+                              (<! (p->c (ipc/ipc "cancel-all-requests"))))))
 
 
 (deftype ^:large-vars/cleanup-todo CapacitorAPI [^:mutable graph-uuid' ^:mutable private-key ^:mutable public-key']
@@ -873,10 +876,10 @@
       (let [token (<! (<get-token this))
             r (<! (<retry-rsapi
                    #(p->c (.updateLocalVersionFiles mobile-util/file-sync
-                                                                (clj->js {:graphUUID graph-uuid
-                                                                          :basePath base-path
-                                                                          :filePaths filepaths
-                                                                          :token token})))))]
+                                                    (clj->js {:graphUUID graph-uuid
+                                                              :basePath base-path
+                                                              :filePaths filepaths
+                                                              :token token})))))]
         r)))
 
   (<delete-local-files [_ graph-uuid base-path filepaths]
@@ -903,15 +906,15 @@
 
   (<delete-remote-files [this graph-uuid _base-path filepaths local-txid]
     (go
-     (let [token (<! (<get-token this))
-           r (<! (p->c (.deleteRemoteFiles mobile-util/file-sync
-                                           (clj->js {:graphUUID graph-uuid
-                                                     :filePaths filepaths
-                                                     :txid local-txid
-                                                     :token token}))))]
-       (if (instance? ExceptionInfo r)
-         r
-         (get (js->clj r) "txid")))))
+      (let [token (<! (<get-token this))
+            r (<! (p->c (.deleteRemoteFiles mobile-util/file-sync
+                                            (clj->js {:graphUUID graph-uuid
+                                                      :filePaths filepaths
+                                                      :txid local-txid
+                                                      :token token}))))]
+        (if (instance? ExceptionInfo r)
+          r
+          (get (js->clj r) "txid")))))
 
   (<encrypt-fnames [_ graph-uuid fnames]
     (go
@@ -927,7 +930,9 @@
                                                     :filePaths fnames}))))]
           (if (instance? ExceptionInfo r)
             (ex-info "decrypt-failed" {:fnames fnames} (ex-cause r))
-            (get (js->clj r) "value"))))))
+            (get (js->clj r) "value")))))
+  (<cancel-all-requests [_]
+    (go (<! (p->c (.cancelAllRequest mobile-util/file-sync))))))
 
 (def rsapi (cond
              (util/electron?)
@@ -942,6 +947,10 @@
              :else
              nil))
 
+(defn rsapi-cancel-all-requests []
+  (when rsapi
+    (<! (<cancel-all-requests rsapi))))
+
 ;;; ### remote & rs api exceptions
 (defn sync-stop-when-api-flying?
   [exp]