refactor: Remove NWPathMonitor auto-sync, keep only on-demand server checks
- Delete NetworkConnectivity.swift with problematic NWPathMonitor - Remove serverDidBecomeAvailable notification - Remove unused startAutoSync from OfflineSyncManager - Server check now only on app start via AppViewModel
This commit is contained in:
parent
1957995a9e
commit
e5334d456d
@ -124,22 +124,4 @@ class OfflineSyncManager: ObservableObject, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Auto Sync on Server Connectivity Changes
|
|
||||||
|
|
||||||
func startAutoSync() {
|
|
||||||
// Monitor server connectivity and auto-sync when server becomes reachable
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
forName: .serverDidBecomeAvailable,
|
|
||||||
object: nil,
|
|
||||||
queue: .main
|
|
||||||
) { [weak self] _ in
|
|
||||||
Task {
|
|
||||||
await self?.syncOfflineBookmarks()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
NotificationCenter.default.removeObserver(self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,50 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import Network
|
|
||||||
|
|
||||||
class ServerConnectivity: ObservableObject {
|
|
||||||
private let monitor = NWPathMonitor()
|
|
||||||
private let queue = DispatchQueue.global(qos: .background)
|
|
||||||
|
|
||||||
@Published var isServerReachable = false
|
|
||||||
|
|
||||||
static let shared = ServerConnectivity()
|
|
||||||
|
|
||||||
private init() {
|
|
||||||
startMonitoring()
|
|
||||||
}
|
|
||||||
|
|
||||||
private func startMonitoring() {
|
|
||||||
monitor.pathUpdateHandler = { [weak self] path in
|
|
||||||
if path.status == .satisfied {
|
|
||||||
// Network is available, now check server
|
|
||||||
Task {
|
|
||||||
let serverReachable = await ServerConnectivity.isServerReachable()
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
let wasReachable = self?.isServerReachable ?? false
|
|
||||||
self?.isServerReachable = serverReachable
|
|
||||||
|
|
||||||
// Notify when server becomes available
|
|
||||||
if !wasReachable && serverReachable {
|
|
||||||
NotificationCenter.default.post(name: .serverDidBecomeAvailable, object: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self?.isServerReachable = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
monitor.start(queue: queue)
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
monitor.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the Readeck server endpoint is reachable
|
|
||||||
static func isServerReachable() async -> Bool {
|
|
||||||
let useCase = DefaultUseCaseFactory.shared.makeCheckServerReachabilityUseCase()
|
|
||||||
return await useCase.execute()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,9 +8,6 @@ extension Notification.Name {
|
|||||||
// MARK: - Authentication
|
// MARK: - Authentication
|
||||||
static let unauthorizedAPIResponse = Notification.Name("UnauthorizedAPIResponse")
|
static let unauthorizedAPIResponse = Notification.Name("UnauthorizedAPIResponse")
|
||||||
|
|
||||||
// MARK: - Network
|
|
||||||
static let serverDidBecomeAvailable = Notification.Name("ServerDidBecomeAvailable")
|
|
||||||
|
|
||||||
// MARK: - UI Interactions
|
// MARK: - UI Interactions
|
||||||
static let dismissKeyboard = Notification.Name("DismissKeyboard")
|
static let dismissKeyboard = Notification.Name("DismissKeyboard")
|
||||||
static let addBookmarkFromShare = Notification.Name("AddBookmarkFromShare")
|
static let addBookmarkFromShare = Notification.Name("AddBookmarkFromShare")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user