From f460570b4423708fb3b5ab1e1213d889a4d7a9b5 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 26 Sep 2026 15:53:40 -0300 Subject: [PATCH] chore: fmt --- examples/api/src-tauri/src/lib.rs | 11 ++-- plugins/barcode-scanner/src/lib.rs | 1 - plugins/cli/src/parser.rs | 12 ++--- plugins/deep-link/src/config.rs | 11 ++-- plugins/deep-link/src/lib.rs | 13 +++-- plugins/dialog/src/commands.rs | 33 ++++++------ plugins/fs/src/android.rs | 8 +-- plugins/fs/src/file_path.rs | 14 +++--- plugins/http/src/commands.rs | 19 +++---- .../src/platform_impl/linux.rs | 6 +-- plugins/store/src/lib.rs | 7 +-- plugins/stronghold/src/lib.rs | 9 ++-- plugins/updater/src/updater.rs | 50 ++++++++++--------- 13 files changed, 101 insertions(+), 93 deletions(-) diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 2cb8d927d..5d51ba5bd 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -205,10 +205,11 @@ pub fn run() { app.run(move |_app_handle, _event| { #[cfg(desktop)] if let RunEvent::ExitRequested { code, api, .. } = &_event - && code.is_none() { - // Keep the event loop running even if all windows are closed - // This allow us to catch system tray events when there is no window - api.prevent_exit(); - } + && code.is_none() + { + // Keep the event loop running even if all windows are closed + // This allow us to catch system tray events when there is no window + api.prevent_exit(); + } }) } diff --git a/plugins/barcode-scanner/src/lib.rs b/plugins/barcode-scanner/src/lib.rs index b84a7b60a..5ca9d9751 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}, }; - mod error; mod models; diff --git a/plugins/cli/src/parser.rs b/plugins/cli/src/parser.rs index 1c66adb52..ed94f0858 100644 --- a/plugins/cli/src/parser.rs +++ b/plugins/cli/src/parser.rs @@ -139,12 +139,12 @@ fn get_matches_internal(config: &Config, matches: &ArgMatches) -> Matches { .subcommands .as_ref() .and_then(|s| s.get(subcommand_name)) - { - cli_matches.set_subcommand( - subcommand_name.to_string(), - get_matches_internal(subcommand_config, subcommand_matches), - ); - } + { + cli_matches.set_subcommand( + subcommand_name.to_string(), + get_matches_internal(subcommand_config, subcommand_matches), + ); + } cli_matches } diff --git a/plugins/deep-link/src/config.rs b/plugins/deep-link/src/config.rs index 94aba9092..e4465719b 100644 --- a/plugins/deep-link/src/config.rs +++ b/plugins/deep-link/src/config.rs @@ -71,11 +71,12 @@ where { let opt = Option::::deserialize(deserializer)?; if let Some(ref host) = opt - && let Some((scheme, _)) = host.split_once("://") { - return Err(serde::de::Error::custom(format!( - "host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix" - ))); - } + && let Some((scheme, _)) = host.split_once("://") + { + return Err(serde::de::Error::custom(format!( + "host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix" + ))); + } Ok(opt) } diff --git a/plugins/deep-link/src/lib.rs b/plugins/deep-link/src/lib.rs index 1b7ca9e1d..13b323711 100644 --- a/plugins/deep-link/src/lib.rs +++ b/plugins/deep-link/src/lib.rs @@ -65,10 +65,10 @@ fn init_deep_link( }, )?; - return Ok(DeepLink { + Ok(DeepLink { app: app.clone(), plugin_handle: handle, - }); + }) } #[cfg(target_os = "ios")] @@ -417,9 +417,10 @@ mod imp { if mimeapps_path.exists() { let mut mimeapps = ini::Ini::load_from_file(&mimeapps_path)?; if let Some(section) = mimeapps.section_mut(Some("Default Applications")) - && section.get(&mime_type).unwrap_or_default() == file_name { - section.remove(&mime_type); - } + && section.get(&mime_type).unwrap_or_default() == file_name + { + section.remove(&mime_type); + } mimeapps.write_to_file(&mimeapps_path)?; } @@ -559,8 +560,6 @@ impl DeepLink { /// /// Use `get_current` on app load to check whether your app was started via a deep link. pub fn on_open_url(&self, f: F) -> EventId { - - self.app.listen("deep-link://new-url", move |event| { if let Ok(urls) = serde_json::from_str(event.payload()) { f(OpenUrlEvent { diff --git a/plugins/dialog/src/commands.rs b/plugins/dialog/src/commands.rs index 1411f909c..0117fefee 100644 --- a/plugins/dialog/src/commands.rs +++ b/plugins/dialog/src/commands.rs @@ -172,12 +172,13 @@ pub(crate) async fn open( } else { let folder = dialog_builder.blocking_pick_folder(); if let Some(folder) = &folder - && let Ok(path) = folder.clone().into_path() { - if let Some(s) = window.try_fs_scope() { - s.allow_directory(&path, options.recursive)?; - } - tauri_scope.allow_directory(&path, options.directory)?; + && let Ok(path) = folder.clone().into_path() + { + if let Some(s) = window.try_fs_scope() { + s.allow_directory(&path, options.recursive)?; } + tauri_scope.allow_directory(&path, options.directory)?; + } OpenResponse::Folder(folder.map(|p| p.simplified())) } } @@ -204,12 +205,13 @@ pub(crate) async fn open( let file = dialog_builder.blocking_pick_file(); if let Some(file) = &file - && let Ok(path) = file.clone().into_path() { - if let Some(s) = window.try_fs_scope() { - s.allow_file(&path)?; - } - tauri_scope.allow_file(&path)?; + && let Ok(path) = file.clone().into_path() + { + if let Some(s) = window.try_fs_scope() { + s.allow_file(&path)?; } + tauri_scope.allow_file(&path)?; + } OpenResponse::File(file.map(|f| f.simplified())) }; Ok(res) @@ -245,12 +247,13 @@ pub(crate) async fn save( let path = dialog_builder.blocking_save_file(); if let Some(p) = &path - && let Ok(path) = p.clone().into_path() { - if let Some(s) = window.try_fs_scope() { - s.allow_file(&path)?; - } - tauri_scope.allow_file(&path)?; + && let Ok(path) = p.clone().into_path() + { + if let Some(s) = window.try_fs_scope() { + s.allow_file(&path)?; } + tauri_scope.allow_file(&path)?; + } Ok(path.map(|p| p.simplified())) } diff --git a/plugins/fs/src/android.rs b/plugins/fs/src/android.rs index 971c42811..b9a829b95 100644 --- a/plugins/fs/src/android.rs +++ b/plugins/fs/src/android.rs @@ -42,9 +42,7 @@ impl Fs { match path.into() { FilePath::Url(u) => self .resolve_content_uri(u.to_string(), opts.android_mode()) - .map_err(|e| { - std::io::Error::other(format!("failed to open file: {e}")) - }), + .map_err(|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 // we must resolve that file with the Android API @@ -52,9 +50,7 @@ impl Fs { .is_ok() { self.resolve_content_uri(p.to_string_lossy(), opts.android_mode()) - .map_err(|e| { - std::io::Error::other(format!("failed to open file: {e}")) - }) + .map_err(|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/file_path.rs b/plugins/fs/src/file_path.rs index 7252b0d3a..86c2aa377 100644 --- a/plugins/fs/src/file_path.rs +++ b/plugins/fs/src/file_path.rs @@ -191,9 +191,10 @@ impl FromStr for FilePath { type Err = Infallible; fn from_str(s: &str) -> std::result::Result { if let Ok(url) = url::Url::from_str(s) - && url.scheme().len() != 1 { - return Ok(Self::Url(url)); - } + && url.scheme().len() != 1 + { + return Ok(Self::Url(url)); + } Ok(Self::Path(PathBuf::from(s))) } } @@ -202,9 +203,10 @@ impl FromStr for SafeFilePath { type Err = Error; fn from_str(s: &str) -> Result { if let Ok(url) = url::Url::from_str(s) - && url.scheme().len() != 1 { - return Ok(Self::Url(url)); - } + && url.scheme().len() != 1 + { + return Ok(Self::Url(url)); + } SafePathBuf::new(s.into()) .map(SafeFilePath::Path) diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index e6c4d48db..d4775c48f 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -349,15 +349,16 @@ pub async fn fetch( // ensure we have an Origin header set if (cfg!(not(feature = "unsafe-headers")) || !headers.contains_key(header::ORIGIN)) - && let Ok(url) = webview.url() { - // The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null" - let origin = if url.scheme() == "tauri" { - "tauri://localhost".to_string() - } else { - url.origin().ascii_serialization() - }; - headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?); - } + && let Ok(url) = webview.url() + { + // The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null" + let origin = if url.scheme() == "tauri" { + "tauri://localhost".to_string() + } else { + url.origin().ascii_serialization() + }; + headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?); + } // In case empty origin is passed, remove it. Some services do not like Origin header // so this way we can remove it in explicit way. The default behaviour is still to set it diff --git a/plugins/single-instance/src/platform_impl/linux.rs b/plugins/single-instance/src/platform_impl/linux.rs index 0cc7e8371..107f3e743 100644 --- a/plugins/single-instance/src/platform_impl/linux.rs +++ b/plugins/single-instance/src/platform_impl/linux.rs @@ -105,7 +105,7 @@ pub fn destroy>(manager: &M) { && let Some(dbus_name) = manager .try_state::() .and_then(|name| WellKnownName::try_from(name.0.clone()).ok()) - { - let _ = connection.0.release_name(dbus_name); - } + { + let _ = connection.0.release_name(dbus_name); + } } diff --git a/plugins/store/src/lib.rs b/plugins/store/src/lib.rs index 3c472accf..6f6dc0bbd 100644 --- a/plugins/store/src/lib.rs +++ b/plugins/store/src/lib.rs @@ -471,9 +471,10 @@ impl Builder { let stores = collection.stores.read().unwrap(); for (path, rid) in stores.iter() { if let Ok(store) = app_handle.resources_table().get::>(*rid) - && let Err(err) = store.save() { - tracing::error!("failed to save store {path:?} with error {err:?}"); - } + && let Err(err) = store.save() + { + tracing::error!("failed to save store {path:?} with error {err:?}"); + } } } }) diff --git a/plugins/stronghold/src/lib.rs b/plugins/stronghold/src/lib.rs index 4c98b664c..01fb9c54d 100644 --- a/plugins/stronghold/src/lib.rs +++ b/plugins/stronghold/src/lib.rs @@ -271,10 +271,11 @@ async fn destroy( ) -> Result<()> { let mut collection = collection.0.lock().unwrap(); if let Some(stronghold) = collection.remove(&snapshot_path) - && let Err(e) = stronghold.save() { - collection.insert(snapshot_path, stronghold); - return Err(e); - } + && let Err(e) = stronghold.save() + { + collection.insert(snapshot_path, stronghold); + return Err(e); + } Ok(()) } diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 8fc650356..d46861070 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -11,7 +11,6 @@ use std::{ time::Duration, }; - use base64::Engine; use futures_util::StreamExt; use http::{HeaderName, header::ACCEPT}; @@ -1187,15 +1186,16 @@ impl Update { let mut archive = tar::Archive::new(decoder); for mut entry in archive.entries()?.flatten() { if let Ok(path) = entry.path() - && path.extension() == Some(OsStr::new("AppImage")) { - // if something went wrong during the extraction, we should restore previous app - if let Err(err) = entry.unpack(&self.extract_path) { - std::fs::rename(tmp_app_image, &self.extract_path)?; - return Err(err.into()); - } - // early finish we have everything we need here - return Ok(()); + && path.extension() == Some(OsStr::new("AppImage")) + { + // if something went wrong during the extraction, we should restore previous app + if let Err(err) = entry.unpack(&self.extract_path) { + std::fs::rename(tmp_app_image, &self.extract_path)?; + return Err(err.into()); } + // early finish we have everything we need here + return Ok(()); + } } // if we have not returned early we should restore the backup std::fs::rename(tmp_app_image, &self.extract_path)?; @@ -1289,17 +1289,19 @@ impl Update { .arg(install_arg) .arg(pkg_path) .status() - && status.success() { - log::debug!("installed {pkg_path:?} with pkexec"); - return Ok(()); - } + && status.success() + { + log::debug!("installed {pkg_path:?} with pkexec"); + return Ok(()); + } // 2. Try zenity or kdialog for a graphical sudo experience if let Ok(password) = self.get_password_graphically() - && self.install_with_sudo(pkg_path, &password, install_cmd, install_arg)? { - log::debug!("installed {pkg_path:?} with GUI sudo"); - return Ok(()); - } + && self.install_with_sudo(pkg_path, &password, install_cmd, install_arg)? + { + log::debug!("installed {pkg_path:?} with GUI sudo"); + return Ok(()); + } // 3. Final fallback: terminal sudo let status = std::process::Command::new("sudo") @@ -1327,9 +1329,10 @@ impl Update { .output(); if let Ok(output) = zenity_result - && output.status.success() { - return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()); - } + && output.status.success() + { + return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()); + } // Fall back to kdialog if zenity fails or isn't available let kdialog_result = std::process::Command::new("kdialog") @@ -1337,9 +1340,10 @@ impl Update { .output(); if let Ok(output) = kdialog_result - && output.status.success() { - return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()); - } + && output.status.success() + { + return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()); + } Err(Error::AuthenticationFailed) }