Yokan / rebuild
Course 1 8624561

WebViewService.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/webview/WebViewService.kt

implementation51 lines
1package eu.friedcutlet.yokan.services.webview23import eu.friedcutlet.yokan.services.http.HttpResponse4import eu.friedcutlet.yokan.services.http.HttpService567interface WebViewService {8    suspend fun open(request: WebViewRequest): Boolean9    suspend fun resolveCloudflare(request: WebViewRequest): HttpResponse?10    /**11     * Headless JS evaluation against [url]. Returns the JSON-encoded result the WebView yielded,12     * or an empty string if WebView is not available on the current platform. The Android actual13     * drives `android.webkit.WebView`; desktop/iOS fall through to the stub unless a host app14     * supplies one.15     */16    suspend fun evaluateScript(url: String, script: String, userAgent: String? = null): String = ""1718    /**19     * Pull the platform WebView's current cookie set for [url] and persist it20     * into the shared `CookieJar`, so the next `http.request` for that host21     * carries the user's session. Called after page loads in the in-app22     * WebView and after every headless `evaluateScript` round-trip.23     *24     * Returns the rendered `name=value; …` cookie string that was harvested25     * (useful for logging / callers that want to confirm), or null if the26     * platform doesn't expose a cookie store.27     */28    suspend fun syncCookies(url: String): String? = null29}3031data class WebViewRequest(32    val url: String,33    val title: String,34    val headers: Map<String, String> = emptyMap(),35)3637/** Default adopts the shared platform store; extras get their profile's isolated store where the platform has one. */38fun createPlatformWebViewService(39    http: HttpService,40    cookieJar: eu.friedcutlet.yokan.services.http.cookies.CookieJar,41    files: eu.friedcutlet.yokan.services.files.LocalFileService,42    scope: kotlinx.coroutines.CoroutineScope? = null,43): WebViewService = ProfileWebViewService(cookieJar, scope) {44    createSharedPlatformWebViewService(http, cookieJar, files)45}4647internal expect fun createSharedPlatformWebViewService(48    http: HttpService,49    cookieJar: eu.friedcutlet.yokan.services.http.cookies.CookieJar,50    files: eu.friedcutlet.yokan.services.files.LocalFileService,51): WebViewService52

Search chapters, reference and source filenames.