fix(core): improve reporting of espanso start command. Relates to #839

This commit is contained in:
Federico Terzi 2021-11-04 21:07:44 +01:00
parent ec7f1772dd
commit 7d5fd6aa8b
2 changed files with 18 additions and 4 deletions

View File

@ -17,12 +17,14 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::time::Instant;
use super::{CliModule, CliModuleArgs, PathsOverrides};
use crate::{
error_eprintln,
exit_code::{
SERVICE_ALREADY_RUNNING, SERVICE_FAILURE, SERVICE_NOT_REGISTERED, SERVICE_NOT_RUNNING,
SERVICE_SUCCESS,
SERVICE_SUCCESS, SERVICE_TIMED_OUT,
},
info_println,
lock::acquire_worker_lock,
@ -131,12 +133,23 @@ fn start_main(paths: &Paths, _paths_overrides: &PathsOverrides, args: &ArgMatche
if let Err(err) = start_service() {
error_eprintln!("unable to start service: {}", err);
return SERVICE_FAILURE;
} else {
info_println!("espanso started correctly!");
}
}
SERVICE_SUCCESS
let now = Instant::now();
while now.elapsed() < std::time::Duration::from_secs(5) {
let lock_file = acquire_worker_lock(&paths.runtime);
if lock_file.is_none() {
info_println!("espanso started correctly!");
return SERVICE_SUCCESS;
}
drop(lock_file);
std::thread::sleep(std::time::Duration::from_millis(200));
}
error_eprintln!("unable to start service: timed out");
SERVICE_TIMED_OUT
}
fn stop_main(paths: &Paths) -> i32 {

View File

@ -51,6 +51,7 @@ pub const SERVICE_FAILURE: i32 = 1;
pub const SERVICE_NOT_REGISTERED: i32 = 2;
pub const SERVICE_ALREADY_RUNNING: i32 = 3;
pub const SERVICE_NOT_RUNNING: i32 = 4;
pub const SERVICE_TIMED_OUT: i32 = 5;
pub const WORKAROUND_SUCCESS: i32 = 0;
#[allow(dead_code)]