Add prechecks
This commit is contained in:
parent
a2b3ab90f0
commit
fbee38d5b8
40
src/check.rs
Normal file
40
src/check.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// This functions are used to check if the required dependencies are satisfied
|
||||||
|
// before starting espanso
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn check_dependencies() -> bool {
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
let mut result = true;
|
||||||
|
|
||||||
|
// Make sure notify-send is installed
|
||||||
|
let status = Command::new("notify-send")
|
||||||
|
.arg("-v")
|
||||||
|
.output();
|
||||||
|
if let Err(_) = status {
|
||||||
|
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();
|
||||||
|
if let Err(_) = status {
|
||||||
|
println!("Error: 'xclip' command is needed for espanso to work correctly, please install it.");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn check_dependencies() -> bool {
|
||||||
|
// TODO: check accessibility
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub fn check_dependencies() -> bool {
|
||||||
|
// Nothing needed on windows
|
||||||
|
true
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::io::{Write};
|
use std::io::{Write};
|
||||||
|
use log::error;
|
||||||
|
|
||||||
pub struct LinuxClipboardManager {}
|
pub struct LinuxClipboardManager {}
|
||||||
|
|
||||||
|
@ -31,8 +32,8 @@ impl super::ClipboardManager for LinuxClipboardManager {
|
||||||
if let Some(output) = stdin {
|
if let Some(output) = stdin {
|
||||||
let res = output.write_all(payload.as_bytes());
|
let res = output.write_all(payload.as_bytes());
|
||||||
|
|
||||||
if let Err(_) = res {
|
if let Err(e) = res {
|
||||||
// TODO: log error
|
error!("Could not set clipboard: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +42,6 @@ impl super::ClipboardManager for LinuxClipboardManager {
|
||||||
|
|
||||||
impl LinuxClipboardManager {
|
impl LinuxClipboardManager {
|
||||||
pub fn new() -> LinuxClipboardManager {
|
pub fn new() -> LinuxClipboardManager {
|
||||||
// TODO: check if xclip is present and log an error otherwise.
|
|
||||||
|
|
||||||
LinuxClipboardManager{}
|
LinuxClipboardManager{}
|
||||||
}
|
}
|
||||||
}
|
}
|
18
src/main.rs
18
src/main.rs
|
@ -27,6 +27,7 @@ use std::io::{BufReader, BufRead};
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
mod event;
|
mod event;
|
||||||
|
mod check;
|
||||||
mod bridge;
|
mod bridge;
|
||||||
mod engine;
|
mod engine;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -154,6 +155,9 @@ fn main() {
|
||||||
restart_main(config_set);
|
restart_main(config_set);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Defaults to start subcommand
|
||||||
|
start_main(config_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Daemon subcommand, start the event loop and spawn a background thread worker
|
/// Daemon subcommand, start the event loop and spawn a background thread worker
|
||||||
|
@ -165,6 +169,8 @@ fn daemon_main(config_set: ConfigSet) {
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
precheck_guard();
|
||||||
|
|
||||||
// Initialize log
|
// Initialize log
|
||||||
let log_level = match config_set.default.log_level {
|
let log_level = match config_set.default.log_level {
|
||||||
0 => LevelFilter::Warn,
|
0 => LevelFilter::Warn,
|
||||||
|
@ -261,6 +267,8 @@ fn start_main(config_set: ConfigSet) {
|
||||||
}
|
}
|
||||||
release_lock(lock_file.unwrap());
|
release_lock(lock_file.unwrap());
|
||||||
|
|
||||||
|
precheck_guard();
|
||||||
|
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
// TODO: start windows detached
|
// TODO: start windows detached
|
||||||
}else{
|
}else{
|
||||||
|
@ -469,3 +477,13 @@ fn acquire_lock() -> Option<File> {
|
||||||
fn release_lock(lock_file: File) {
|
fn release_lock(lock_file: File) {
|
||||||
lock_file.unlock().unwrap()
|
lock_file.unlock().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Used to make sure all the required dependencies are present before starting espanso.
|
||||||
|
fn precheck_guard() {
|
||||||
|
let satisfied = check::check_dependencies();
|
||||||
|
if !satisfied {
|
||||||
|
println!();
|
||||||
|
println!("Pre-check was not successful, espanso could not be started.");
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user