Fix delayed application of HTTP engine changes

This commit is contained in:
FooIbar authored and Vladimir Dostoyevskiy committed 2024-01-07 13:36:41 +08:00
1 parent 4e36cbabc0
commit c82de0b779
3 files changed
+10 -10

No files matched your search

@@ -148,7 +148,7 @@ object Settings : DataStorePreferences(null) {
var harmonizeCategoryColor by boolPref("harmonize_category_color", true)
var preloadThumbAggressively by boolPref("preload_thumb_aggressively", false)
var downloadOriginImage by boolPref("download_origin_image", false)
var enableCronet by boolPref("enable_cronet", true)
var enableCronet by boolPref("enable_cronet", true).observed { updateWhenEnableCronetChanges() }
var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_LOCAL)
var defaultFavSlot by intPref("default_favorite_slot", -2)
var securityDelay by intPref("require_unlock_delay", 0)
@@ -3,6 +3,8 @@ package com.hippo.ehviewer
import android.app.UiModeManager
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import com.hippo.ehviewer.EhApplication.Companion.ktorClient
import com.hippo.ehviewer.EhApplication.Companion.noRedirectKtorClient
import com.hippo.ehviewer.client.EhCookieStore
import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.client.EhTagDatabase
@@ -43,6 +45,13 @@ fun updateWhenKeepMediaStatusChanges() {
}
}
fun updateWhenEnableCronetChanges() {
collectScope.launchIO {
ktorClient = ktorClient.apply { close() }
noRedirectKtorClient = noRedirectKtorClient.apply { close() }
}
}
fun updateWhenThemeChanges() {
collectScope.launch {
delay(100) // Avoid recompose being cancelled
@@ -36,8 +36,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.hippo.ehviewer.BuildConfig
import com.hippo.ehviewer.EhApplication.Companion.ktorClient
import com.hippo.ehviewer.EhApplication.Companion.noRedirectKtorClient
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
@@ -147,11 +145,6 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
summary = if (enableCronet) "Cronet" else "OkHttp",
) {
coroutineScope.launch {
fun reset() {
ktorClient = ktorClient.apply { close() }
noRedirectKtorClient = noRedirectKtorClient.apply { close() }
}
dialogState.awaitPermissionOrCancel(
title = R.string.settings_advanced_http_engine,
showCancelButton = false,
@@ -162,7 +155,6 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
selected = !enableCronet,
onClick = {
enableCronet = false
reset()
},
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2),
) {
@@ -172,7 +164,6 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
selected = enableCronet,
onClick = {
enableCronet = true
reset()
},
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
enabled = isCronetAvailable,