瀏覽代碼

Merge branch 'feat/tweet-shape' of github.com:logseq/logseq into feat/tweet-shape

Konstantinos Kaloutas 2 年之前
父節點
當前提交
59a38836f6
共有 3 個文件被更改,包括 28 次插入3 次删除
  1. 7 3
      src/main/frontend/fs/sync.cljs
  2. 1 0
      src/main/frontend/handler.cljs
  3. 20 0
      src/main/frontend/util.cljc

+ 7 - 3
src/main/frontend/fs/sync.cljs

@@ -2725,7 +2725,7 @@
                ^:mutable ratelimit-local-changes-chan
                *txid *txid-for-get-deletion-log
                ^:mutable state ^:mutable remote-change-chan ^:mutable *ws *stopped? *paused?
-               ^:mutable ops-chan
+               ^:mutable ops-chan ^:mutable app-awake-from-sleep-chan
                ;; control chans
                private-full-sync-chan private-remote->local-sync-chan
                private-remote->local-full-sync-chan private-pause-resume-chan]
@@ -2757,6 +2757,7 @@
 
   (start [this]
     (set! ops-chan (chan (async/dropping-buffer 10)))
+    (set! app-awake-from-sleep-chan (chan (async/sliding-buffer 1)))
     (set! *ws (atom nil))
     (set! remote-change-chan (ws-listen! graph-uuid *ws))
     (set! ratelimit-local-changes-chan (<ratelimit local->remote-syncer local-changes-revised-chan))
@@ -2765,6 +2766,7 @@
     (async/tap remote->local-sync-mult private-remote->local-sync-chan)
     (async/tap remote->local-full-sync-mult private-remote->local-full-sync-chan)
     (async/tap pause-resume-mult private-pause-resume-chan)
+    (async/tap util/app-wake-up-from-sleep-mult app-awake-from-sleep-chan)
     (go-loop []
       (let [{:keys [remote->local remote->local-full-sync local->remote-full-sync local->remote resume pause stop]}
             (async/alt!
@@ -2780,8 +2782,9 @@
                                                     vs     (cons v rest-v)]
                                                 (println "local changes:" vs)
                                                 {:local->remote vs})))
+              app-awake-from-sleep-chan {:remote->local true}
               (timeout (* 20 60 1000)) {:local->remote-full-sync true}
-              (timeout (* 5 60 1000)) {:remote->local true}
+              (timeout (* 10 60 1000)) {:remote->local true}
               :priority true)]
         (cond
           stop
@@ -3071,6 +3074,7 @@
         (async/untap remote->local-sync-mult private-remote->local-sync-chan)
         (async/untap remote->local-full-sync-mult private-remote->local-full-sync-chan)
         (async/untap pause-resume-mult private-pause-resume-chan)
+        (async/untap util/app-wake-up-from-sleep-mult app-awake-from-sleep-chan)
         (when ops-chan (async/close! ops-chan))
         (stop-local->remote! local->remote-syncer)
         (stop-remote->local! remote->local-syncer)
@@ -3104,7 +3108,7 @@
     (.set-local->remote-syncer! remote->local-syncer local->remote-syncer)
     (swap! *sync-state sync-state--update-current-syncing-graph-uuid graph-uuid)
     (->SyncManager user-uuid graph-uuid base-path *sync-state local->remote-syncer remote->local-syncer remoteapi-with-stop
-                   nil *txid *txid-for-get-deletion-log nil nil nil *stopped? *paused? nil (chan 1) (chan 1) (chan 1) (chan 1))))
+                   nil *txid *txid-for-get-deletion-log nil nil nil *stopped? *paused? nil nil (chan 1) (chan 1) (chan 1) (chan 1))))
 
 (defn sync-manager-singleton
   [user-uuid graph-uuid base-path repo txid *sync-state]

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

@@ -228,6 +228,7 @@
 
   (db/run-batch-txs!)
   (file/<ratelimit-file-writes!)
+  (util/<app-wake-up-from-sleep-loop (atom false))
 
   (when config/dev?
     (enable-datalog-console))

+ 20 - 0
src/main/frontend/util.cljc

@@ -1445,3 +1445,23 @@
           (reset! last-mem ret)
           ret)
         @last-mem))))
+
+#?(:cljs
+   (do
+     (def ^:private app-wake-up-from-sleep-chan (async/chan 1))
+     (def app-wake-up-from-sleep-mult (async/mult app-wake-up-from-sleep-chan))
+     (defn <app-wake-up-from-sleep-loop
+       "start a async/go-loop to check the app awake from sleep.
+Use (async/tap `app-wake-up-from-sleep-mult`) to receive messages.
+Arg *stop: atom, reset to true to stop the loop"
+       [*stop]
+       (let [*last-activated-at (volatile! (tc/to-epoch (t/now)))]
+         (async/go-loop []
+           (if @*stop
+             (println :<app-wake-up-from-sleep-loop :stop)
+             (let [now-epoch (tc/to-epoch (t/now))]
+               (when (< @*last-activated-at (- now-epoch 10))
+                 (async/>! app-wake-up-from-sleep-chan {:last-activated-at @*last-activated-at :now now-epoch}))
+               (vreset! *last-activated-at now-epoch)
+               (async/<! (async/timeout 5000))
+               (recur))))))))