espanso/src/check.rs

72 lines
2.4 KiB
Rust
Raw Permalink Normal View History

2019-09-15 16:29:11 +00:00
/*
* This file is part of espanso.
*
* Copyright (C) 2019 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
// This functions are used to check if the required dependencies and conditions are satisfied
2019-09-15 13:39:18 +00:00
// before starting espanso
#[cfg(target_os = "linux")]
pub fn check_preconditions() -> bool {
2019-09-15 13:39:18 +00:00
use std::process::Command;
let mut result = true;
// Make sure notify-send is installed
let status = Command::new("notify-send").arg("-v").output();
2019-09-28 08:44:25 +00:00
if status.is_err() {
2019-09-15 13:39:18 +00:00
println!("Error: 'notify-send' command is needed for espanso to work correctly, please install it.");
result = false;
}
// Make sure xclip is installed
let status = Command::new("xclip").arg("-version").output();
2019-09-28 08:44:25 +00:00
if status.is_err() {
println!(
"Error: 'xclip' command is needed for espanso to work correctly, please install it."
);
2019-09-15 13:39:18 +00:00
result = false;
}
result
}
#[cfg(target_os = "macos")]
pub fn check_preconditions() -> bool {
// Make sure no app is currently using secure input.
let secure_input_app = crate::system::macos::MacSystemManager::get_secure_input_application();
if let Some((app_name, process)) = secure_input_app {
eprintln!("WARNING: An application is currently using SecureInput and might prevent espanso from working correctly.");
eprintln!();
eprintln!("APP: {}", app_name);
eprintln!("PROC: {}", process);
eprintln!();
eprintln!("Please close it or disable SecureInput for that application (most apps that use it have a");
eprintln!("setting to disable it).");
eprintln!("Until then, espanso might not work as expected.");
}
2019-09-16 15:52:33 +00:00
true
2019-09-15 13:39:18 +00:00
}
#[cfg(target_os = "windows")]
pub fn check_preconditions() -> bool {
2019-09-15 13:39:18 +00:00
// Nothing needed on windows
true
}