blob: d112c11bd9e0f1f547dc46a5fbe4c8f9017eb43b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package mx.trackermap.TrackerMap.controllers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import mx.trackermap.TrackerMap.Injectable
import platform.Network.*
import platform.darwin.*
actual class NetworkController: Injectable {
private val monitor = nw_path_monitor_create()
private val queue: dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND.toLong(), 0u)
private val _networkAvailable = MutableStateFlow<Boolean?>(null)
actual val networkAvailable = _networkAvailable.asStateFlow()
private val updateHandler: nw_path_monitor_update_handler_t = { path: nw_path_t ->
val status = nw_path_get_status(path)
_networkAvailable.value = status in arrayOf(nw_path_status_satisfied, nw_path_status_satisfiable)
}
init {
nw_path_monitor_set_update_handler(monitor, updateHandler)
nw_path_monitor_set_queue(monitor, queue)
nw_path_monitor_start(monitor)
}
}
|