Get cookies for image limits if site is Ex

This commit is contained in:
FooIbar authored and tarsin committed 2023-02-11 07:54:11 +08:00
1 parent 453df64f69
commit 099d802a03
5 files changed
+46 -31

No files matched your search

@@ -895,8 +895,7 @@ object EhEngine {
}
@Throws(Throwable::class)
suspend fun getUConfig(): Void? {
val url = EhUrl.uConfigUrl
suspend fun getUConfig(url: String = EhUrl.uConfigUrl): Void? {
Log.d(TAG, url)
var request = EhRequestBuilder(url, null).build()
var call = okHttpClient.newCall(request)
@@ -96,7 +96,6 @@ fun CookieSignInScene() {
store.addCookie(newCookie(EhCookieStore.KEY_IPB_PASS_HASH, hash, EhUrl.DOMAIN_E))
store.addCookie(newCookie(EhCookieStore.KEY_IPB_PASS_HASH, hash, EhUrl.DOMAIN_EX))
if (igneous.isBlank()) return
store.addCookie(newCookie(EhCookieStore.KEY_IGNEOUS, igneous, EhUrl.DOMAIN_E))
store.addCookie(newCookie(EhCookieStore.KEY_IGNEOUS, igneous, EhUrl.DOMAIN_EX))
}
@@ -18,6 +18,8 @@ import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.ui.EhActivity
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
class LoginActivity : EhActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -63,31 +65,37 @@ class LoginActivity : EhActivity() {
}
}
suspend fun postLogin() {
runCatching {
EhEngine.getProfile().run {
Settings.putDisplayName(displayName)
Settings.putAvatar(avatar)
}
}.onFailure {
it.printStackTrace()
}
runCatching {
Settings.putGallerySite(EhUrl.SITE_EX)
EhEngine.getUConfig()
}.onFailure {
Settings.putSelectSite(false)
Settings.putGallerySite(EhUrl.SITE_E)
suspend fun postLogin() = coroutineScope {
launch {
runCatching {
EhEngine.getUConfig()
EhEngine.getProfile().run {
Settings.putDisplayName(displayName)
Settings.putAvatar(avatar)
}
}.onFailure {
it.printStackTrace()
}
}
launch {
runCatching {
Settings.putGallerySite(EhUrl.SITE_EX)
EhEngine.getUConfig()
}.onFailure {
Settings.putSelectSite(false)
Settings.putGallerySite(EhUrl.SITE_E)
launch {
runCatching {
EhEngine.getUConfig()
}.onFailure {
it.printStackTrace()
}
}
}
}.join()
}
val LocalNavController = compositionLocalOf<NavController> { error("CompositionLocal LocalNavController not present!") }
val LocalNavController =
compositionLocalOf<NavController> { error("CompositionLocal LocalNavController not present!") }
const val SIGN_IN_ROUTE_NAME = "SignIn"
const val WEBVIEW_SIGN_IN_ROUTE_NAME = "WebViewSignIn"
@@ -119,14 +119,17 @@ fun SelectSiteScreen() {
) {
Button(onClick = {
Settings.putSelectSite(false)
if (!siteEx) {
Settings.putGallerySite(EhUrl.SITE_E)
coroutineScope.launchNonCancellable {
runCatching {
coroutineScope.launchNonCancellable {
runCatching {
if (!siteEx) {
Settings.putGallerySite(EhUrl.SITE_E)
EhEngine.getUConfig()
}.onFailure {
it.printStackTrace()
} else {
// Get cookies for image limits
EhEngine.getUConfig(EhUrl.URL_UCONFIG_E)
}
}.onFailure {
it.printStackTrace()
}
}
activity.finish()
@@ -15,7 +15,9 @@ import com.hippo.ehviewer.client.EhCookieStore
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.widget.DialogWebChromeClient
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.lang.withUIContext
import okhttp3.Cookie
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
@@ -99,10 +101,14 @@ fun WebviewSignInScreen() {
}
if (getId && getHash) {
present = true
coroutineScope.launchNonCancellable {
postLogin()
coroutineScope.launchIO {
withNonCancellableContext {
postLogin()
}
withUIContext {
navController.navigate(SELECT_SITE_ROUTE_NAME)
}
}
navController.navigate(SELECT_SITE_ROUTE_NAME)
}
}
}