mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
sync capture + emulation status
This commit is contained in:
@@ -10,8 +10,8 @@ license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/ferdinandschober/lan-mouse"
|
||||
|
||||
[profile.release]
|
||||
# strip = true
|
||||
# lto = "fat"
|
||||
strip = true
|
||||
lto = "fat"
|
||||
|
||||
[dependencies]
|
||||
input-event = { path = "input-event", version = "0.1.0" }
|
||||
|
||||
@@ -113,10 +113,11 @@ pub enum FrontendRequest {
|
||||
EnableEmulation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
|
||||
pub enum Status {
|
||||
Enabled,
|
||||
#[default]
|
||||
Disabled,
|
||||
Enabled,
|
||||
}
|
||||
|
||||
impl From<Status> for bool {
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
process, str,
|
||||
};
|
||||
|
||||
use crate::frontend::{gtk::window::Window, FrontendRequest};
|
||||
use crate::frontend::gtk::window::Window;
|
||||
|
||||
use adw::Application;
|
||||
use endi::{Endian, ReadBytes};
|
||||
@@ -113,7 +113,6 @@ fn build_ui(app: &Application) {
|
||||
});
|
||||
|
||||
let window = Window::new(app, tx);
|
||||
window.request(FrontendRequest::Enumerate());
|
||||
|
||||
glib::spawn_future_local(clone!(@weak window => async move {
|
||||
loop {
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
client::{ClientConfig, ClientHandle, ClientManager, ClientState, Position},
|
||||
config::Config,
|
||||
dns::DnsResolver,
|
||||
frontend::{self, FrontendEvent, FrontendListener, FrontendRequest},
|
||||
frontend::{self, FrontendEvent, FrontendListener, FrontendRequest, Status},
|
||||
server::capture_task::CaptureEvent,
|
||||
};
|
||||
|
||||
@@ -59,6 +59,8 @@ pub struct Server {
|
||||
config: Rc<Config>,
|
||||
pending_frontend_events: Rc<RefCell<VecDeque<FrontendEvent>>>,
|
||||
pending_dns_requests: Rc<RefCell<VecDeque<ClientHandle>>>,
|
||||
capture_status: Rc<Cell<Status>>,
|
||||
emulation_status: Rc<Cell<Status>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -113,6 +115,8 @@ impl Server {
|
||||
notifies,
|
||||
pending_frontend_events: Rc::new(RefCell::new(VecDeque::new())),
|
||||
pending_dns_requests: Rc::new(RefCell::new(VecDeque::new())),
|
||||
capture_status: Default::default(),
|
||||
emulation_status: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +182,9 @@ impl Server {
|
||||
Ok(s) => join_handles.push(self.clone().handle_frontend_stream(s, request_tx.clone())),
|
||||
Err(e) => log::warn!("error accepting frontend connection: {e}"),
|
||||
};
|
||||
self.enumerate();
|
||||
self.notify_frontend(FrontendEvent::EmulationStatus(self.emulation_status.get()));
|
||||
self.notify_frontend(FrontendEvent::CaptureStatus(self.capture_status.get()));
|
||||
}
|
||||
request = request_rx.recv() => {
|
||||
self.handle_request(&capture_tx, &emulation_tx, request.expect("channel closed")).await;
|
||||
@@ -317,42 +324,23 @@ impl Server {
|
||||
self.deactivate_client(capture, emulate, handle).await;
|
||||
}
|
||||
}
|
||||
FrontendRequest::ChangePort(port) => {
|
||||
self.request_port_change(port);
|
||||
}
|
||||
FrontendRequest::ChangePort(port) => self.request_port_change(port),
|
||||
FrontendRequest::Delete(handle) => {
|
||||
self.remove_client(capture, emulate, handle).await;
|
||||
self.notify_frontend(FrontendEvent::Deleted(handle));
|
||||
}
|
||||
FrontendRequest::Enumerate() => {
|
||||
let clients = self
|
||||
.client_manager
|
||||
.borrow()
|
||||
.get_client_states()
|
||||
.map(|(h, (c, s))| (h, c.clone(), s.clone()))
|
||||
.collect();
|
||||
self.notify_frontend(FrontendEvent::Enumerate(clients));
|
||||
}
|
||||
FrontendRequest::GetState(handle) => {
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
FrontendRequest::Enumerate() => self.enumerate(),
|
||||
FrontendRequest::GetState(handle) => self.broadcast_client(handle),
|
||||
FrontendRequest::UpdateFixIps(handle, fix_ips) => {
|
||||
self.update_fix_ips(handle, fix_ips).await;
|
||||
self.update_fix_ips(handle, fix_ips);
|
||||
self.request_dns(handle);
|
||||
}
|
||||
FrontendRequest::UpdateHostname(handle, hostname) => {
|
||||
self.update_hostname(handle, hostname).await;
|
||||
self.request_dns(handle);
|
||||
}
|
||||
FrontendRequest::UpdatePort(handle, port) => {
|
||||
self.update_port(handle, port);
|
||||
}
|
||||
FrontendRequest::UpdateHostname(handle, host) => self.update_hostname(handle, host),
|
||||
FrontendRequest::UpdatePort(handle, port) => self.update_port(handle, port),
|
||||
FrontendRequest::UpdatePosition(handle, pos) => {
|
||||
self.update_pos(handle, capture, emulate, pos).await;
|
||||
}
|
||||
FrontendRequest::ResolveDns(handle) => {
|
||||
self.request_dns(handle);
|
||||
}
|
||||
FrontendRequest::ResolveDns(handle) => self.request_dns(handle),
|
||||
};
|
||||
false
|
||||
}
|
||||
@@ -372,6 +360,16 @@ impl Server {
|
||||
})
|
||||
}
|
||||
|
||||
fn enumerate(&self) {
|
||||
let clients = self
|
||||
.client_manager
|
||||
.borrow()
|
||||
.get_client_states()
|
||||
.map(|(h, (c, s))| (h, c.clone(), s.clone()))
|
||||
.collect();
|
||||
self.notify_frontend(FrontendEvent::Enumerate(clients));
|
||||
}
|
||||
|
||||
async fn add_client(&self) -> ClientHandle {
|
||||
let handle = self.client_manager.borrow_mut().add_client();
|
||||
log::info!("added client {handle}");
|
||||
@@ -447,7 +445,7 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
async fn update_fix_ips(&self, handle: ClientHandle, fix_ips: Vec<IpAddr>) {
|
||||
fn update_fix_ips(&self, handle: ClientHandle, fix_ips: Vec<IpAddr>) {
|
||||
let mut client_manager = self.client_manager.borrow_mut();
|
||||
let Some((c, _)) = client_manager.get_mut(handle) else {
|
||||
return;
|
||||
@@ -456,7 +454,7 @@ impl Server {
|
||||
c.fix_ips = fix_ips;
|
||||
}
|
||||
|
||||
async fn update_hostname(&self, handle: ClientHandle, hostname: Option<String>) {
|
||||
fn update_hostname(&self, handle: ClientHandle, hostname: Option<String>) {
|
||||
let mut client_manager = self.client_manager.borrow_mut();
|
||||
let Some((c, s)) = client_manager.get_mut(handle) else {
|
||||
return;
|
||||
@@ -521,6 +519,18 @@ impl Server {
|
||||
};
|
||||
self.notify_frontend(event);
|
||||
}
|
||||
|
||||
fn set_emulation_status(&self, status: Status) {
|
||||
self.emulation_status.replace(status);
|
||||
let status = FrontendEvent::EmulationStatus(status);
|
||||
self.notify_frontend(status);
|
||||
}
|
||||
|
||||
fn set_capture_status(&self, status: Status) {
|
||||
self.capture_status.replace(status);
|
||||
let status = FrontendEvent::CaptureStatus(status);
|
||||
self.notify_frontend(status);
|
||||
}
|
||||
}
|
||||
|
||||
async fn listen_frontend(
|
||||
|
||||
@@ -14,11 +14,7 @@ use input_capture::{
|
||||
|
||||
use input_event::{scancode, Event, KeyboardEvent};
|
||||
|
||||
use crate::{
|
||||
client::ClientHandle,
|
||||
frontend::{FrontendEvent, Status},
|
||||
server::State,
|
||||
};
|
||||
use crate::{client::ClientHandle, frontend::Status, server::State};
|
||||
|
||||
use super::Server;
|
||||
|
||||
@@ -59,7 +55,7 @@ async fn capture_task(
|
||||
if let Err(e) = do_capture(backend, &server, &sender_tx, &mut notify_rx).await {
|
||||
log::warn!("input capture exited: {e}");
|
||||
}
|
||||
server.notify_frontend(FrontendEvent::CaptureStatus(Status::Disabled));
|
||||
server.set_capture_status(Status::Disabled);
|
||||
if server.is_cancelled() {
|
||||
break;
|
||||
}
|
||||
@@ -81,7 +77,7 @@ async fn do_capture(
|
||||
_ = server.cancelled() => return Ok(()),
|
||||
};
|
||||
|
||||
server.notify_frontend(FrontendEvent::CaptureStatus(Status::Enabled));
|
||||
server.set_capture_status(Status::Enabled);
|
||||
|
||||
// FIXME DUPLICATES
|
||||
let clients = server
|
||||
|
||||
@@ -8,7 +8,7 @@ use tokio::{
|
||||
|
||||
use crate::{
|
||||
client::{ClientHandle, ClientManager},
|
||||
frontend::{FrontendEvent, Status},
|
||||
frontend::Status,
|
||||
server::State,
|
||||
};
|
||||
use input_emulation::{
|
||||
@@ -63,8 +63,7 @@ async fn emulation_task(
|
||||
log::warn!("input emulation exited: {e}");
|
||||
}
|
||||
}
|
||||
let emulation_disabled = FrontendEvent::EmulationStatus(Status::Disabled);
|
||||
server.notify_frontend(emulation_disabled);
|
||||
server.set_emulation_status(Status::Disabled);
|
||||
|
||||
if server.notifies.cancel.is_cancelled() {
|
||||
break;
|
||||
@@ -90,8 +89,8 @@ async fn do_emulation(
|
||||
}
|
||||
_ = server.cancelled() => return Ok(()),
|
||||
};
|
||||
let emulation_enabled = FrontendEvent::EmulationStatus(Status::Enabled);
|
||||
server.notify_frontend(emulation_enabled);
|
||||
|
||||
server.set_emulation_status(Status::Enabled);
|
||||
|
||||
let res = do_emulation_session(server, &mut emulation, rx, udp_rx, sender_tx, capture_tx).await;
|
||||
emulation.terminate().await;
|
||||
|
||||
Reference in New Issue
Block a user