Skip to content

Commit 1743e7f

Browse files
authored
fix(macos): new_window_req_handler crashing when using custom data store (#1608)
1 parent 4b44ebb commit 1743e7f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wry": patch
3+
---
4+
5+
Fix new_window_req_handler craashing when creating new window for webview that has a custom data_store_identifier.

src/wkwebview/mod.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,25 @@ impl InnerWebView {
225225
#[cfg(target_os = "ios")]
226226
let custom_data_store_available = os_major_version >= 17;
227227

228-
let data_store = match (
229-
attributes.incognito,
230-
custom_data_store_available,
231-
pl_attrs.data_store_identifier,
232-
) {
233-
(true, _, _) => WKWebsiteDataStore::nonPersistentDataStore(mtm),
234-
// if data_store_identifier is given and custom data stores are available, use custom store
235-
(false, true, Some(data_store)) => {
236-
let identifier = NSUUID::from_bytes(data_store);
237-
WKWebsiteDataStore::dataStoreForIdentifier(&identifier, mtm)
238-
}
239-
// default data store
240-
_ => WKWebsiteDataStore::defaultDataStore(mtm),
228+
let data_store = if using_existing_config {
229+
config.websiteDataStore()
230+
} else {
231+
let data_store = match (
232+
attributes.incognito,
233+
custom_data_store_available,
234+
pl_attrs.data_store_identifier,
235+
) {
236+
(true, _, _) => WKWebsiteDataStore::nonPersistentDataStore(mtm),
237+
// if data_store_identifier is given and custom data stores are available, use custom store
238+
(false, true, Some(data_store)) => {
239+
let identifier = NSUUID::from_bytes(data_store);
240+
WKWebsiteDataStore::dataStoreForIdentifier(&identifier, mtm)
241+
}
242+
// default data store
243+
_ => WKWebsiteDataStore::defaultDataStore(mtm),
244+
};
245+
config.setWebsiteDataStore(&data_store);
246+
data_store
241247
};
242248

243249
// Register Custom Protocols
@@ -302,7 +308,6 @@ impl InnerWebView {
302308
custom_protocol_task_ids: Default::default(),
303309
});
304310

305-
config.setWebsiteDataStore(&data_store);
306311
let _preference = config.preferences();
307312
let _yes = NSNumber::numberWithBool(true);
308313

0 commit comments

Comments
 (0)