diff --git a/next/kmp/dwebview/src/androidMain/kotlin/org/dweb_browser/dwebview/DWebProfileStore.chromium.kt b/next/kmp/dwebview/src/androidMain/kotlin/org/dweb_browser/dwebview/DWebProfileStore.chromium.kt index 075a3a121..b46d09412 100644 --- a/next/kmp/dwebview/src/androidMain/kotlin/org/dweb_browser/dwebview/DWebProfileStore.chromium.kt +++ b/next/kmp/dwebview/src/androidMain/kotlin/org/dweb_browser/dwebview/DWebProfileStore.chromium.kt @@ -4,8 +4,6 @@ import android.annotation.SuppressLint import androidx.webkit.ProfileStore import androidx.webkit.WebViewCompat import org.dweb_browser.dwebview.engine.DWebViewEngine -import org.dweb_browser.helper.compose.ENV_SWITCH_KEY -import org.dweb_browser.helper.compose.envSwitch import org.dweb_browser.helper.platform.keyValueStore import org.dweb_browser.helper.withMainContext @@ -21,6 +19,7 @@ class ChromiumWebProfileStore(private val profileStore: ProfileStore) : AndroidW */ init { for (name in profileStore.allProfileNames.toList()) { + /// 上个版本的隐私模式使用 incognito_ 前缀,但几乎没有生效过 if (name.endsWith(IncognitoSuffix)) { profileStore.deleteProfile(name) } @@ -38,24 +37,22 @@ class ChromiumWebProfileStore(private val profileStore: ProfileStore) : AndroidW override suspend fun getAllProfileNames() = allProfiles.keys.toList() override val isSupportIncognitoProfile: Boolean = true - override fun getOrCreateProfile(engine: DWebViewEngine, profileName: String): DWebProfile = when { - envSwitch.isEnabled(ENV_SWITCH_KEY.DWEBVIEW_PROFILE) -> - (allProfiles[profileName] ?: profileStore.getOrCreateProfile(profileName)).let { profile -> - WebViewCompat.setProfile(engine, profileName) - ChromiumWebProfile(profile).also { - allProfiles[profileName] = it - keyValueStore.setValues(DwebProfilesKey, allProfiles.keys) - } + override fun getOrCreateProfile(engine: DWebViewEngine, profileName: String): DWebProfile = + /// 上个版本(240622)起,已经在使用 profileStore 来创建并使用 profile 了 + (allProfiles[profileName] ?: profileStore.getOrCreateProfile(profileName)).let { profile -> + WebViewCompat.setProfile(engine, profileName) + ChromiumWebProfile(profile).also { + allProfiles[profileName] = it + keyValueStore.setValues(DwebProfilesKey, allProfiles.keys) } - - else -> CompactDWebProfile("*") - } + } override fun getOrCreateIncognitoProfile( engine: DWebViewEngine, sessionId: String, profileName: String, ): ChromiumWebProfile { + /// 上个版本(240622)的 incognito 模式使用更简单的 prefix 模式,但几乎没有生效过 val incognitoProfileName = "$profileName@$sessionId$IncognitoSuffix" return (profileStore.getOrCreateProfile(incognitoProfileName)).let { profile -> WebViewCompat.setProfile(engine, incognitoProfileName)