Refactor to not get sign-in state from cookies
This commit is contained in:
1 parent
8ac2f33949
commit
ec9b85f30f
12 files changed
+23
-28
No files matched your search
@@ -112,6 +112,7 @@ object Settings : DataStorePreferences(null) {
|
||||
val languageFilter = intPref("language_filter", -1)
|
||||
val downloadSortMode = intPref("download_sort_mode", SortMode.Default.flag)
|
||||
val downloadFilterMode = intPref("download_filter_mode", DownloadsFilterMode.Default.flag)
|
||||
val hasSignedIn = boolPref("has_signed_in", false)
|
||||
val meteredNetworkWarning = boolPref("cellular_network_warning", false)
|
||||
val blackDarkTheme = boolPref("black_dark_theme", false)
|
||||
val gridView = boolPref("grid_view", false)
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hippo.ehviewer
|
||||
|
||||
import android.app.UiModeManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhTagDatabase
|
||||
import com.hippo.ehviewer.dailycheck.updateDailyCheckWork
|
||||
@@ -54,7 +53,7 @@ fun updateWhenRequestNewsChanges() {
|
||||
}
|
||||
|
||||
fun updateWhenGallerySiteChanges() {
|
||||
if (!Settings.needSignIn && EhCookieStore.hasSignedIn()) {
|
||||
if (Settings.hasSignedIn.value) {
|
||||
collectScope.launchIO {
|
||||
runCatching {
|
||||
EhEngine.getUConfig()
|
||||
|
||||
@@ -12,14 +12,9 @@ import io.ktor.http.renderSetCookieHeader
|
||||
|
||||
object EhCookieStore : CookiesStorage {
|
||||
private val manager = CookieManager.getInstance()
|
||||
fun signOut() = manager.removeAllCookies(null)
|
||||
fun removeAllCookies() = manager.removeAllCookies(null)
|
||||
fun contains(url: String, name: String) = load(Url(url)).fastAny { it.name == name }
|
||||
|
||||
fun hasSignedIn(): Boolean {
|
||||
val url = EhUrl.HOST_E
|
||||
return contains(url, KEY_IPB_MEMBER_ID) && contains(url, KEY_IPB_PASS_HASH)
|
||||
}
|
||||
|
||||
const val KEY_IPB_MEMBER_ID = "ipb_member_id"
|
||||
const val KEY_IPB_PASS_HASH = "ipb_pass_hash"
|
||||
const val KEY_IGNEOUS = "igneous"
|
||||
|
||||
@@ -152,8 +152,9 @@ object EhUtils {
|
||||
val categoryTextColor = Color(0xffe6e0e9)
|
||||
|
||||
fun signOut() {
|
||||
EhCookieStore.signOut()
|
||||
EhCookieStore.removeAllCookies()
|
||||
Settings.displayName.value = null
|
||||
Settings.hasSignedIn.value = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
Settings.needSignIn = true
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
@@ -83,7 +82,7 @@ val today
|
||||
get() = (Clock.System.now().epochSeconds / 86400).toInt()
|
||||
|
||||
suspend fun checkDawn() = runCatching {
|
||||
if (EhCookieStore.hasSignedIn() && Settings.lastDawnDays != today) {
|
||||
if (Settings.hasSignedIn.value && Settings.lastDawnDays != today) {
|
||||
EhEngine.getNews(true)?.let {
|
||||
Settings.lastDawnDays = today
|
||||
showEventNotification(it)
|
||||
|
||||
@@ -40,7 +40,6 @@ import androidx.core.content.ContextCompat
|
||||
import com.hippo.ehviewer.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.BaseGalleryInfo
|
||||
@@ -190,7 +189,7 @@ suspend fun DialogState.startDownload(
|
||||
|
||||
suspend fun DialogState.modifyFavorites(galleryInfo: BaseGalleryInfo): Boolean {
|
||||
val localFavorited = EhDB.containLocalFavorites(galleryInfo.gid)
|
||||
if (EhCookieStore.hasSignedIn()) {
|
||||
if (Settings.hasSignedIn.value) {
|
||||
val isFavorited = galleryInfo.favoriteSlot != NOT_FAVORITED
|
||||
val defaultFavSlot = Settings.defaultFavSlot
|
||||
if (defaultFavSlot == -2) {
|
||||
|
||||
@@ -40,5 +40,6 @@ suspend fun postLogin() = coroutineScope {
|
||||
}.onFailure {
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
}
|
||||
Settings.hasSignedIn.value = true
|
||||
Settings.needSignIn = false
|
||||
}
|
||||
@@ -57,7 +57,6 @@ import androidx.paging.filter
|
||||
import com.hippo.ehviewer.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.data.BaseGalleryInfo
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder
|
||||
@@ -100,6 +99,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) = composing(navigator) {
|
||||
val localFavName = stringResource(R.string.local_favorites)
|
||||
val cloudFavName = stringResource(R.string.cloud_favorites)
|
||||
val animateItems by Settings.animateItems.collectAsState()
|
||||
val hasSignedIn by Settings.hasSignedIn.collectAsState()
|
||||
|
||||
// Meta State
|
||||
var urlBuilder by rememberSaveable { mutableStateOf(FavListUrlBuilder(favCat = Settings.recentFavCat)) }
|
||||
@@ -192,7 +192,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) = composing(navigator) {
|
||||
}
|
||||
}
|
||||
val localFav = stringResource(id = R.string.local_favorites) to localFavCount
|
||||
val faves = if (EhCookieStore.hasSignedIn()) {
|
||||
val faves = if (hasSignedIn) {
|
||||
arrayOf(
|
||||
localFav,
|
||||
stringResource(id = R.string.cloud_favorites) to Settings.favCloudCount,
|
||||
@@ -399,7 +399,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) = composing(navigator) {
|
||||
// First is local favorite, the other 10 is cloud favorite
|
||||
val items = buildList {
|
||||
add(localFavName)
|
||||
if (EhCookieStore.hasSignedIn()) {
|
||||
if (hasSignedIn) {
|
||||
addAll(Settings.favCat)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ import androidx.core.text.parseAsHtml
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhFilter.remember
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
@@ -244,7 +243,7 @@ fun GalleryCommentsScreen(gid: Long, navigator: DestinationsNavigator) = composi
|
||||
}
|
||||
}
|
||||
}
|
||||
val hasSignedIn = remember { EhCookieStore.hasSignedIn() }
|
||||
val hasSignedIn by Settings.hasSignedIn.collectAsState()
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
|
||||
@@ -154,8 +154,8 @@ import sh.calvin.reorderable.rememberReorderableLazyListState
|
||||
@Destination<RootGraph>
|
||||
@Composable
|
||||
fun HomePageScreen(navigator: DestinationsNavigator) {
|
||||
val displayName by Settings.displayName.collectAsState()
|
||||
GalleryListScreen(ListUrlBuilder(category = displayName?.let { EhUtils.NONE } ?: EhUtils.NON_H), navigator)
|
||||
val hasSignedIn by Settings.hasSignedIn.collectAsState()
|
||||
GalleryListScreen(ListUrlBuilder(category = if (hasSignedIn) EhUtils.NONE else EhUtils.NON_H), navigator)
|
||||
}
|
||||
|
||||
@Destination<RootGraph>
|
||||
|
||||
@@ -36,9 +36,9 @@ import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.asMutableState
|
||||
import com.hippo.ehviewer.client.CHROME_USER_AGENT
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder
|
||||
import com.hippo.ehviewer.collectAsState
|
||||
import com.hippo.ehviewer.ui.tools.LocalDialogState
|
||||
import com.hippo.ehviewer.ui.tools.observed
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
@@ -215,7 +215,8 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (EhCookieStore.hasSignedIn()) {
|
||||
val hasSignedIn by Settings.hasSignedIn.collectAsState()
|
||||
if (hasSignedIn) {
|
||||
val backupNothing = stringResource(id = R.string.settings_advanced_backup_favorite_nothing)
|
||||
val backupFailed = stringResource(id = R.string.settings_advanced_backup_favorite_failed)
|
||||
val backupSucceed = stringResource(id = R.string.settings_advanced_backup_favorite_success)
|
||||
|
||||
@@ -84,7 +84,7 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
|
||||
val context = LocalContext.current
|
||||
fun launchSnackBar(content: String) = coroutineScope.launch { snackbarHostState.showSnackbar(content) }
|
||||
val signin = EhCookieStore.hasSignedIn()
|
||||
val hasSignedIn by Settings.hasSignedIn.collectAsState()
|
||||
val dialogState = LocalDialogState.current
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -120,9 +120,9 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
dismissText = R.string.settings_eh_clear_igneous,
|
||||
showCancelButton = cookies.last().second != null,
|
||||
onCancelButtonClick = { EhCookieStore.clearIgneous() },
|
||||
secure = signin,
|
||||
secure = hasSignedIn,
|
||||
) {
|
||||
if (signin) {
|
||||
if (hasSignedIn) {
|
||||
Column {
|
||||
val warning = stringResource(id = R.string.settings_eh_identity_cookies_signed)
|
||||
val str = cookies.joinToString("\n") { (k, v) -> "$k: $v" }
|
||||
@@ -153,7 +153,7 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (signin) {
|
||||
if (hasSignedIn) {
|
||||
val placeholder = stringResource(id = R.string.please_wait)
|
||||
val resetImageLimitSucceed = stringResource(id = R.string.reset_limits_succeed)
|
||||
var result by rememberSaveable { mutableStateOf<HomeParser.Result?>(null) }
|
||||
@@ -263,7 +263,7 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
val items = buildList {
|
||||
add(disabled)
|
||||
add(localFav)
|
||||
if (signin) {
|
||||
if (hasSignedIn) {
|
||||
addAll(Settings.favCat)
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
title = stringResource(id = R.string.settings_eh_metered_network_warning),
|
||||
value = Settings.meteredNetworkWarning::value,
|
||||
)
|
||||
if (signin) {
|
||||
if (hasSignedIn) {
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.settings_eh_show_jpn_title),
|
||||
summary = stringResource(id = R.string.settings_eh_show_jpn_title_summary),
|
||||
|
||||
Reference in new issue
Block a user