@ -23,9 +23,11 @@ import com.tailscale.ipn.ui.util.PeerCategorizer
import com.tailscale.ipn.ui.util.PeerSet
import com.tailscale.ipn.ui.util.PeerSet
import com.tailscale.ipn.ui.util.TimeUtil
import com.tailscale.ipn.ui.util.TimeUtil
import com.tailscale.ipn.ui.util.set
import com.tailscale.ipn.ui.util.set
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch
import kotlinx.coroutines.launch
import java.time.Duration
import java.time.Duration
@ -38,6 +40,7 @@ class MainViewModelFactory(private val vpnViewModel: VpnViewModel) : ViewModelPr
}
}
}
}
@OptIn ( FlowPreview :: class )
class MainViewModel ( private val vpnViewModel : VpnViewModel ) : IpnViewModel ( ) {
class MainViewModel ( private val vpnViewModel : VpnViewModel ) : IpnViewModel ( ) {
// The user readable state of the system
// The user readable state of the system
@ -112,6 +115,14 @@ class MainViewModel(private val vpnViewModel: VpnViewModel) : IpnViewModel() {
}
}
}
}
viewModelScope . launch {
searchTerm
. debounce ( 250L )
. collect { term ->
peers . set ( peerCategorizer . groupedAndFilteredPeers ( term ) )
}
}
viewModelScope . launch {
viewModelScope . launch {
Notifier . netmap . collect { it ->
Notifier . netmap . collect { it ->
it ?. let { netmap ->
it ?. let { netmap ->
@ -131,16 +142,12 @@ class MainViewModel(private val vpnViewModel: VpnViewModel) : IpnViewModel() {
}
}
}
}
}
}
viewModelScope . launch {
searchTerm . collect { term -> peers . set ( peerCategorizer . groupedAndFilteredPeers ( term ) ) }
}
}
viewModelScope . launch {
viewModelScope . launch {
App . get ( ) . healthNotifier ?. currentIcon ?. collect { icon -> healthIcon . set ( icon ) }
App . get ( ) . healthNotifier ?. currentIcon ?. collect { icon -> healthIcon . set ( icon ) }
}
}
}
}
}
fun showVPNPermissionLauncherIfUnauthorized ( ) {
fun showVPNPermissionLauncherIfUnauthorized ( ) {
val vpnIntent = VpnService . prepare ( App . get ( ) )
val vpnIntent = VpnService . prepare ( App . get ( ) )