Skip to content

Commit

Permalink
defer creation of input capture / emulation (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
feschber authored Apr 26, 2024
1 parent 636c592 commit 77aa96e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};
use tokio::signal;

use crate::{capture, emulate};
use crate::{
client::{ClientHandle, ClientManager},
config::Config,
Expand Down Expand Up @@ -78,7 +77,6 @@ impl Server {
return anyhow::Ok(());
}
};
let (emulate, capture) = tokio::join!(emulate::create(), capture::create());

let (timer_tx, timer_rx) = tokio::sync::mpsc::channel(1);
let (frontend_notify_tx, frontend_notify_rx) = tokio::sync::mpsc::channel(1);
Expand All @@ -89,7 +87,6 @@ impl Server {

// input capture
let (mut capture_task, capture_channel) = capture_task::new(
capture,
self.clone(),
sender_tx.clone(),
timer_tx.clone(),
Expand All @@ -98,7 +95,6 @@ impl Server {

// input emulation
let (mut emulation_task, emulate_channel) = emulation_task::new(
emulate,
self.clone(),
receiver_rx,
sender_tx.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/server/capture_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{collections::HashSet, net::SocketAddr};
use tokio::{sync::mpsc::Sender, task::JoinHandle};

use crate::{
capture::InputCapture,
capture::{self, InputCapture},
client::{ClientEvent, ClientHandle},
event::{Event, KeyboardEvent},
scancode,
Expand All @@ -25,14 +25,14 @@ pub enum CaptureEvent {
}

pub fn new(
mut capture: Box<dyn InputCapture>,
server: Server,
sender_tx: Sender<(Event, SocketAddr)>,
timer_tx: Sender<()>,
release_bind: Vec<scancode::Linux>,
) -> (JoinHandle<Result<()>>, Sender<CaptureEvent>) {
let (tx, mut rx) = tokio::sync::mpsc::channel(32);
let task = tokio::task::spawn_local(async move {
let mut capture = capture::create().await;
let mut pressed_keys = HashSet::new();
loop {
tokio::select! {
Expand Down
4 changes: 2 additions & 2 deletions src/server/emulation_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::{

use crate::{
client::{ClientEvent, ClientHandle},
emulate::InputEmulation,
emulate::{self, InputEmulation},
event::{Event, KeyboardEvent},
scancode,
server::State,
Expand All @@ -27,7 +27,6 @@ pub enum EmulationEvent {
}

pub fn new(
mut emulate: Box<dyn InputEmulation>,
server: Server,
mut udp_rx: Receiver<Result<(Event, SocketAddr)>>,
sender_tx: Sender<(Event, SocketAddr)>,
Expand All @@ -36,6 +35,7 @@ pub fn new(
) -> (JoinHandle<Result<()>>, Sender<EmulationEvent>) {
let (tx, mut rx) = tokio::sync::mpsc::channel(32);
let emulate_task = tokio::task::spawn_local(async move {
let mut emulate = emulate::create().await;
let mut last_ignored = None;

loop {
Expand Down

0 comments on commit 77aa96e

Please sign in to comment.