From 2fd6927030fa2e2b6f7039f049e462edf87887f5 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 5 Oct 2021 23:17:22 +0200 Subject: [PATCH] fix(core): fix warnings --- espanso/src/cli/daemon/watcher.rs | 2 +- espanso/src/cli/service/macos.rs | 4 ++-- espanso/src/cli/workaround/secure_input.rs | 15 +++++++-------- espanso/src/cli/worker/config.rs | 3 +-- .../engine/process/middleware/matcher/convert.rs | 3 +-- .../engine/process/middleware/render/mod.rs | 2 +- espanso/src/cli/worker/match_cache.rs | 6 +++--- espanso/src/cli/worker/secure_input.rs | 12 ++++++------ espanso/src/exit_code.rs | 1 + espanso/src/path/macos.rs | 4 ++-- 10 files changed, 25 insertions(+), 27 deletions(-) diff --git a/espanso/src/cli/daemon/watcher.rs b/espanso/src/cli/daemon/watcher.rs index 5b039e3..34358d7 100644 --- a/espanso/src/cli/daemon/watcher.rs +++ b/espanso/src/cli/daemon/watcher.rs @@ -128,6 +128,6 @@ fn has_hidden_attribute(path: &Path) -> bool { } #[cfg(not(windows))] -fn has_hidden_attribute(path: &Path) -> bool { +fn has_hidden_attribute(_: &Path) -> bool { false } diff --git a/espanso/src/cli/service/macos.rs b/espanso/src/cli/service/macos.rs index c65e120..f6914f5 100644 --- a/espanso/src/cli/service/macos.rs +++ b/espanso/src/cli/service/macos.rs @@ -59,7 +59,7 @@ pub fn register() -> Result<()> { // Copy the user PATH variable and inject it in the Plist file so that // it gets loaded by Launchd. // To see why this is necessary: https://github.com/federico-terzi/espanso/issues/233 - let user_path = std::env::var("PATH").unwrap_or("".to_owned()); + let user_path = std::env::var("PATH").unwrap_or_else(|_| "".to_owned()); let plist_content = plist_content.replace("{{{PATH}}}", &user_path); std::fs::write(plist_file.clone(), plist_content).expect("Unable to write plist file"); @@ -131,7 +131,7 @@ pub fn start_service() -> Result<()> { eprintln!("Unable to start espanso as a service as it's not been registered."); eprintln!("You can either register it first with `espanso service register` or"); eprintln!("you can run it in unmanaged mode with `espanso service start --unmanaged`"); - eprintln!(""); + eprintln!(); eprintln!("NOTE: unmanaged mode means espanso does not rely on the system service manager"); eprintln!(" to run, but as a result, you are in charge of starting/stopping espanso"); eprintln!(" when needed."); diff --git a/espanso/src/cli/workaround/secure_input.rs b/espanso/src/cli/workaround/secure_input.rs index 3addc79..a14bb4c 100644 --- a/espanso/src/cli/workaround/secure_input.rs +++ b/espanso/src/cli/workaround/secure_input.rs @@ -24,19 +24,19 @@ use std::{ process::{Command, Stdio}, }; -const BLUR_CHROME_WINDOWS_SCRIPT: &'static str = +const BLUR_CHROME_WINDOWS_SCRIPT: &str = include_str!("../../res/macos/scripts/blur_chrome_windows.scpt"); -const GET_RUNNING_APPS_SCRIPT: &'static str = +const GET_RUNNING_APPS_SCRIPT: &str = include_str!("../../res/macos/scripts/get_running_apps.scpt"); -const FOCUS_BITWARDEN_SCRIPT: &'static str = +const FOCUS_BITWARDEN_SCRIPT: &str = include_str!("../../res/macos/scripts/focus_bitwarden.scpt"); -const SECURE_INPUT_ASK_LOCK_SCREEN_SCRIPT: &'static str = +const SECURE_INPUT_ASK_LOCK_SCREEN_SCRIPT: &str = include_str!("../../res/macos/scripts/secure_input_ask_lock_screen.scpt"); -const SUCCESS_DIALOG_SCRIPT: &'static str = +const SUCCESS_DIALOG_SCRIPT: &str = include_str!("../../res/macos/scripts/secure_input_disabled_dialog.scpt"); pub fn run_secure_input_workaround() -> Result<()> { @@ -58,10 +58,10 @@ fn execute_secure_input_workaround() -> Result<()> { .unwrap_or_default() ); println!("so restarting that application could solve the problem."); - println!(""); + println!(); println!("Unfortunately, that guess might be wrong if SecureInput was activated by"); println!("the application while in the background."); - println!(""); + println!(); println!("This workaround will attempt to execute a series of known actions that often"); println!("help in disabling secure input."); @@ -112,7 +112,6 @@ fn run_apple_script(script: &str) -> Result { let child_stdin = child.stdin.as_mut().unwrap(); child_stdin.write_all(script.as_bytes())?; - drop(child_stdin); let output = child.wait_with_output()?; let stdout = String::from_utf8_lossy(&output.stdout); diff --git a/espanso/src/cli/worker/config.rs b/espanso/src/cli/worker/config.rs index 450fd89..cc78531 100644 --- a/espanso/src/cli/worker/config.rs +++ b/espanso/src/cli/worker/config.rs @@ -24,7 +24,6 @@ use espanso_config::{ matches::store::{MatchSet, MatchStore}, }; use espanso_info::{AppInfo, AppInfoProvider}; -use std::iter::FromIterator; use super::builtin::is_builtin_match; @@ -75,7 +74,7 @@ fn to_app_properties(info: &AppInfo) -> AppProperties { impl<'a> espanso_engine::process::MatchFilter for ConfigManager<'a> { fn filter_active(&self, matches_ids: &[i32]) -> Vec { - let ids_set: HashSet = HashSet::from_iter(matches_ids.iter().copied()); + let ids_set: HashSet = matches_ids.iter().copied().collect::>(); let (_, match_set) = self.active_context(); let active_user_defined_matches: Vec = match_set diff --git a/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs b/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs index 7b4e4ee..ff34c55 100644 --- a/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs +++ b/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs @@ -30,7 +30,6 @@ use espanso_match::{ rolling::{RollingMatch, StringMatchOptions}, }; use log::error; -use std::iter::FromIterator; use crate::cli::worker::builtin::BuiltInMatch; @@ -125,6 +124,6 @@ impl<'a> MatchConverter<'a> { fn global_match_set(&self) -> MatchSet { let paths = self.config_store.get_all_match_paths(); - self.match_store.query(&Vec::from_iter(paths.into_iter())) + self.match_store.query(&paths.into_iter().collect::>()) } } diff --git a/espanso/src/cli/worker/engine/process/middleware/render/mod.rs b/espanso/src/cli/worker/engine/process/middleware/render/mod.rs index 68fcd3d..98b1afa 100644 --- a/espanso/src/cli/worker/engine/process/middleware/render/mod.rs +++ b/espanso/src/cli/worker/engine/process/middleware/render/mod.rs @@ -115,8 +115,8 @@ fn generate_context<'a>( } Context { - templates, global_vars, + templates, } } diff --git a/espanso/src/cli/worker/match_cache.rs b/espanso/src/cli/worker/match_cache.rs index 29e37ae..2d85f72 100644 --- a/espanso/src/cli/worker/match_cache.rs +++ b/espanso/src/cli/worker/match_cache.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use std::{collections::HashMap, iter::FromIterator}; +use std::{collections::HashMap}; use espanso_config::{ config::ConfigStore, @@ -35,7 +35,7 @@ impl<'a> MatchCache<'a> { let mut cache = HashMap::new(); let paths = config_store.get_all_match_paths(); - let global_set = match_store.query(&Vec::from_iter(paths.into_iter())); + let global_set = match_store.query(&paths.into_iter().collect::>()); for m in global_set.matches { cache.insert(m.id, m); @@ -98,8 +98,8 @@ impl<'a> CombinedMatchCache<'a> { } Self { - builtin_match_cache, user_match_cache, + builtin_match_cache, } } diff --git a/espanso/src/cli/worker/secure_input.rs b/espanso/src/cli/worker/secure_input.rs index 3288a41..417582f 100644 --- a/espanso/src/cli/worker/secure_input.rs +++ b/espanso/src/cli/worker/secure_input.rs @@ -34,9 +34,6 @@ pub fn initialize_and_spawn(_secure_input_send: Sender) -> Res #[cfg(target_os = "macos")] pub fn initialize_and_spawn(secure_input_sender: Sender) -> Result<()> { - use log::{error, info}; - use std::time::Duration; - std::thread::Builder::new() .name("secure-input-monitor".to_string()) .spawn(move || { @@ -54,9 +51,11 @@ pub fn initialize_and_spawn(secure_input_sender: Sender) -> Re #[cfg(target_os = "macos")] fn secure_input_main( secure_input_sender: Sender, - min_watch_interval: Duration, - max_watch_interval: Duration, + min_watch_interval: std::time::Duration, + max_watch_interval: std::time::Duration, ) { + use log::{error, info}; + info!("monitoring the status of secure input"); let mut last_secure_input_pid: Option = None; @@ -67,6 +66,7 @@ fn secure_input_main( // Some application is currently on SecureInput let should_notify = if let Some(old_pid) = last_secure_input_pid { // We already detected a SecureInput app + #[allow(clippy::needless_bool)] if old_pid != pid { // The old app is different from the current one, we should take action true @@ -100,7 +100,7 @@ fn secure_input_main( // No app is currently keeping SecureInput // If there was an app with SecureInput, notify that is now free - if let Some(_) = last_secure_input_pid { + if last_secure_input_pid.is_some() { info!("secure input has been disabled"); if let Err(error) = secure_input_sender.send(SecureInputEvent::Disabled) { diff --git a/espanso/src/exit_code.rs b/espanso/src/exit_code.rs index d343205..81eda51 100644 --- a/espanso/src/exit_code.rs +++ b/espanso/src/exit_code.rs @@ -54,6 +54,7 @@ pub const SERVICE_NOT_RUNNING: i32 = 4; pub const WORKAROUND_SUCCESS: i32 = 0; #[allow(dead_code)] pub const WORKAROUND_FAILURE: i32 = 1; +#[allow(dead_code)] pub const WORKAROUND_NOT_AVAILABLE: i32 = 2; #[allow(dead_code)] diff --git a/espanso/src/path/macos.rs b/espanso/src/path/macos.rs index c649e35..729cea9 100644 --- a/espanso/src/path/macos.rs +++ b/espanso/src/path/macos.rs @@ -63,7 +63,7 @@ pub fn add_espanso_to_path(prompt_when_necessary: bool) -> Result<()> { return Err(PathError::SymlinkError(error).into()); } } - other_error => { + _other_error => { return Err(PathError::SymlinkError(error).into()); } } @@ -103,7 +103,7 @@ pub fn remove_espanso_from_path(prompt_when_necessary: bool) -> Result<()> { return Err(PathError::SymlinkError(error).into()); } } - other_error => { + _other_error => { return Err(PathError::SymlinkError(error).into()); } }