mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Merge branch 'release/v0.3.9'
This commit is contained in:
commit
5d1f4b6154
1 changed files with 27 additions and 28 deletions
|
|
@ -55,10 +55,7 @@ import com.github.damontecres.wholphin.ui.util.ProvideLocalClock
|
||||||
import com.github.damontecres.wholphin.util.DebugLogTree
|
import com.github.damontecres.wholphin.util.DebugLogTree
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
|
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
@ -295,40 +292,42 @@ class MainActivityViewModel
|
||||||
private val backdropService: BackdropService,
|
private val backdropService: BackdropService,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
fun appStart() {
|
fun appStart() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launchIO {
|
||||||
val prefs = preferences.data.firstOrNull() ?: AppPreferences.getDefaultInstance()
|
try {
|
||||||
if (prefs.signInAutomatically) {
|
val prefs =
|
||||||
val current =
|
preferences.data.firstOrNull() ?: AppPreferences.getDefaultInstance()
|
||||||
withContext(Dispatchers.IO) {
|
if (prefs.signInAutomatically) {
|
||||||
|
val current =
|
||||||
serverRepository.restoreSession(
|
serverRepository.restoreSession(
|
||||||
prefs.currentServerId?.toUUIDOrNull(),
|
prefs.currentServerId?.toUUIDOrNull(),
|
||||||
prefs.currentUserId?.toUUIDOrNull(),
|
prefs.currentUserId?.toUUIDOrNull(),
|
||||||
)
|
)
|
||||||
}
|
if (current != null) {
|
||||||
if (current != null) {
|
// Restored
|
||||||
// Restored
|
navigationManager.navigateTo(SetupDestination.AppContent(current))
|
||||||
navigationManager.navigateTo(SetupDestination.AppContent(current))
|
|
||||||
} else {
|
|
||||||
// Did not restore
|
|
||||||
navigationManager.navigateTo(SetupDestination.ServerList)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
navigationManager.navigateTo(SetupDestination.Loading)
|
|
||||||
backdropService.clearBackdrop()
|
|
||||||
val currentServerId = prefs.currentServerId?.toUUIDOrNull()
|
|
||||||
if (currentServerId != null) {
|
|
||||||
val currentServer =
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
serverRepository.serverDao.getServer(currentServerId)?.server
|
|
||||||
}
|
|
||||||
if (currentServer != null) {
|
|
||||||
navigationManager.navigateTo(SetupDestination.UserList(currentServer))
|
|
||||||
} else {
|
} else {
|
||||||
|
// Did not restore
|
||||||
navigationManager.navigateTo(SetupDestination.ServerList)
|
navigationManager.navigateTo(SetupDestination.ServerList)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
navigationManager.navigateTo(SetupDestination.ServerList)
|
navigationManager.navigateTo(SetupDestination.Loading)
|
||||||
|
backdropService.clearBackdrop()
|
||||||
|
val currentServerId = prefs.currentServerId?.toUUIDOrNull()
|
||||||
|
if (currentServerId != null) {
|
||||||
|
val currentServer =
|
||||||
|
serverRepository.serverDao.getServer(currentServerId)?.server
|
||||||
|
if (currentServer != null) {
|
||||||
|
navigationManager.navigateTo(SetupDestination.UserList(currentServer))
|
||||||
|
} else {
|
||||||
|
navigationManager.navigateTo(SetupDestination.ServerList)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
navigationManager.navigateTo(SetupDestination.ServerList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Timber.e(ex, "Error during appStart")
|
||||||
|
navigationManager.navigateTo(SetupDestination.ServerList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue