enhance(sync): watch :mobile/app-state-change

trigger a remote->local sync once :mobile/app-state-change activated
This commit is contained in:
rcmerci
2022-06-09 15:08:46 +08:00
parent 406c0a6869
commit 9e85937116
3 changed files with 22 additions and 6 deletions

View File

@@ -1748,6 +1748,13 @@
(add-watch *sync-state ::update-global-state
(fn [_ _ _ n]
(state/set-file-sync-state repo n)))
;; watch :mobile/app-state-change,
;; trigger a remote->local once activated
(add-watch (rum/cursor state/state :mobile/app-state-change) "sync-manage"
(fn [_ _ _ {:keys [is-active?]}]
(when is-active?
(offer! remote->local-sync-chan true))))
(.start sm)
@@ -1769,7 +1776,6 @@
(sync-stop))))))))))))
;;; debug funcs
(comment
(get-remote-all-files-meta remoteapi graph-uuid)

View File

@@ -11,7 +11,7 @@
[frontend.util :as util]))
(def *url (atom nil))
;; FIXME: `appUrlOpen` are fired twice when receiving a same intent.
;; FIXME: `appUrlOpen` are fired twice when receiving a same intent.
;; The following two variable atoms are used to compare whether
;; they are from the same intent share.
(def *last-shared-url (atom nil))
@@ -22,7 +22,7 @@
[]
(let [path (fs/iOS-ensure-documents!)]
(println "iOS container path: " path))
(.addEventListener js/window
"load"
(fn [_event]
@@ -31,7 +31,7 @@
1000))))
(mobile-util/check-ios-zoomed-display)
(.removeAllListeners mobile-util/file-sync)
(.addListener mobile-util/file-sync "debug"
@@ -99,6 +99,7 @@
(fn [^js state]
(when (state/get-current-repo)
(let [is-active? (.-isActive state)]
(state/set-mobile-app-state-change is-active?)
(when-not is-active?
(editor-handler/save-current-block!)))))))
@@ -108,6 +109,6 @@
(when (mobile-util/native-ios?)
(ios-init))
(when (mobile-util/native-platform?)
(general-init)))

View File

@@ -155,7 +155,10 @@
;;; add a random in (<= 1000000) to observer its update
:mobile/toolbar-update-observer 0
:mobile/show-tabbar? false
;;; Used to monitor mobile app status,
;;; value spec:
;;; {:is-active? bool, :timestamp int}
:mobile/app-state-change (atom nil)
;; plugin
:plugin/enabled (and (util/electron?)
;; true false :theme-only
@@ -1685,3 +1688,9 @@
[repo]
(:feature/enable-encryption?
(get (sub-config) repo)))
(defn set-mobile-app-state-change
[is-active?]
(set-state! :mobile/app-state-change
{:is-active? is-active?
:timestamp (inst-ms (js/Date.))}))