mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-23 05:00:52 +03:00
fix service exit
This commit is contained in:
@@ -174,6 +174,7 @@ impl Emulation {
|
||||
/// discarding events when it is disabled
|
||||
pub(crate) struct EmulationProxy {
|
||||
emulation_active: Rc<Cell<bool>>,
|
||||
exit_requested: Rc<Cell<bool>>,
|
||||
request_tx: Sender<ProxyRequest>,
|
||||
event_rx: Receiver<EmulationEvent>,
|
||||
task: JoinHandle<()>,
|
||||
@@ -191,9 +192,16 @@ impl EmulationProxy {
|
||||
let (request_tx, request_rx) = channel();
|
||||
let (event_tx, event_rx) = channel();
|
||||
let emulation_active = Rc::new(Cell::new(false));
|
||||
let task = spawn_local(Self::emulation_task(backend, request_rx, event_tx));
|
||||
let exit_requested = Rc::new(Cell::new(false));
|
||||
let task = spawn_local(Self::emulation_task(
|
||||
backend,
|
||||
exit_requested.clone(),
|
||||
request_rx,
|
||||
event_tx,
|
||||
));
|
||||
Self {
|
||||
emulation_active,
|
||||
exit_requested,
|
||||
request_tx,
|
||||
task,
|
||||
event_rx,
|
||||
@@ -228,6 +236,7 @@ impl EmulationProxy {
|
||||
|
||||
async fn emulation_task(
|
||||
backend: Option<input_emulation::Backend>,
|
||||
exit_requested: Rc<Cell<bool>>,
|
||||
mut request_rx: Receiver<ProxyRequest>,
|
||||
event_tx: Sender<EmulationEvent>,
|
||||
) {
|
||||
@@ -245,6 +254,9 @@ impl EmulationProxy {
|
||||
{
|
||||
log::warn!("input emulation exited: {e}");
|
||||
}
|
||||
if exit_requested.get() {
|
||||
break;
|
||||
}
|
||||
// wait for reenable request
|
||||
loop {
|
||||
match request_rx.recv().await.expect("channel closed") {
|
||||
@@ -330,6 +342,7 @@ impl EmulationProxy {
|
||||
}
|
||||
|
||||
async fn terminate(&mut self) {
|
||||
self.exit_requested.replace(true);
|
||||
self.request_tx
|
||||
.send(ProxyRequest::Terminate)
|
||||
.expect("channel closed");
|
||||
|
||||
Reference in New Issue
Block a user