#1257 - Prevent the syncing indicator from showing over the offline one

This commit is contained in:
Stefan Ceriu
2023-08-08 15:09:05 +03:00
committed by Stefan Ceriu
parent 59865a4b16
commit 56544d6604
2 changed files with 20 additions and 8 deletions
@@ -475,10 +475,10 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
networkMonitorObserver = ServiceLocator.shared.networkMonitor networkMonitorObserver = ServiceLocator.shared.networkMonitor
.reachabilityPublisher .reachabilityPublisher
.removeDuplicates() .removeDuplicates()
.sink { reachable in .sink { reachability in
MXLog.info("Reachability changed to \(reachable)") MXLog.info("Reachability changed to \(reachability)")
if reachable { if reachability == .reachable {
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier) ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier)
} else { } else {
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier, ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier,
@@ -566,7 +566,10 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: identifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true)) ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: identifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
} }
showLoadingIndicator() // Prevent the syncing indicator from showing over the offline one
if ServiceLocator.shared.networkMonitor.reachabilityPublisher.value == .reachable {
showLoadingIndicator()
}
clientProxyObserver = userSession.clientProxy clientProxyObserver = userSession.clientProxy
.callbacks .callbacks
+13 -4
View File
@@ -18,10 +18,19 @@ import Combine
import Foundation import Foundation
import Network import Network
enum NetworkMonitorReachability {
case reachable
case unreachable
}
class NetworkMonitor { class NetworkMonitor {
private let pathMonitor: NWPathMonitor private let pathMonitor: NWPathMonitor
private let queue: DispatchQueue private let queue: DispatchQueue
let reachabilityPublisher: CurrentValueSubject<Bool, Never>
private let reachabilitySubject: CurrentValueSubject<NetworkMonitorReachability, Never>
var reachabilityPublisher: CurrentValuePublisher<NetworkMonitorReachability, Never> {
reachabilitySubject.asCurrentValuePublisher()
}
var isCurrentConnectionExpensive: Bool { var isCurrentConnectionExpensive: Bool {
pathMonitor.currentPath.isExpensive pathMonitor.currentPath.isExpensive
@@ -34,14 +43,14 @@ class NetworkMonitor {
init() { init() {
queue = DispatchQueue(label: "io.element.elementx.networkmonitor", qos: .background) queue = DispatchQueue(label: "io.element.elementx.networkmonitor", qos: .background)
pathMonitor = NWPathMonitor() pathMonitor = NWPathMonitor()
reachabilityPublisher = CurrentValueSubject<Bool, Never>(true) reachabilitySubject = CurrentValueSubject<NetworkMonitorReachability, Never>(.reachable)
pathMonitor.pathUpdateHandler = { [weak self] path in pathMonitor.pathUpdateHandler = { [weak self] path in
DispatchQueue.main.async { DispatchQueue.main.async {
if path.status == .satisfied { if path.status == .satisfied {
self?.reachabilityPublisher.send(true) self?.reachabilitySubject.send(.reachable)
} else { } else {
self?.reachabilityPublisher.send(false) self?.reachabilitySubject.send(.unreachable)
} }
} }
} }