From a433ec09d13c6532f54256608d8e951283d64596 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 26 Sep 2026 15:46:48 -0300 Subject: [PATCH] fix: mobile clippy warnings --- plugins/barcode-scanner/src/lib.rs | 1 - plugins/clipboard-manager/src/lib.rs | 4 +- plugins/fs/src/android.rs | 10 +- plugins/fs/src/commands.rs | 253 +++++++++--------- plugins/fs/src/ios.rs | 4 +- plugins/notification/src/models.rs | 9 +- plugins/opener/src/reveal_item_in_dir.rs | 4 +- plugins/shell/src/lib.rs | 1 + .../examples/vanilla/src-tauri/src/main.rs | 23 +- plugins/updater/src/updater.rs | 7 +- .../updater/tests/app-updater/tests/update.rs | 3 +- .../tests/updater-migration/tests/update.rs | 1 + 12 files changed, 157 insertions(+), 163 deletions(-) diff --git a/plugins/barcode-scanner/src/lib.rs b/plugins/barcode-scanner/src/lib.rs index fb6a89257..b84a7b60a 100644 --- a/plugins/barcode-scanner/src/lib.rs +++ b/plugins/barcode-scanner/src/lib.rs @@ -13,7 +13,6 @@ use tauri::{ plugin::{Builder, PluginHandle, TauriPlugin}, }; -pub use models::*; mod error; mod models; diff --git a/plugins/clipboard-manager/src/lib.rs b/plugins/clipboard-manager/src/lib.rs index d08d77c2c..024f6f593 100644 --- a/plugins/clipboard-manager/src/lib.rs +++ b/plugins/clipboard-manager/src/lib.rs @@ -10,7 +10,7 @@ )] use tauri::{ - Manager, RunEvent, Runtime, + Manager, Runtime, plugin::{Builder, TauriPlugin}, }; @@ -62,7 +62,7 @@ pub fn init() -> TauriPlugin { }) .on_event(|_app, _event| { #[cfg(desktop)] - if let RunEvent::Exit = _event { + if let tauri::RunEvent::Exit = _event { _app.clipboard().cleanup(); } }) diff --git a/plugins/fs/src/android.rs b/plugins/fs/src/android.rs index a914b4d9c..971c42811 100644 --- a/plugins/fs/src/android.rs +++ b/plugins/fs/src/android.rs @@ -43,10 +43,7 @@ impl Fs { FilePath::Url(u) => self .resolve_content_uri(u.to_string(), opts.android_mode()) .map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, - format!("failed to open file: {e}"), - ) + std::io::Error::other(format!("failed to open file: {e}")) }), FilePath::Path(p) => { // tauri::utils::platform::resources_dir() returns a PathBuf with the Android asset URI prefix @@ -56,10 +53,7 @@ impl Fs { { self.resolve_content_uri(p.to_string_lossy(), opts.android_mode()) .map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, - format!("failed to open file: {e}"), - ) + std::io::Error::other(format!("failed to open file: {e}")) }) } else { std::fs::OpenOptions::from(opts).open(p) diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 9065efa7c..dff4e6a9f 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -159,26 +159,26 @@ impl Drop for FileHandle { // Only clean up if we're tracking this resource // If start_accessing_security_scoped_resource was used, it won't be in our tracking // and we shouldn't interfere - if let FilePath::Url(url) = file_path { - if url.scheme() == "file" { - let security_scoped_resources = - self.app_handle.state::(); + if let FilePath::Url(url) = file_path + && url.scheme() == "file" + { + let security_scoped_resources = + self.app_handle.state::(); - // Only clean up if it's not tracked manually - if !security_scoped_resources.is_tracked_manually(url.as_str()) { - log::debug!( - "Stopping accessing security-scoped resource for URL: {url} on drop" - ); - let _ = self - .app_handle - .fs() - .stop_accessing_security_scoped_resource(FilePath::Url(url.clone())); - security_scoped_resources.remove(url.as_str()); - } else { - log::debug!( - "Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)" - ); - } + // Only clean up if it's not tracked manually + if !security_scoped_resources.is_tracked_manually(url.as_str()) { + log::debug!( + "Stopping accessing security-scoped resource for URL: {url} on drop" + ); + let _ = self + .app_handle + .fs() + .stop_accessing_security_scoped_resource(FilePath::Url(url.clone())); + security_scoped_resources.remove(url.as_str()); + } else { + log::debug!( + "Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)" + ); } } } @@ -237,26 +237,24 @@ impl Drop for PathHandle { // Only clean up if we're tracking this resource (i.e., resolve_path started it) // If start_accessing_security_scoped_resource was used, it won't be in our tracking // and we shouldn't interfere - if let FilePath::Url(url) = file_path { - if url.scheme() == "file" { - let security_scoped_resources = - self.app_handle.state::(); + if let FilePath::Url(url) = file_path + && url.scheme() == "file" + { + let security_scoped_resources = + self.app_handle.state::(); - // Only clean up if it's not tracked manually - if !security_scoped_resources.is_tracked_manually(url.as_str()) { - log::debug!( - "Stopping accessing security-scoped resource for URL: {url} on drop" - ); - let _ = self - .app_handle - .fs() - .stop_accessing_security_scoped_resource(FilePath::Url(url.clone())); - security_scoped_resources.remove(url.as_str()); - } else { - log::debug!( - "Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)" - ); - } + // Only clean up if it's not tracked manually + if !security_scoped_resources.is_tracked_manually(url.as_str()) { + log::debug!("Stopping accessing security-scoped resource for URL: {url} on drop"); + let _ = self + .app_handle + .fs() + .stop_accessing_security_scoped_resource(FilePath::Url(url.clone())); + security_scoped_resources.remove(url.as_str()); + } else { + log::debug!( + "Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)" + ); } } } @@ -1280,50 +1278,49 @@ pub fn start_accessing_security_scoped_resource( }; // Only handle file URLs - if let FilePath::Url(url) = &file_path { - if url.scheme() == "file" { - use objc2_foundation::{NSString, NSURL}; + if let FilePath::Url(url) = &file_path + && url.scheme() == "file" + { + use objc2_foundation::{NSString, NSURL}; - let url_nsstring = NSString::from_str(url.as_str()); - let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) }; - if let Some(ns_url) = ns_url { - // Check if already active - let security_scoped_resources = - webview.state::(); - if security_scoped_resources.is_tracked_manually(url.as_str()) { + let url_nsstring = NSString::from_str(url.as_str()); + let ns_url = NSURL::URLWithString(&url_nsstring); + if let Some(ns_url) = ns_url { + // Check if already active + let security_scoped_resources = webview.state::(); + if security_scoped_resources.is_tracked_manually(url.as_str()) { + log::debug!( + "Security-scoped resource already active for URL: {}", + url.as_str() + ); + return Ok(()); + } + + // Start accessing the security-scoped resource + unsafe { + let success = ns_url.startAccessingSecurityScopedResource(); + if success { log::debug!( - "Security-scoped resource already active for URL: {}", + "Started accessing security-scoped resource for URL: {}", url.as_str() ); - return Ok(()); + security_scoped_resources.track_manually(url.as_str().to_string()); + } else { + log::warn!( + "Failed to start accessing security-scoped resource for URL: {}", + url.as_str() + ); + return Err(CommandError::from(format!( + "Failed to start accessing security-scoped resource for URL: {}", + url.as_str() + ))); } - - // Start accessing the security-scoped resource - unsafe { - let success = ns_url.startAccessingSecurityScopedResource(); - if success { - log::debug!( - "Started accessing security-scoped resource for URL: {}", - url.as_str() - ); - security_scoped_resources.track_manually(url.as_str().to_string()); - } else { - log::warn!( - "Failed to start accessing security-scoped resource for URL: {}", - url.as_str() - ); - return Err(CommandError::from(format!( - "Failed to start accessing security-scoped resource for URL: {}", - url.as_str() - ))); - } - } - } else { - return Err(CommandError::from(format!( - "Failed to create NSURL from URL: {}", - url.as_str() - ))); } + } else { + return Err(CommandError::from(format!( + "Failed to create NSURL from URL: {}", + url.as_str() + ))); } } Ok(()) @@ -1352,31 +1349,31 @@ pub fn stop_accessing_security_scoped_resource( }; // Only handle file URLs - if let FilePath::Url(url) = file_path { - if url.scheme() == "file" { - let security_scoped_resources = webview.state::(); + if let FilePath::Url(url) = file_path + && url.scheme() == "file" + { + let security_scoped_resources = webview.state::(); - // Check if it's tracked - if !security_scoped_resources.is_tracked_manually(url.as_str()) { - log::debug!( - "Security-scoped resource not tracked as active for URL: {}", - url.as_str() - ); - return Ok(()); - } - - // Stop accessing the security-scoped resource - webview - .fs() - .stop_accessing_security_scoped_resource(FilePath::Url(url.clone()))?; - - // Remove from tracking - security_scoped_resources.remove(url.as_str()); + // Check if it's tracked + if !security_scoped_resources.is_tracked_manually(url.as_str()) { log::debug!( - "Stopped accessing security-scoped resource for URL: {}", + "Security-scoped resource not tracked as active for URL: {}", url.as_str() ); + return Ok(()); } + + // Stop accessing the security-scoped resource + webview + .fs() + .stop_accessing_security_scoped_resource(FilePath::Url(url.clone()))?; + + // Remove from tracking + security_scoped_resources.remove(url.as_str()); + log::debug!( + "Stopped accessing security-scoped resource for URL: {}", + url.as_str() + ); } Ok(()) } @@ -1518,47 +1515,47 @@ pub fn resolve_path( // On iOS, start accessing security-scoped resource if the path is a file URL // Only if it hasn't been started already via start_accessing_security_scoped_resource #[cfg(target_os = "ios")] - if let SafeFilePath::Url(url) = &path { - if url.scheme() == "file" { - use objc2_foundation::{NSString, NSURL}; + if let SafeFilePath::Url(url) = &path + && url.scheme() == "file" + { + use objc2_foundation::{NSString, NSURL}; - let security_scoped_resources = webview.state::(); + let security_scoped_resources = webview.state::(); - // Check if already active (started via start_accessing_security_scoped_resource) - if !security_scoped_resources.is_tracked_manually(url.as_str()) { - let url_nsstring = NSString::from_str(url.as_str()); - let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) }; - if let Some(ns_url) = ns_url { - // Start accessing the security-scoped resource - // This is required for files outside the app's sandbox (e.g., from file picker) - unsafe { - let success = ns_url.startAccessingSecurityScopedResource(); - if success { - log::debug!( - "Started accessing security-scoped resource for URL: {} (via resolve_path)", - url.as_str() - ); - // Track it so we know to clean it up - security_scoped_resources.track_manually(url.as_str().to_string()); - } else { - log::warn!( - "Failed to start accessing security-scoped resource for URL: {}", - url.as_str() - ); - } + // Check if already active (started via start_accessing_security_scoped_resource) + if !security_scoped_resources.is_tracked_manually(url.as_str()) { + let url_nsstring = NSString::from_str(url.as_str()); + let ns_url = NSURL::URLWithString(&url_nsstring); + if let Some(ns_url) = ns_url { + // Start accessing the security-scoped resource + // This is required for files outside the app's sandbox (e.g., from file picker) + unsafe { + let success = ns_url.startAccessingSecurityScopedResource(); + if success { + log::debug!( + "Started accessing security-scoped resource for URL: {} (via resolve_path)", + url.as_str() + ); + // Track it so we know to clean it up + security_scoped_resources.track_manually(url.as_str().to_string()); + } else { + log::warn!( + "Failed to start accessing security-scoped resource for URL: {}", + url.as_str() + ); } - } else { - log::debug!( - "Failed to create NSURL from URL: {}, ignoring security-scoped resource access request", - url.as_str() - ); } } else { log::debug!( - "Security-scoped resource already active for URL: {} (started via start_accessing_security_scoped_resource), skipping", + "Failed to create NSURL from URL: {}, ignoring security-scoped resource access request", url.as_str() ); } + } else { + log::debug!( + "Security-scoped resource already active for URL: {} (started via start_accessing_security_scoped_resource), skipping", + url.as_str() + ); } } diff --git a/plugins/fs/src/ios.rs b/plugins/fs/src/ios.rs index 7c1fc271b..ff36b8b09 100644 --- a/plugins/fs/src/ios.rs +++ b/plugins/fs/src/ios.rs @@ -47,7 +47,7 @@ impl Fs { // Create NSURL from the URL string // URLWithString may return None for invalid URLs, but file:// URLs should be valid - let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) }; + let ns_url = NSURL::URLWithString(&url_nsstring); if let Some(ns_url) = ns_url { // Start accessing the security-scoped resource // This is required for files outside the app's sandbox (e.g., from file picker) @@ -127,7 +127,7 @@ impl Fs { }; let url_nsstring = NSString::from_str(&url_string); - let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) }; + let ns_url = NSURL::URLWithString(&url_nsstring); if let Some(ns_url) = ns_url { // Stop accessing the security-scoped resource unsafe { diff --git a/plugins/notification/src/models.rs b/plugins/notification/src/models.rs index b146dcb89..bb638f117 100644 --- a/plugins/notification/src/models.rs +++ b/plugins/notification/src/models.rs @@ -725,7 +725,7 @@ mod android { /// /// It maps to the `NotificationManager.IMPORTANCE_*` constants and is serialized as its /// integer value. Only available on Android. - #[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)] + #[derive(Debug, Default, Clone, Copy, Serialize_repr, Deserialize_repr)] #[repr(u8)] pub enum Importance { /// The notifications are not shown. @@ -737,17 +737,12 @@ mod android { /// The notifications are shown and make a sound. /// /// This is the value used when the channel does not define an importance. + #[default] Default = 3, /// The notifications are shown, make a sound and pop up as a heads-up notification. High = 4, } - impl Default for Importance { - fn default() -> Self { - Self::Default - } - } - /// How much of a notification is shown on the lock screen. /// /// It maps to the `Notification.VISIBILITY_*` constants and is serialized as its diff --git a/plugins/opener/src/reveal_item_in_dir.rs b/plugins/opener/src/reveal_item_in_dir.rs index 1b593cf6b..fa63b9508 100644 --- a/plugins/opener/src/reveal_item_in_dir.rs +++ b/plugins/opener/src/reveal_item_in_dir.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; /// /// - **Android / iOS:** Unsupported. pub fn reveal_item_in_dir>(path: P) -> crate::Result<()> { - let path = canonicalize(path.as_ref())?; + let _path = canonicalize(path.as_ref())?; #[cfg(any( windows, @@ -21,7 +21,7 @@ pub fn reveal_item_in_dir>(path: P) -> crate::Result<()> { target_os = "netbsd", target_os = "openbsd" ))] - return imp::reveal_items_in_dir(&[path]); + return imp::reveal_items_in_dir(&[_path]); #[cfg(not(any( windows, diff --git a/plugins/shell/src/lib.rs b/plugins/shell/src/lib.rs index dd5967456..60f881c5f 100644 --- a/plugins/shell/src/lib.rs +++ b/plugins/shell/src/lib.rs @@ -87,6 +87,7 @@ impl Shell { /// See [`crate::open::open`] for how it handles security-related measures. #[cfg(mobile)] #[deprecated(since = "2.1.0", note = "Use tauri-plugin-opener instead.")] + #[allow(deprecated)] pub fn open(&self, path: impl Into, _with: Option) -> Result<()> { self.mobile_plugin_handle .run_mobile_plugin("open", path.into()) diff --git a/plugins/single-instance/examples/vanilla/src-tauri/src/main.rs b/plugins/single-instance/examples/vanilla/src-tauri/src/main.rs index 835857c99..7177806d1 100644 --- a/plugins/single-instance/examples/vanilla/src-tauri/src/main.rs +++ b/plugins/single-instance/examples/vanilla/src-tauri/src/main.rs @@ -8,15 +8,20 @@ )] fn main() { - tauri::Builder::default() - .plugin( - tauri_plugin_single_instance::Builder::new() - .callback(move |app, argv, cwd| { - println!("{}, {argv:?}, {cwd}", app.package_info().name); - }) - .dbus_id("org.Tauri.SIExampleApp".to_owned()) - .build(), - ) + let builder = tauri::Builder::default(); + + // single-instance is only available on desktop + #[cfg(desktop)] + let builder = builder.plugin( + tauri_plugin_single_instance::Builder::new() + .callback(move |app, argv, cwd| { + println!("{}, {argv:?}, {cwd}", app.package_info().name); + }) + .dbus_id("org.Tauri.SIExampleApp".to_owned()) + .build(), + ); + + builder .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 515eb9399..8fc650356 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -5,15 +5,12 @@ use std::{ collections::HashMap, ffi::OsString, - io::Cursor, path::{Path, PathBuf}, str::FromStr, sync::Arc, time::Duration, }; -#[cfg(not(target_os = "macos"))] -use std::ffi::OsStr; use base64::Engine; use futures_util::StreamExt; @@ -26,6 +23,10 @@ use reqwest::{ }; use semver::Version; use serde::{Deserialize, Deserializer, Serialize, de::Error as DeError}; +#[cfg(windows)] +use std::ffi::OsStr; +#[cfg(desktop)] +use std::io::Cursor; use tauri::{ AppHandle, Resource, Runtime, utils::{ diff --git a/plugins/updater/tests/app-updater/tests/update.rs b/plugins/updater/tests/app-updater/tests/update.rs index 6cf13a03e..77273836c 100644 --- a/plugins/updater/tests/app-updater/tests/update.rs +++ b/plugins/updater/tests/app-updater/tests/update.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +#![cfg(any(target_os = "linux", target_os = "macos", windows))] #![allow(dead_code, unused_imports)] use std::{ @@ -376,7 +377,7 @@ fn stage_app_under_test(root_dir: &Path, target: &str, bundle_target: BundleTarg ) }); - return staged; + staged } } diff --git a/plugins/updater/tests/updater-migration/tests/update.rs b/plugins/updater/tests/updater-migration/tests/update.rs index 49f1bc98e..5fa8b010d 100644 --- a/plugins/updater/tests/updater-migration/tests/update.rs +++ b/plugins/updater/tests/updater-migration/tests/update.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +#![cfg(any(target_os = "linux", target_os = "macos", windows))] #![allow(dead_code, unused_imports)] use std::{