Maybe fix a few crashes related to mangadex logins
This commit is contained in:
parent
f76c48c8ae
commit
be52ea6f18
@ -12,7 +12,6 @@ import exh.md.utils.MdUtil
|
||||
import exh.util.seconds
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlinx.serialization.encodeToString
|
||||
|
||||
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
||||
val authService by authServiceLazy
|
||||
@ -31,7 +30,7 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
||||
}
|
||||
val refresh = runCatching {
|
||||
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
|
||||
preferences.trackToken(mdList).set(MdUtil.jsonParser.encodeToString(jsonResponse.token))
|
||||
MdUtil.updateLoginToken(jsonResponse.token, preferences, mdList)
|
||||
}
|
||||
|
||||
val e = refresh.exceptionOrNull()
|
||||
@ -52,12 +51,16 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
||||
if (e is CancellationException) throw e
|
||||
|
||||
val loginResponseDto = loginResult.getOrNull()
|
||||
MdUtil.updateLoginToken(
|
||||
loginResponseDto?.token,
|
||||
preferences,
|
||||
mdList
|
||||
)
|
||||
loginResponseDto != null
|
||||
if (loginResponseDto != null) {
|
||||
MdUtil.updateLoginToken(
|
||||
loginResponseDto.token,
|
||||
preferences,
|
||||
mdList
|
||||
)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,10 +300,8 @@ class MdUtil {
|
||||
|
||||
fun refreshToken(preferences: PreferencesHelper, mdList: MdList) = getLoginBody(preferences, mdList)?.refresh
|
||||
|
||||
fun updateLoginToken(token: LoginBodyTokenDto?, preferences: PreferencesHelper, mdList: MdList) {
|
||||
if (token != null) {
|
||||
preferences.trackToken(mdList).set(jsonParser.encodeToString(token))
|
||||
} else preferences.trackToken(mdList).delete()
|
||||
fun updateLoginToken(token: LoginBodyTokenDto, preferences: PreferencesHelper, mdList: MdList) {
|
||||
preferences.trackToken(mdList).set(jsonParser.encodeToString(token))
|
||||
}
|
||||
|
||||
fun getAuthHeaders(headers: Headers, preferences: PreferencesHelper, mdList: MdList) =
|
||||
|
Loading…
x
Reference in New Issue
Block a user