Skip to content

Commit

Permalink
feat(macos): Add with_data_store_identifier to WebviewBuilder (ta…
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored Nov 28, 2024
1 parent 53f8086 commit 18bd639
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/data-store-identifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": "minor:feat"
"tauri-runtime": "minor:feat"
"tauri-runtime-wry": "minor:feat"
---

Add `WebviewWindowBuilder/WebviewBuilder::data_store_identifier` on macOS.
9 changes: 9 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use tao::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
use webview2_com::FocusChangedEventHandler;
#[cfg(windows)]
use windows::Win32::{Foundation::HWND, System::WinRT::EventRegistrationToken};
#[cfg(any(target_os = "macos", target_os = "ios"))]
use wry::WebViewBuilderExtDarwin;
#[cfg(windows)]
use wry::WebViewBuilderExtWindows;

Expand Down Expand Up @@ -4351,6 +4353,13 @@ fn create_webview<T: UserEvent>(
}
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
{
if let Some(data_store_identifier) = &webview_attributes.data_store_identifier {
webview_builder = webview_builder.with_data_store_identifier(*data_store_identifier);
}
}

webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
kind,
window_id.clone(),
Expand Down
2 changes: 2 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub struct WebviewAttributes {
pub zoom_hotkeys_enabled: bool,
pub browser_extensions_enabled: bool,
pub extensions_path: Option<PathBuf>,
pub data_store_identifier: Option<[u8; 16]>,
pub use_https_scheme: bool,
pub devtools: Option<bool>,
pub background_color: Option<Color>,
Expand Down Expand Up @@ -273,6 +274,7 @@ impl WebviewAttributes {
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
data_store_identifier: None,
extensions_path: None,
use_https_scheme: false,
devtools: None,
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,18 @@ fn main() {
self
}

/// Initialize the WebView with a custom data store identifier.
/// Can be used as a replacement for data_directory not being available in WKWebView.
///
/// - **macOS / iOS**: Available on macOS >= 14 and iOS >= 17
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg_attr(docsrs, doc(any(target_os = "macos", target_os = "ios")))]
#[must_use]
pub fn data_store_identifier(mut self, data_store_identifier: [u8; 16]) -> Self {
self.webview_attributes.data_store_identifier = Some(data_store_identifier);
self
}

/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
///
/// ## Note
Expand Down
14 changes: 14 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,20 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
self
}

/// Initialize the WebView with a custom data store identifier.
/// Can be used as a replacement for data_directory not being available in WKWebView.
///
/// - **macOS / iOS**: Available on macOS >= 14 and iOS >= 17
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg_attr(docsrs, doc(any(target_os = "macos", target_os = "ios")))]
#[must_use]
pub fn data_store_identifier(mut self, data_store_identifier: [u8; 16]) -> Self {
self.webview_builder = self
.webview_builder
.data_store_identifier(data_store_identifier);
self
}

/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
///
/// ## Note
Expand Down

0 comments on commit 18bd639

Please sign in to comment.