浏览代码

enhance: use flow to synchronize network-status to the worker

flows/network-online-event-flow considers both mobile and web scenarios
rcmerci 6 月之前
父节点
当前提交
5384ec063e
共有 2 个文件被更改,包括 8 次插入3 次删除
  1. 7 0
      src/main/frontend/background_tasks.cljs
  2. 1 3
      src/main/frontend/handler.cljs

+ 7 - 0
src/main/frontend/background_tasks.cljs

@@ -2,6 +2,7 @@
   "Some background tasks"
   (:require [frontend.common.missionary :as c.m]
             [frontend.flows :as flows]
+            [frontend.state :as state]
             [logseq.db.common.entity-plus :as entity-plus]
             [missionary.core :as m]))
 
@@ -13,3 +14,9 @@
       ;; (prn :reset-immutable-entities-cache!)
       (entity-plus/reset-immutable-entities-cache!)))
   flows/current-repo-flow))
+
+(c.m/run-background-task
+ ::sync-to-worker-network-online-status
+ (m/reduce
+  (fn [_ online?] (state/<invoke-db-worker :thread-api/update-thread-atom :thread-atom/online-event online?))
+  flows/network-online-event-flow))

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

@@ -102,9 +102,7 @@
 (defn- handle-connection-change
   [e]
   (let [online? (= (gobj/get e "type") "online")]
-    (state/set-online! online?)
-    (state/<invoke-db-worker :thread-api/update-thread-atom
-                             :thread-atom/online-event online?)))
+    (state/set-online! online?)))
 
 (defn set-network-watcher!
   []