impl change config request

This commit is contained in:
Ferdinand Schober
2025-03-23 12:31:47 +01:00
committed by Ferdinand Schober
parent 6d16747c19
commit 18bba183ee
3 changed files with 37 additions and 2 deletions

View File

@@ -15,6 +15,15 @@ pub struct ClientManager {
} }
impl ClientManager { impl ClientManager {
/// get all clients
pub fn clients(&self) -> Vec<(ClientConfig, ClientState)> {
self.clients
.borrow()
.iter()
.map(|(_, c)| c.clone())
.collect::<Vec<_>>()
}
/// add a new client to this manager /// add a new client to this manager
pub fn add_client(&self) -> ClientHandle { pub fn add_client(&self) -> ClientHandle {
self.clients.borrow_mut().insert(Default::default()) as ClientHandle self.clients.borrow_mut().insert(Default::default()) as ClientHandle

View File

@@ -431,4 +431,8 @@ impl Config {
.expect("config") .expect("config")
.authorized_fingerprints = Some(fingerprints); .authorized_fingerprints = Some(fingerprints);
} }
pub fn write_back(&self) {
todo!()
}
} }

View File

@@ -1,7 +1,7 @@
use crate::{ use crate::{
capture::{Capture, CaptureType, ICaptureEvent}, capture::{Capture, CaptureType, ICaptureEvent},
client::ClientManager, client::ClientManager,
config::Config, config::{Config, ConfigClient},
connect::LanMouseConnection, connect::LanMouseConnection,
crypto, crypto,
dns::{DnsEvent, DnsResolver}, dns::{DnsEvent, DnsResolver},
@@ -39,6 +39,8 @@ pub enum ServiceError {
} }
pub struct Service { pub struct Service {
/// configuration
config: Config,
/// input capture /// input capture
capture: Capture, capture: Capture,
/// input emulation /// input emulation
@@ -122,6 +124,7 @@ impl Service {
let port = config.port(); let port = config.port();
let service = Self { let service = Self {
config,
capture, capture,
emulation, emulation,
frontend_listener, frontend_listener,
@@ -200,10 +203,29 @@ impl Service {
FrontendRequest::UpdateEnterHook(handle, enter_hook) => { FrontendRequest::UpdateEnterHook(handle, enter_hook) => {
self.update_enter_hook(handle, enter_hook) self.update_enter_hook(handle, enter_hook)
} }
FrontendRequest::SaveConfiguration => todo!(), FrontendRequest::SaveConfiguration => self.save_config(),
} }
} }
fn save_config(&mut self) {
let clients = self.client_manager.clients();
let clients = clients
.into_iter()
.map(|(c, s)| ConfigClient {
ips: HashSet::from_iter(c.fix_ips),
hostname: c.hostname,
port: c.port,
pos: c.pos,
active: s.active,
enter_hook: c.cmd,
})
.collect();
self.config.set_clients(clients);
let authorized_keys = self.authorized_keys.read().expect("lock").clone();
self.config.set_authorized_keys(authorized_keys);
self.config.write_back();
}
async fn handle_frontend_pending(&mut self) { async fn handle_frontend_pending(&mut self) {
while let Some(event) = self.pending_frontend_events.pop_front() { while let Some(event) = self.pending_frontend_events.pop_front() {
self.frontend_listener.broadcast(event).await; self.frontend_listener.broadcast(event).await;