Fix logout of mangadex

This commit is contained in:
Jobobby04 2021-07-22 19:28:59 -04:00
parent 1480829dd1
commit b769043f36
5 changed files with 27 additions and 35 deletions

View File

@ -45,6 +45,7 @@ import exh.md.utils.MdUtil
import exh.metadata.metadata.MangaDexSearchMetadata
import exh.source.DelegatedHttpSource
import exh.ui.metadata.adapters.MangaDexDescriptionAdapter
import kotlinx.coroutines.CancellationException
import okhttp3.OkHttpClient
import okhttp3.Response
import rx.Observable
@ -209,19 +210,10 @@ class MangaDex(delegate: HttpSource, val context: Context) :
}
override suspend fun logout(): Boolean {
val result = try {
loginHelper.logout()
true
} catch (e: NoSessionException) {
true
} catch (e: Exception) {
e.message?.equals("HTTP error 405") ?: false
}
return if (result) {
mdList.logout()
true
} else false
val e = runCatching { loginHelper.logout() }.exceptionOrNull()
if (e is CancellationException) throw e
mdList.logout()
return true
}
override suspend fun fetchAllFollows(): List<Pair<SManga, MangaDexSearchMetadata>> {

View File

@ -416,10 +416,6 @@ class SettingsAdvancedController : SettingsController() {
}
class ClearDatabaseDialogController : DialogController() {
// SY -->
var keepReadManga = false
// SY <--
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val item = arrayOf(
activity!!.getString(R.string.clear_db_exclude_read)
@ -427,6 +423,7 @@ class SettingsAdvancedController : SettingsController() {
val selected = booleanArrayOf(true)
return MaterialAlertDialogBuilder(activity!!)
.setMessage(R.string.clear_database_confirmation)
// SY -->
.setMultiChoiceItems(item, selected) { _, _, isChecked ->
selected[0] = isChecked
}

View File

@ -9,6 +9,7 @@ import exh.md.dto.LoginRequestDto
import exh.md.dto.RefreshTokenDto
import exh.md.service.MangaDexAuthService
import exh.md.utils.MdUtil
import kotlinx.coroutines.CancellationException
import kotlinx.serialization.encodeToString
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
@ -30,6 +31,10 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
preferences.trackToken(mdList).set(MdUtil.jsonParser.encodeToString(jsonResponse.token))
}
val e = refresh.exceptionOrNull()
if (e is CancellationException) throw e
return refresh.isSuccess
}
@ -41,6 +46,9 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
val loginRequest = LoginRequestDto(username, password)
val loginResult = runCatching { authService.login(loginRequest) }
val e = loginResult.exceptionOrNull()
if (e is CancellationException) throw e
val loginResponseDto = loginResult.getOrNull()
MdUtil.updateLoginToken(
loginResponseDto?.token,

View File

@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.toast
import exh.log.xLogW
import exh.source.getMainSource
@ -107,7 +108,7 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
)
if (result) {
dialog?.dismiss()
launchUI {
withUIContext {
binding.root.context.toast(R.string.login_success)
}
} else {

View File

@ -8,11 +8,13 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.source.online.all.MangaDex
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.launchNow
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.toast
import exh.source.getMainSource
import kotlinx.coroutines.CancellationException
@ -23,7 +25,7 @@ import uy.kohesive.injekt.injectLazy
class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
val source = Injekt.get<SourceManager>().get(args.getLong("key", 0))?.getMainSource() as? MangaDex
val source = Injekt.get<SourceManager>().get(args.getLong("key", 0))?.getMainSource() as? LoginSource
val trackManager: TrackManager by injectLazy()
@ -40,29 +42,21 @@ class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
launchNow {
supervisorScope {
if (source != null) {
var exception: Exception? = null
val loggedOut = try {
withIOContext { source.logout() }
} catch (e: Exception) {
if (e is CancellationException) throw e
exception = e
false
val loggedOut = withIOContext {
source.logout()
}
if (loggedOut) {
trackManager.mdList.logout()
activity?.toast(R.string.logout_success)
withUIContext {
activity?.toast(R.string.logout_success)
}
(targetController as? Listener)?.siteLogoutDialogClosed(source)
} else {
launchUI {
if (exception != null) {
activity?.toast(exception.message)
} else {
activity?.toast(R.string.unknown_error)
}
withUIContext {
activity?.toast(R.string.unknown_error)
}
}
} else launchUI { activity?.toast("Mangadex not enabled") }
} else withUIContext { activity?.toast("Mangadex not enabled") }
}
}
}