Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsheen committed Jul 11, 2024
1 parent e8d2c6e commit ab9804b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/wkwebview/class/document_title_changed_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Drop for DocumentTitleChangedObserver {
self
.ivars()
.object
.removeObserver_forKeyPath(&self, &NSString::from_str("title"));
.removeObserver_forKeyPath(self, &NSString::from_str("title"));
}
}
}
10 changes: 5 additions & 5 deletions src/wkwebview/class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

pub mod wry_web_view;
pub mod wry_web_view_delegate;
pub mod document_title_changed_observer;
pub mod wry_navigation_delegate;
pub mod url_scheme_handler;
pub mod wry_download_delegate;
pub mod wry_web_view_ui_delegate;
pub mod wry_navigation_delegate;
pub mod wry_web_view;
pub mod wry_web_view_delegate;
pub mod wry_web_view_parent;
pub mod url_scheme_handler;
pub mod wry_web_view_ui_delegate;
9 changes: 4 additions & 5 deletions src/wkwebview/class/url_scheme_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn create(name: &str) -> &AnyClass {
unsafe {
let scheme_name = format!("{}URLSchemeHandler", name);
let cls = ClassBuilder::new(&scheme_name, NSObject::class());
let cls = match cls {
match cls {
Some(mut cls) => {
cls.add_ivar::<*mut c_void>("function");
cls.add_ivar::<u32>("webview_id");
Expand All @@ -40,13 +40,12 @@ pub fn create(name: &str) -> &AnyClass {
cls.register()
}
None => AnyClass::get(&scheme_name).expect("Failed to get the class definition"),
};
cls
}
}
}

// Task handler for custom protocol
extern "C" fn start_task<'a>(
extern "C" fn start_task(
this: &AnyObject,
_sel: objc2::runtime::Sel,
webview: *mut WryWebView,
Expand All @@ -61,7 +60,7 @@ extern "C" fn start_task<'a>(
let task_uuid = (*webview).add_custom_task_key(task_key);

let ivar = this.class().instance_variable("webview_id").unwrap();
let webview_id: u32 = ivar.load::<u32>(this).clone();
let webview_id: u32 = *ivar.load::<u32>(this);
let ivar = this.class().instance_variable("function").unwrap();
let function: &*mut c_void = ivar.load(this);
if !function.is_null() {
Expand Down
4 changes: 2 additions & 2 deletions src/wkwebview/class/wry_download_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ impl WryDownloadDelegate {

impl Drop for WryDownloadDelegate {
fn drop(&mut self) {
if self.ivars().started != null_mut() {
if !self.ivars().started.is_null() {
unsafe {
drop(Box::from_raw(self.ivars().started));
}
}
if self.ivars().completed != null_mut() {
if !self.ivars().completed.is_null() {
unsafe {
drop(Box::from_raw(self.ivars().completed));
}
Expand Down
30 changes: 17 additions & 13 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,13 @@ impl InnerWebView {

let config_unwind_safe = AssertUnwindSafe(&config);
let handler_unwind_safe = AssertUnwindSafe(handler);
if catch_unwind(|| {
let set_result = catch_unwind(|| {
config_unwind_safe.setURLSchemeHandler_forURLScheme(
Some(&*(handler_unwind_safe.cast::<ProtocolObject<dyn WKURLSchemeHandler>>())),
&NSString::from_str(&name),
);
})
.is_err()
{
});
if set_result.is_err() {
return Err(Error::UrlSchemeRegisterError(name));
}
}
Expand Down Expand Up @@ -261,7 +260,8 @@ impl InnerWebView {
}
};

let proxies: Retained<NSArray<NSObject>> = NSArray::arrayWithObject(&*proxy_config);
let proxies: Retained<objc2_foundation::NSArray<NSObject>> =
objc2_foundation::NSArray::arrayWithObject(&*proxy_config);
data_store.setValue_forKey(Some(&proxies), ns_string!("proxyConfigurations"));
}

Expand Down Expand Up @@ -375,7 +375,7 @@ impl InnerWebView {
if attributes.devtools {
let has_inspectable_property: bool =
NSObject::respondsToSelector(&webview, objc2::sel!(setInspectable:));
if has_inspectable_property == true {
if has_inspectable_property {
webview.setInspectable(true);
}
// this cannot be on an `else` statement, it does not work on macOS :(
Expand Down Expand Up @@ -433,7 +433,7 @@ impl InnerWebView {

let ui_delegate: Retained<WryWebViewUIDelegate> = WryWebViewUIDelegate::new(mtm);
let proto_ui_delegate = ProtocolObject::from_ref(ui_delegate.as_ref());
webview.setUIDelegate(Some(&proto_ui_delegate));
webview.setUIDelegate(Some(proto_ui_delegate));

// ns window is required for the print operation
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -538,7 +538,7 @@ r#"Object.defineProperty(window, 'ipc', {

let mut result = String::new();

if val != null_mut() {
if !val.is_null() {
let json_ns_data = NSJSONSerialization::dataWithJSONObject_options_error(
&*val,
objc2_foundation::NSJSONWritingOptions::NSJSONWritingFragmentsAllowed,
Expand All @@ -561,14 +561,18 @@ r#"Object.defineProperty(window, 'ipc', {
.evaluateJavaScript_completionHandler(&NSString::from_str(js), Some(&handler));
} else {
#[cfg(feature = "tracing")]
let handler = block2::RcBlock::new(move |val: *mut AnyObject, _err: *mut NSError| {
span.lock().unwrap().take();
})
.copy();
let handler = Some(
block2::RcBlock::new(move |_val: *mut AnyObject, _err: *mut NSError| {
span.lock().unwrap().take();
})
.copy(),
);
#[cfg(not(feature = "tracing"))]
let handler: Option<block2::RcBlock<dyn Fn(*mut AnyObject, *mut NSError)>> = None;

self
.webview
.evaluateJavaScript_completionHandler(&NSString::from_str(js), None);
.evaluateJavaScript_completionHandler(&NSString::from_str(js), handler.as_deref());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wkwebview/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn did_commit_navigation(
let mut pending_scripts = this.ivars().pending_scripts.lock().unwrap();
if let Some(scripts) = &*pending_scripts {
for script in scripts {
webview.evaluateJavaScript_completionHandler(&NSString::from_str(&script), None);
webview.evaluateJavaScript_completionHandler(&NSString::from_str(script), None);
}
*pending_scripts = None;
}
Expand Down

0 comments on commit ab9804b

Please sign in to comment.