fix(core): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 23:17:22 +02:00
parent 4b57dd04ca
commit 2fd6927030
10 changed files with 25 additions and 27 deletions

View File

@ -128,6 +128,6 @@ fn has_hidden_attribute(path: &Path) -> bool {
} }
#[cfg(not(windows))] #[cfg(not(windows))]
fn has_hidden_attribute(path: &Path) -> bool { fn has_hidden_attribute(_: &Path) -> bool {
false false
} }

View File

@ -59,7 +59,7 @@ pub fn register() -> Result<()> {
// Copy the user PATH variable and inject it in the Plist file so that // Copy the user PATH variable and inject it in the Plist file so that
// it gets loaded by Launchd. // it gets loaded by Launchd.
// To see why this is necessary: https://github.com/federico-terzi/espanso/issues/233 // 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); let plist_content = plist_content.replace("{{{PATH}}}", &user_path);
std::fs::write(plist_file.clone(), plist_content).expect("Unable to write plist file"); 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!("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 either register it first with `espanso service register` or");
eprintln!("you can run it in unmanaged mode with `espanso service start --unmanaged`"); 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!("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!(" to run, but as a result, you are in charge of starting/stopping espanso");
eprintln!(" when needed."); eprintln!(" when needed.");

View File

@ -24,19 +24,19 @@ use std::{
process::{Command, Stdio}, 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"); 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"); 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"); 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"); 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"); include_str!("../../res/macos/scripts/secure_input_disabled_dialog.scpt");
pub fn run_secure_input_workaround() -> Result<()> { pub fn run_secure_input_workaround() -> Result<()> {
@ -58,10 +58,10 @@ fn execute_secure_input_workaround() -> Result<()> {
.unwrap_or_default() .unwrap_or_default()
); );
println!("so restarting that application could solve the problem."); println!("so restarting that application could solve the problem.");
println!(""); println!();
println!("Unfortunately, that guess might be wrong if SecureInput was activated by"); println!("Unfortunately, that guess might be wrong if SecureInput was activated by");
println!("the application while in the background."); println!("the application while in the background.");
println!(""); println!();
println!("This workaround will attempt to execute a series of known actions that often"); println!("This workaround will attempt to execute a series of known actions that often");
println!("help in disabling secure input."); println!("help in disabling secure input.");
@ -112,7 +112,6 @@ fn run_apple_script(script: &str) -> Result<String> {
let child_stdin = child.stdin.as_mut().unwrap(); let child_stdin = child.stdin.as_mut().unwrap();
child_stdin.write_all(script.as_bytes())?; child_stdin.write_all(script.as_bytes())?;
drop(child_stdin);
let output = child.wait_with_output()?; let output = child.wait_with_output()?;
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);

View File

@ -24,7 +24,6 @@ use espanso_config::{
matches::store::{MatchSet, MatchStore}, matches::store::{MatchSet, MatchStore},
}; };
use espanso_info::{AppInfo, AppInfoProvider}; use espanso_info::{AppInfo, AppInfoProvider};
use std::iter::FromIterator;
use super::builtin::is_builtin_match; 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> { impl<'a> espanso_engine::process::MatchFilter for ConfigManager<'a> {
fn filter_active(&self, matches_ids: &[i32]) -> Vec<i32> { fn filter_active(&self, matches_ids: &[i32]) -> Vec<i32> {
let ids_set: HashSet<i32> = HashSet::from_iter(matches_ids.iter().copied()); let ids_set: HashSet<i32> = matches_ids.iter().copied().collect::<HashSet<_>>();
let (_, match_set) = self.active_context(); let (_, match_set) = self.active_context();
let active_user_defined_matches: Vec<i32> = match_set let active_user_defined_matches: Vec<i32> = match_set

View File

@ -30,7 +30,6 @@ use espanso_match::{
rolling::{RollingMatch, StringMatchOptions}, rolling::{RollingMatch, StringMatchOptions},
}; };
use log::error; use log::error;
use std::iter::FromIterator;
use crate::cli::worker::builtin::BuiltInMatch; use crate::cli::worker::builtin::BuiltInMatch;
@ -125,6 +124,6 @@ impl<'a> MatchConverter<'a> {
fn global_match_set(&self) -> MatchSet { fn global_match_set(&self) -> MatchSet {
let paths = self.config_store.get_all_match_paths(); 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::<Vec<_>>())
} }
} }

View File

@ -115,8 +115,8 @@ fn generate_context<'a>(
} }
Context { Context {
templates,
global_vars, global_vars,
templates,
} }
} }

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::{collections::HashMap, iter::FromIterator}; use std::{collections::HashMap};
use espanso_config::{ use espanso_config::{
config::ConfigStore, config::ConfigStore,
@ -35,7 +35,7 @@ impl<'a> MatchCache<'a> {
let mut cache = HashMap::new(); let mut cache = HashMap::new();
let paths = config_store.get_all_match_paths(); 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::<Vec<_>>());
for m in global_set.matches { for m in global_set.matches {
cache.insert(m.id, m); cache.insert(m.id, m);
@ -98,8 +98,8 @@ impl<'a> CombinedMatchCache<'a> {
} }
Self { Self {
builtin_match_cache,
user_match_cache, user_match_cache,
builtin_match_cache,
} }
} }

View File

@ -34,9 +34,6 @@ pub fn initialize_and_spawn(_secure_input_send: Sender<SecureInputEvent>) -> Res
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub fn initialize_and_spawn(secure_input_sender: Sender<SecureInputEvent>) -> Result<()> { pub fn initialize_and_spawn(secure_input_sender: Sender<SecureInputEvent>) -> Result<()> {
use log::{error, info};
use std::time::Duration;
std::thread::Builder::new() std::thread::Builder::new()
.name("secure-input-monitor".to_string()) .name("secure-input-monitor".to_string())
.spawn(move || { .spawn(move || {
@ -54,9 +51,11 @@ pub fn initialize_and_spawn(secure_input_sender: Sender<SecureInputEvent>) -> Re
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn secure_input_main( fn secure_input_main(
secure_input_sender: Sender<SecureInputEvent>, secure_input_sender: Sender<SecureInputEvent>,
min_watch_interval: Duration, min_watch_interval: std::time::Duration,
max_watch_interval: Duration, max_watch_interval: std::time::Duration,
) { ) {
use log::{error, info};
info!("monitoring the status of secure input"); info!("monitoring the status of secure input");
let mut last_secure_input_pid: Option<i64> = None; let mut last_secure_input_pid: Option<i64> = None;
@ -67,6 +66,7 @@ fn secure_input_main(
// Some application is currently on SecureInput // Some application is currently on SecureInput
let should_notify = if let Some(old_pid) = last_secure_input_pid { let should_notify = if let Some(old_pid) = last_secure_input_pid {
// We already detected a SecureInput app // We already detected a SecureInput app
#[allow(clippy::needless_bool)]
if old_pid != pid { if old_pid != pid {
// The old app is different from the current one, we should take action // The old app is different from the current one, we should take action
true true
@ -100,7 +100,7 @@ fn secure_input_main(
// No app is currently keeping SecureInput // No app is currently keeping SecureInput
// If there was an app with SecureInput, notify that is now free // 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"); info!("secure input has been disabled");
if let Err(error) = secure_input_sender.send(SecureInputEvent::Disabled) { if let Err(error) = secure_input_sender.send(SecureInputEvent::Disabled) {

View File

@ -54,6 +54,7 @@ pub const SERVICE_NOT_RUNNING: i32 = 4;
pub const WORKAROUND_SUCCESS: i32 = 0; pub const WORKAROUND_SUCCESS: i32 = 0;
#[allow(dead_code)] #[allow(dead_code)]
pub const WORKAROUND_FAILURE: i32 = 1; pub const WORKAROUND_FAILURE: i32 = 1;
#[allow(dead_code)]
pub const WORKAROUND_NOT_AVAILABLE: i32 = 2; pub const WORKAROUND_NOT_AVAILABLE: i32 = 2;
#[allow(dead_code)] #[allow(dead_code)]

View File

@ -63,7 +63,7 @@ pub fn add_espanso_to_path(prompt_when_necessary: bool) -> Result<()> {
return Err(PathError::SymlinkError(error).into()); return Err(PathError::SymlinkError(error).into());
} }
} }
other_error => { _other_error => {
return Err(PathError::SymlinkError(error).into()); 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()); return Err(PathError::SymlinkError(error).into());
} }
} }
other_error => { _other_error => {
return Err(PathError::SymlinkError(error).into()); return Err(PathError::SymlinkError(error).into());
} }
} }