feat(core): improve notification handling
This commit is contained in:
parent
e9d90929a6
commit
adc13c707d
|
@ -110,6 +110,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
|
|||
&paths_overrides,
|
||||
exit_notify.clone(),
|
||||
&mut worker_run_count,
|
||||
false,
|
||||
);
|
||||
|
||||
ipc::initialize_and_spawn(&paths.runtime, exit_notify.clone())
|
||||
|
@ -159,7 +160,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
|
|||
}
|
||||
|
||||
if !has_timed_out {
|
||||
spawn_worker(&paths, &paths_overrides, exit_notify.clone(), &mut worker_run_count);
|
||||
spawn_worker(&paths, &paths_overrides, exit_notify.clone(), &mut worker_run_count, false);
|
||||
} else {
|
||||
error!("could not restart worker, as the exit process has timed out");
|
||||
}
|
||||
|
@ -174,7 +175,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
|
|||
}
|
||||
WORKER_RESTART => {
|
||||
info!("worker requested a restart, spawning a new one...");
|
||||
spawn_worker(&paths, &paths_overrides, exit_notify.clone(), &mut worker_run_count);
|
||||
spawn_worker(&paths, &paths_overrides, exit_notify.clone(), &mut worker_run_count, true);
|
||||
}
|
||||
_ => {
|
||||
error!("received unexpected exit code from worker {}, exiting", code);
|
||||
|
@ -236,6 +237,7 @@ fn spawn_worker(
|
|||
paths_overrides: &PathsOverrides,
|
||||
exit_notify: Sender<i32>,
|
||||
worker_run_count: &mut i32,
|
||||
manual_start: bool,
|
||||
) {
|
||||
info!("spawning the worker process...");
|
||||
|
||||
|
@ -265,12 +267,18 @@ fn spawn_worker(
|
|||
};
|
||||
|
||||
let mut command = Command::new(&espanso_exe_path.to_string_lossy().to_string());
|
||||
command.args(&[
|
||||
|
||||
let string_worker_run_count = format!("{}", worker_run_count);
|
||||
let mut args = vec![
|
||||
"worker",
|
||||
"--monitor-daemon",
|
||||
"--run-count",
|
||||
&format!("{}", worker_run_count),
|
||||
]);
|
||||
&string_worker_run_count
|
||||
];
|
||||
if manual_start {
|
||||
args.push("--manual");
|
||||
}
|
||||
command.args(&args);
|
||||
command.with_paths_overrides(paths_overrides);
|
||||
|
||||
let mut child = command.spawn().expect("unable to spawn worker process");
|
||||
|
|
|
@ -73,6 +73,7 @@ pub fn initialize_and_spawn(
|
|||
secure_input_receiver: Receiver<SecureInputEvent>,
|
||||
use_evdev_backend: bool,
|
||||
run_count: i32,
|
||||
has_been_started_manually: bool,
|
||||
) -> Result<JoinHandle<ExitMode>> {
|
||||
let handle = std::thread::Builder::new()
|
||||
.name("engine thread".to_string())
|
||||
|
@ -215,8 +216,13 @@ pub fn initialize_and_spawn(
|
|||
// TODO: check config
|
||||
match run_count {
|
||||
0 => ui_remote.show_notification("Espanso is running!"),
|
||||
1 => ui_remote.show_notification("Configuration reloaded! Espanso automatically loads new changes as soon as you save them."),
|
||||
_ => {},
|
||||
n => {
|
||||
if has_been_started_manually {
|
||||
ui_remote.show_notification("Configuration reloaded!");
|
||||
} else if n == 1 {
|
||||
ui_remote.show_notification("Configuration reloaded! Espanso automatically loads new changes as soon as you save them.");
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
let mut engine = crate::engine::Engine::new(&funnel, &mut processor, &dispatcher);
|
||||
|
|
|
@ -67,6 +67,8 @@ fn worker_main(args: CliModuleArgs) -> i32 {
|
|||
.unwrap_or(0);
|
||||
debug!("starting with run-count = {:?}", cli_args);
|
||||
|
||||
let has_been_started_manually = cli_args.is_present("manual");
|
||||
|
||||
// Avoid running multiple worker instances
|
||||
let lock_file = acquire_worker_lock(&paths.runtime);
|
||||
if lock_file.is_none() {
|
||||
|
@ -129,6 +131,7 @@ fn worker_main(args: CliModuleArgs) -> i32 {
|
|||
engine_secure_input_receiver,
|
||||
use_evdev_backend,
|
||||
run_count,
|
||||
has_been_started_manually,
|
||||
)
|
||||
.expect("unable to initialize engine");
|
||||
|
||||
|
|
|
@ -345,6 +345,12 @@ fn main() {
|
|||
.required(false)
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("manual")
|
||||
.long("manual")
|
||||
.required(false)
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("monitor-daemon")
|
||||
.long("monitor-daemon")
|
||||
|
|
Loading…
Reference in New Issue
Block a user