Always initialize server/user view models

This commit is contained in:
Damontecres 2025-11-14 13:33:33 -05:00
parent c5a5345f6c
commit b7dfb2ca5f
No known key found for this signature in database
4 changed files with 7 additions and 10 deletions

View file

@ -53,6 +53,7 @@ fun SwitchServerContent(
var showAddServer by remember { mutableStateOf(false) } var showAddServer by remember { mutableStateOf(false) }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
viewModel.init()
viewModel.discoverServers() viewModel.discoverServers()
} }

View file

@ -52,10 +52,6 @@ class SwitchServerViewModel
addServerState.value = LoadingState.Pending addServerState.value = LoadingState.Pending
} }
init {
init()
}
fun init() { fun init() {
viewModelScope.launchIO { viewModelScope.launchIO {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {

View file

@ -58,6 +58,9 @@ fun SwitchUserContent(
), ),
) { ) {
val context = LocalContext.current val context = LocalContext.current
LaunchedEffect(Unit) {
viewModel.init()
}
// val currentServer by viewModel.serverRepository.currentServer.observeAsState() // val currentServer by viewModel.serverRepository.currentServer.observeAsState()
val currentUser by viewModel.serverRepository.currentUser.observeAsState() val currentUser by viewModel.serverRepository.currentUser.observeAsState()

View file

@ -48,12 +48,6 @@ class SwitchUserViewModel
fun create(server: JellyfinServer): SwitchUserViewModel fun create(server: JellyfinServer): SwitchUserViewModel
} }
init {
viewModelScope.launch(Dispatchers.Main + ExceptionHandler()) {
serverRepository.switchServerOrUser()
}
}
val serverQuickConnect = MutableLiveData<Boolean>(false) val serverQuickConnect = MutableLiveData<Boolean>(false)
val users = MutableLiveData<List<JellyfinUser>>(listOf()) val users = MutableLiveData<List<JellyfinUser>>(listOf())
@ -78,6 +72,9 @@ class SwitchUserViewModel
} }
fun init() { fun init() {
viewModelScope.launch(Dispatchers.Main + ExceptionHandler()) {
serverRepository.switchServerOrUser()
}
quickConnectJob?.cancel() quickConnectJob?.cancel()
viewModelScope.launchIO { viewModelScope.launchIO {
users.setValueOnMain(listOf()) users.setValueOnMain(listOf())