Yokan / rebuild
Course 1 8624561

SharedPlatformWebView.android.kt

composeApp/src/androidMain/kotlin/eu/friedcutlet/yokan/ui/screens/webview/SharedPlatformWebView.android.kt

implementation29 lines
1package eu.friedcutlet.yokan.ui.screens.webview23import androidx.webkit.CookieManagerCompat4import androidx.webkit.WebViewFeature5import com.multiplatform.webview.cookie.Cookie6import com.multiplatform.webview.web.NativeWebView7import com.multiplatform.webview.web.WebViewFactoryParam8import eu.friedcutlet.yokan.domain.ProfileId9import eu.friedcutlet.yokan.services.webview.newProfileWebView10import eu.friedcutlet.yokan.services.webview.profileCookieManager11import kotlinx.coroutines.Dispatchers12import kotlinx.coroutines.withContext1314internal actual fun profileWebViewFactory(profileId: ProfileId): (WebViewFactoryParam) -> NativeWebView =15    { param -> newProfileWebView(param.context, profileId) }1617// ProfileStore (extra profiles' cookie stores) is main-thread only.18internal actual suspend fun setProfileWebViewCookie(profileId: ProfileId, url: String, cookie: Cookie) =19    withContext(Dispatchers.Main.immediate) { profileCookieManager(profileId).setCookie(url, cookie.toString()) }2021internal actual suspend fun profileWebViewSetCookies(profileId: ProfileId, url: String): List<String> =22    withContext(Dispatchers.Main.immediate) {23        val manager = profileCookieManager(profileId)24        if (WebViewFeature.isFeatureSupported(WebViewFeature.GET_COOKIE_INFO)) {25            CookieManagerCompat.getCookieInfo(manager, url)26        } else {27            manager.getCookie(url).orEmpty().split(';').map { "${it.trim()}; Path=/" }28        }29    }30

Search chapters, reference and source filenames.