diff --git a/wrywebview/src/main/kotlin/io/github/kdroidfilter/webview/wry/WryWebViewPanel.kt b/wrywebview/src/main/kotlin/io/github/kdroidfilter/webview/wry/WryWebViewPanel.kt index 07a7e58..c8bd768 100644 --- a/wrywebview/src/main/kotlin/io/github/kdroidfilter/webview/wry/WryWebViewPanel.kt +++ b/wrywebview/src/main/kotlin/io/github/kdroidfilter/webview/wry/WryWebViewPanel.kt @@ -273,6 +273,17 @@ class WryWebViewPanel( } ?: emptyList() } + fun getCookies(): List { + return webviewId?.let { + try { + NativeBindings.getCookies(it) + } catch (e: Exception) { + log("getCookies failed: ${e.message}") + emptyList() + } + } ?: emptyList() + } + fun clearCookiesForUrl(url: String) { val action = { webviewId?.let { NativeBindings.clearCookiesForUrl(it, url) } } if (SwingUtilities.isEventDispatchThread()) { @@ -792,6 +803,10 @@ private object NativeBindings { return io.github.kdroidfilter.webview.wry.getCookiesForUrl(id, url) } + fun getCookies(id: ULong): List { + return io.github.kdroidfilter.webview.wry.getCookies(id) + } + fun clearCookiesForUrl(id: ULong, url: String) { io.github.kdroidfilter.webview.wry.clearCookiesForUrl(id, url) } diff --git a/wrywebview/src/main/rust/lib.rs b/wrywebview/src/main/rust/lib.rs index 6653810..58c0ba4 100644 --- a/wrywebview/src/main/rust/lib.rs +++ b/wrywebview/src/main/rust/lib.rs @@ -763,6 +763,25 @@ pub fn drain_ipc_messages(id: u64) -> Result, WebViewError> { // Cookies // ============================================================================ +fn get_cookies_inner(id: u64) -> Result, WebViewError> { + wry_log!("[wrywebview] get_cookies id={}", id); + with_webview(id, |webview| { + let cookies = webview.cookies().map_err(WebViewError::from)?; + Ok(cookies.iter().map(cookie_record_from).collect()) + }) +} + +#[uniffi::export] +pub fn get_cookies(id: u64) -> Result, WebViewError> { + #[cfg(target_os = "linux")] + { + return run_on_gtk_thread(move || get_cookies_inner(id)); + } + + #[cfg(not(target_os = "linux"))] + run_on_main_thread(move || get_cookies_inner(id)) +} + fn get_cookies_for_url_inner(id: u64, url: String) -> Result, WebViewError> { wry_log!("[wrywebview] get_cookies_for_url id={} url={}", id, url); with_webview(id, |webview| {