mirror of
https://github.com/logseq/logseq.git
synced 2026-05-22 03:34:07 +00:00
refactor: remove usages of navigator.onLine, window.ononline
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
(def ^:private current-login-user-validator (ma/validator current-login-user-schema))
|
||||
(def *current-login-user (atom nil :validator current-login-user-validator))
|
||||
|
||||
(def *network-online? (atom nil))
|
||||
(def *network-online? (atom true))
|
||||
|
||||
;; Public Flows
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -149,7 +149,6 @@
|
||||
(render)
|
||||
(i18n/start)
|
||||
(instrument/init)
|
||||
(state/set-online! js/navigator.onLine)
|
||||
|
||||
(-> (util/indexeddb-check?)
|
||||
(p/catch (fn [_e]
|
||||
|
||||
@@ -47,39 +47,28 @@
|
||||
(dedupe)
|
||||
rtc-state-flow)))
|
||||
|
||||
(def ^:private network-online-change-flow
|
||||
(m/stream
|
||||
(m/relieve
|
||||
(m/observe
|
||||
(fn ctor [emit!]
|
||||
(let [origin-callback js/window.ononline]
|
||||
(set! js/window.ononline emit!)
|
||||
(emit! nil)
|
||||
(fn dtor []
|
||||
(set! js/window.ononline origin-callback))))))))
|
||||
|
||||
(def rtc-try-restart-flow
|
||||
"emit an event when it's time to restart rtc loop.
|
||||
conditions:
|
||||
- user logged in
|
||||
- no rtc loop running now
|
||||
- last rtc stop-reason is websocket message timeout
|
||||
- current js/navigator.onLine=true
|
||||
- online
|
||||
- throttle 5000ms"
|
||||
(->> (m/latest
|
||||
(fn [rtc-state _ login-user]
|
||||
(assoc rtc-state :login-user login-user))
|
||||
(fn [rtc-state online? login-user]
|
||||
(assoc rtc-state :login-user login-user :online? online?))
|
||||
rtc-state-flow
|
||||
(c.m/continue-flow network-online-change-flow)
|
||||
flows/network-online-event-flow
|
||||
flows/current-login-user-flow)
|
||||
(m/eduction
|
||||
(keep (fn [m]
|
||||
(let [{:keys [rtc-lock last-stop-exception-ex-data graph-uuid login-user]} m]
|
||||
(when (and (some? (:email login-user))
|
||||
(let [{:keys [rtc-lock last-stop-exception-ex-data graph-uuid login-user online?]} m]
|
||||
(when (and online?
|
||||
(some? (:email login-user))
|
||||
(some? graph-uuid)
|
||||
(not rtc-lock) ; no rtc loop now
|
||||
(= :rtc.exception/ws-timeout (:type last-stop-exception-ex-data))
|
||||
(true? js/navigator.onLine))
|
||||
(= :rtc.exception/ws-timeout (:type last-stop-exception-ex-data)))
|
||||
{:graph-uuid graph-uuid :t (common-util/time-ms)})))))
|
||||
(c.m/throttle 5000)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user