Skip to content

Commit 18bd639

Browse files
authored
feat(macos): Add with_data_store_identifier to WebviewBuilder (#11798)
1 parent 53f8086 commit 18bd639

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

.changes/data-store-identifier.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": "minor:feat"
3+
"tauri-runtime": "minor:feat"
4+
"tauri-runtime-wry": "minor:feat"
5+
---
6+
7+
Add `WebviewWindowBuilder/WebviewBuilder::data_store_identifier` on macOS.

crates/tauri-runtime-wry/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ use tao::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
4040
use webview2_com::FocusChangedEventHandler;
4141
#[cfg(windows)]
4242
use windows::Win32::{Foundation::HWND, System::WinRT::EventRegistrationToken};
43+
#[cfg(any(target_os = "macos", target_os = "ios"))]
44+
use wry::WebViewBuilderExtDarwin;
4345
#[cfg(windows)]
4446
use wry::WebViewBuilderExtWindows;
4547

@@ -4351,6 +4353,13 @@ fn create_webview<T: UserEvent>(
43514353
}
43524354
}
43534355

4356+
#[cfg(any(target_os = "macos", target_os = "ios"))]
4357+
{
4358+
if let Some(data_store_identifier) = &webview_attributes.data_store_identifier {
4359+
webview_builder = webview_builder.with_data_store_identifier(*data_store_identifier);
4360+
}
4361+
}
4362+
43544363
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
43554364
kind,
43564365
window_id.clone(),

crates/tauri-runtime/src/webview.rs

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub struct WebviewAttributes {
211211
pub zoom_hotkeys_enabled: bool,
212212
pub browser_extensions_enabled: bool,
213213
pub extensions_path: Option<PathBuf>,
214+
pub data_store_identifier: Option<[u8; 16]>,
214215
pub use_https_scheme: bool,
215216
pub devtools: Option<bool>,
216217
pub background_color: Option<Color>,
@@ -273,6 +274,7 @@ impl WebviewAttributes {
273274
proxy_url: None,
274275
zoom_hotkeys_enabled: false,
275276
browser_extensions_enabled: false,
277+
data_store_identifier: None,
276278
extensions_path: None,
277279
use_https_scheme: false,
278280
devtools: None,

crates/tauri/src/webview/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,18 @@ fn main() {
814814
self
815815
}
816816

817+
/// Initialize the WebView with a custom data store identifier.
818+
/// Can be used as a replacement for data_directory not being available in WKWebView.
819+
///
820+
/// - **macOS / iOS**: Available on macOS >= 14 and iOS >= 17
821+
#[cfg(any(target_os = "macos", target_os = "ios"))]
822+
#[cfg_attr(docsrs, doc(any(target_os = "macos", target_os = "ios")))]
823+
#[must_use]
824+
pub fn data_store_identifier(mut self, data_store_identifier: [u8; 16]) -> Self {
825+
self.webview_attributes.data_store_identifier = Some(data_store_identifier);
826+
self
827+
}
828+
817829
/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
818830
///
819831
/// ## Note

crates/tauri/src/webview/webview_window.rs

+14
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,20 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
918918
self
919919
}
920920

921+
/// Initialize the WebView with a custom data store identifier.
922+
/// Can be used as a replacement for data_directory not being available in WKWebView.
923+
///
924+
/// - **macOS / iOS**: Available on macOS >= 14 and iOS >= 17
925+
#[cfg(any(target_os = "macos", target_os = "ios"))]
926+
#[cfg_attr(docsrs, doc(any(target_os = "macos", target_os = "ios")))]
927+
#[must_use]
928+
pub fn data_store_identifier(mut self, data_store_identifier: [u8; 16]) -> Self {
929+
self.webview_builder = self
930+
.webview_builder
931+
.data_store_identifier(data_store_identifier);
932+
self
933+
}
934+
921935
/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
922936
///
923937
/// ## Note

0 commit comments

Comments
 (0)