refactor: remove redundant clones in WebView and download handling (#1646)

* refactor: remove redundant clones in WebView and download handling

* Update .changes/cleanup-redundant-clone.md

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>

---------

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>
This commit is contained in:
Tunglies
2026-01-04 15:28:31 +08:00
committed by GitHub
parent 7b77322f88
commit 51d06d0cec
5 changed files with 10 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"wry": patch
---
Remove redundant clones in WebView and download handling. No user facing changes.

View File

@@ -2386,7 +2386,7 @@ impl WebViewExtMacOS for WebView {
}
fn ns_window(&self) -> Retained<NSWindow> {
self.webview.webview.window().unwrap().clone()
self.webview.webview.window().unwrap()
}
fn reparent(&self, window: *mut NSWindow) -> Result<()> {

View File

@@ -282,7 +282,7 @@ extern "C" fn start_task(
.map_err(|_e| crate::Error::CustomProtocolTaskInvalid)?;
check_webview_id_valid(webview_id)?;
check_task_is_valid(&webview, task_key, task_uuid.clone())?;
check_task_is_valid(&webview, task_key, task_uuid)?;
objc2::exception::catch(AssertUnwindSafe(|| {
task.didFinish();

View File

@@ -74,7 +74,7 @@ pub(crate) fn download_policy(
let started_fn = &this.ivars().started;
if let Some(started_fn) = started_fn {
let mut started_fn = started_fn.borrow_mut();
match started_fn(url.to_string().to_string(), &mut download_destination) {
match started_fn(url.to_string(), &mut download_destination) {
true => {
let path = NSString::from_str(&download_destination.display().to_string());
let ns_url = NSURL::fileURLWithPath_isDirectory(&path, false);

View File

@@ -570,7 +570,7 @@ impl InnerWebView {
id: webview_id,
mtm,
webview: webview.clone(),
manager: manager.clone(),
manager,
ns_view: ns_view.retain(),
data_store,
pending_scripts,
@@ -629,7 +629,7 @@ r#"Object.defineProperty(window, 'ipc', {
NSAutoresizingMaskOptions::ViewHeightSizable
| NSAutoresizingMaskOptions::ViewWidthSizable,
);
parent_view.addSubview(&webview.clone());
parent_view.addSubview(&webview);
// Tell the webview receive keyboard events in the window.
// See https://github.com/tauri-apps/wry/issues/739