diff --git a/src/context/mod.rs b/src/context/mod.rs index c338de7..bb60478 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -30,6 +30,7 @@ use std::sync::mpsc::Sender; use crate::event::Event; use std::path::PathBuf; use std::fs::create_dir_all; +use std::sync::Once; pub trait Context { fn eventloop(&self); @@ -55,6 +56,8 @@ pub fn new(send_channel: Sender) -> Box { // espanso directories +static WARING_INIT : Once = Once::new(); + pub fn get_data_dir() -> PathBuf { let data_dir = dirs::data_local_dir().expect("Can't obtain data_local_dir(), terminating."); let espanso_dir = data_dir.join("espanso"); @@ -79,9 +82,13 @@ pub fn get_config_dir() -> PathBuf { let home_dir = dirs::home_dir().expect("Can't obtain the user home directory, terminating."); let legacy_espanso_dir = home_dir.join(".espanso"); if legacy_espanso_dir.exists() { - eprintln!("WARNING: using legacy espanso config location in $HOME/.espanso is DEPRECATED"); - eprintln!("Starting from espanso v0.3.0, espanso config location is changed."); - eprintln!("Please check out the documentation to find out more: https://espanso.org/docs/configuration/"); + // Avoid printing the warning multiple times with std::sync::Once + WARING_INIT.call_once(|| { + eprintln!("WARNING: using legacy espanso config location in $HOME/.espanso is DEPRECATED"); + eprintln!("Starting from espanso v0.3.0, espanso config location is changed."); + eprintln!("Please check out the documentation to find out more: https://espanso.org/docs/configuration/"); + eprintln!() + }); return legacy_espanso_dir; }