Quellcode durchsuchen

enhance(iOS): save current block once switch to other app

Some users report data loss if close logseq immediately after edit,
the PR resoves this issue.
leizhe vor 4 Jahren
Ursprung
Commit
123f789429
1 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen
  1. 11 5
      src/main/frontend/mobile/core.cljs

+ 11 - 5
src/main/frontend/mobile/core.cljs

@@ -6,7 +6,10 @@
             [clojure.string :as string]
             [frontend.fs.capacitor-fs :as fs]
             [frontend.components.repo :as repo]
-            [frontend.handler.web.nfs :as nfs-handler]))
+            [frontend.handler.web.nfs :as nfs-handler]
+            [frontend.handler.editor :as editor-handler]
+            [frontend.handler.notification :as notification]
+            [promesa.core :as p]))
 
 (defn init!
   []
@@ -42,7 +45,10 @@
                   #(state/pub-event! [:mobile/keyboard-did-show]))
 
     (.addListener App "appStateChange"
-                  #(when-let [repo (state/get-current-repo)]
-                     (nfs-handler/refresh! repo repo/refresh-cb)
-                     ;; (notification/show! "Notes updated!" :success true)
-                     ))))
+                  (fn [^js state]
+                    (when-let [repo (state/get-current-repo)]
+                      (let [is-active? (.-isActive state)]
+                        (if is-active?
+                          (p/do! (nfs-handler/refresh! repo repo/refresh-cb)
+                                 (notification/show! "Notes updated!" :success true))
+                          (editor-handler/save-current-block!))))))))