From 5537d70989484cea7e048695c6890f7b9dc90749 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 19 Oct 2019 21:44:59 +0200 Subject: [PATCH] Fix bug that caused the deprecation warning message to be printed multiple times. Fix #85. --- src/context/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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; }