From 9c3fcbf815fcc06be180c627cbcd6b2650734a40 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 13 Sep 2026 13:20:34 +0200 Subject: [PATCH] Fix the Clippy findings in the Linux-only code paths --- runtime/src/environment.rs | 8 ++-- runtime/src/global_shortcuts.rs | 66 +++++++++++++++++---------------- runtime/src/secret.rs | 8 ++-- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/runtime/src/environment.rs b/runtime/src/environment.rs index 6c49c8de..09844573 100644 --- a/runtime/src/environment.rs +++ b/runtime/src/environment.rs @@ -504,10 +504,10 @@ fn read_locale_from_environment() -> Option<(String, &'static str)> { } for key in ["LC_ALL", "LC_MESSAGES", "LANG"] { - if let Ok(value) = env::var(key) { - if let Some(locale) = normalize_locale_tag(&value) { - return Some((locale, key)); - } + if let Ok(value) = env::var(key) + && let Some(locale) = normalize_locale_tag(&value) + { + return Some((locale, key)); } } diff --git a/runtime/src/global_shortcuts.rs b/runtime/src/global_shortcuts.rs index bb62e993..e0effe05 100644 --- a/runtime/src/global_shortcuts.rs +++ b/runtime/src/global_shortcuts.rs @@ -149,6 +149,12 @@ struct ShortcutManager { /// Stores the backend-specific resources required by an active shortcut. enum ActiveBinding { /// Stores a shortcut registered through the Tauri plugin. + /// + /// Never constructed on Linux: registration there goes through the XDG portal and falls back + /// to the focused window, so nothing ever reaches the Tauri plugin. The variant stays all the + /// same, because the code which releases, suspends, and restores bindings is shared across + /// platforms and would otherwise have to be cut in two for one unreachable case. + #[cfg_attr(target_os = "linux", allow(dead_code))] Tauri { /// Contains the registered shortcut in Tauri syntax. shortcut: String, @@ -247,40 +253,38 @@ pub async fn register( } #[cfg(target_os = "linux")] - { - match prepare_portal_binding(&request, event_sender.clone()).await { - Ok(new_binding) => { - let effective_display_name = new_binding.effective_display_name(); - replace_portal_binding(&app_handle, &mut manager, request.id, new_binding).await; - info!(Source = "XDG portal"; "Global shortcut '{}' is active through the desktop portal.", request.id); - return ShortcutResponse::success(ShortcutBackend::Portal, effective_display_name); - }, + match prepare_portal_binding(&request, event_sender.clone()).await { + Ok(new_binding) => { + let effective_display_name = new_binding.effective_display_name(); + replace_portal_binding(&app_handle, &mut manager, request.id, new_binding).await; + info!(Source = "XDG portal"; "Global shortcut '{}' is active through the desktop portal.", request.id); + ShortcutResponse::success(ShortcutBackend::Portal, effective_display_name) + }, - Err(error) => { - let current_backend = manager.bindings.get(&request.id).map(ActiveBinding::backend); - if may_fallback_to_local(error.kind, current_backend) { - warn!(Source = "XDG portal"; "Global shortcut registration failed; using the focused-window fallback: {}", error.message); + Err(error) => { + let current_backend = manager.bindings.get(&request.id).map(ActiveBinding::backend); + if may_fallback_to_local(error.kind, current_backend) { + warn!(Source = "XDG portal"; "Global shortcut registration failed; using the focused-window fallback: {}", error.message); - if let Some(old_binding) = manager.bindings.remove(&request.id) { - close_binding(&app_handle, request.id, old_binding).await; - } - - manager.bindings.insert(request.id, ActiveBinding::Local { shortcut: request.shortcut.clone() }); - return ShortcutResponse::success(ShortcutBackend::Local, request.shortcut); - } else { - let cancelled = error.kind == PortalFailureKind::Cancelled; - if cancelled { - warn!(Source = "XDG portal"; "Global shortcut configuration was cancelled by the user; preserving the active portal binding."); - } else if error.kind == PortalFailureKind::Denied { - warn!(Source = "XDG portal"; "Global shortcut permission was denied; preserving the active portal binding: {}", error.message); - } else { - error!(Source = "XDG portal"; "Global shortcut registration failed; preserving the active portal binding: {}", error.message); - } - - return ShortcutResponse::error(error.message, ShortcutBackend::Portal, cancelled); + if let Some(old_binding) = manager.bindings.remove(&request.id) { + close_binding(&app_handle, request.id, old_binding).await; } - }, - } + + manager.bindings.insert(request.id, ActiveBinding::Local { shortcut: request.shortcut.clone() }); + ShortcutResponse::success(ShortcutBackend::Local, request.shortcut) + } else { + let cancelled = error.kind == PortalFailureKind::Cancelled; + if cancelled { + warn!(Source = "XDG portal"; "Global shortcut configuration was cancelled by the user; preserving the active portal binding."); + } else if error.kind == PortalFailureKind::Denied { + warn!(Source = "XDG portal"; "Global shortcut permission was denied; preserving the active portal binding: {}", error.message); + } else { + error!(Source = "XDG portal"; "Global shortcut registration failed; preserving the active portal binding: {}", error.message); + } + + ShortcutResponse::error(error.message, ShortcutBackend::Portal, cancelled) + } + }, } #[cfg(not(target_os = "linux"))] diff --git a/runtime/src/secret.rs b/runtime/src/secret.rs index a6eaab86..cca69c0b 100644 --- a/runtime/src/secret.rs +++ b/runtime/src/secret.rs @@ -23,10 +23,10 @@ fn issue_code(error: &KeyringError) -> SecretStoreIssueCode { } #[cfg(target_os = "linux")] - if let KeyringError::PlatformFailure(error) | KeyringError::NoStorageAccess(error) = error { - if let Some(error) = error.downcast_ref::() { - return secret_service_issue_code(error); - } + if let KeyringError::PlatformFailure(error) | KeyringError::NoStorageAccess(error) = error + && let Some(error) = error.downcast_ref::() + { + return secret_service_issue_code(error); } SecretStoreIssueCode::Unknown