Fix app crash if mangadex logout dialog has a issue

This commit is contained in:
Jobobby04 2021-01-21 18:46:54 -05:00
parent 94f0dd8362
commit 003e916ab0

View File

@ -14,6 +14,8 @@ import eu.kanade.tachiyomi.util.lang.launchNow
import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import exh.source.getMainSource import exh.source.getMainSource
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.supervisorScope
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -35,17 +37,30 @@ class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
.title(R.string.logout) .title(R.string.logout)
.positiveButton(R.string.logout) { .positiveButton(R.string.logout) {
launchNow { launchNow {
source?.let { source -> supervisorScope {
val loggedOut = withIOContext { source.logout() } 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
}
if (loggedOut) { if (loggedOut) {
trackManager.mdList.logout() trackManager.mdList.logout()
activity?.toast(R.string.logout_success) activity?.toast(R.string.logout_success)
(targetController as? Listener)?.siteLogoutDialogClosed(source) (targetController as? Listener)?.siteLogoutDialogClosed(source)
} else { } else {
activity?.toast(R.string.unknown_error) if (exception != null) {
} activity?.toast(exception.message)
} ?: activity!!.toast("Mangadex not enabled") } else {
activity?.toast(R.string.unknown_error)
}
}
} else activity?.toast("Mangadex not enabled")
}
} }
} }
.negativeButton(android.R.string.cancel) .negativeButton(android.R.string.cancel)