diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt index 3feef0ffae86..00b0a9305b5a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt @@ -105,3 +105,10 @@ inline fun combine( suspend inline fun Deferred.awaitWithTimeoutOrNull(timeout: Long) = withTimeoutOrNull(timeout) { await() } + +fun Deferred.getOrDefault(default: T) = + try { + getCompleted() + } catch (e: IllegalStateException) { + default + } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt index e966b621da27..8980941e6d85 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt @@ -32,6 +32,7 @@ import net.mullvad.mullvadvpn.repository.AccountRepository import net.mullvad.mullvadvpn.repository.DeviceRepository import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase import net.mullvad.mullvadvpn.util.awaitWithTimeoutOrNull +import net.mullvad.mullvadvpn.util.getOrDefault private const val MINIMUM_LOADING_SPINNER_TIME_MILLIS = 500L @@ -101,8 +102,8 @@ class LoginViewModel( .first() } delay(1000) - val outOfTime = isOutOfTimeDeferred.awaitWithTimeoutOrNull(200) - if (outOfTime == true) { + val isOutOfTime = isOutOfTimeDeferred.getOrDefault(false) + if (isOutOfTime) { _uiSideEffect.emit(LoginUiSideEffect.NavigateToOutOfTime) } else { _uiSideEffect.emit(LoginUiSideEffect.NavigateToConnect)