Skip to content

Commit c5da55f

Browse files
committed
impl change config request
1 parent 3124b95 commit c5da55f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ pub struct ClientManager {
1515
}
1616

1717
impl ClientManager {
18+
/// get all clients
19+
pub fn clients(&self) -> Vec<(ClientConfig, ClientState)> {
20+
self.clients
21+
.borrow()
22+
.iter()
23+
.map(|(_, c)| c.clone())
24+
.collect::<Vec<_>>()
25+
}
26+
1827
/// add a new client to this manager
1928
pub fn add_client(&self) -> ClientHandle {
2029
self.clients.borrow_mut().insert(Default::default()) as ClientHandle

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,8 @@ impl Config {
431431
.expect("config")
432432
.authorized_fingerprints = Some(fingerprints);
433433
}
434+
435+
pub fn write_back(&self) {
436+
todo!()
437+
}
434438
}

src/service.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
capture::{Capture, CaptureType, ICaptureEvent},
33
client::ClientManager,
4-
config::Config,
4+
config::{Config, ConfigClient},
55
connect::LanMouseConnection,
66
crypto,
77
dns::{DnsEvent, DnsResolver},
@@ -39,6 +39,8 @@ pub enum ServiceError {
3939
}
4040

4141
pub struct Service {
42+
/// configuration
43+
config: Config,
4244
/// input capture
4345
capture: Capture,
4446
/// input emulation
@@ -122,6 +124,7 @@ impl Service {
122124

123125
let port = config.port();
124126
let service = Self {
127+
config,
125128
capture,
126129
emulation,
127130
frontend_listener,
@@ -200,10 +203,29 @@ impl Service {
200203
FrontendRequest::UpdateEnterHook(handle, enter_hook) => {
201204
self.update_enter_hook(handle, enter_hook)
202205
}
203-
FrontendRequest::SaveConfiguration => todo!(),
206+
FrontendRequest::SaveConfiguration => self.save_config(),
204207
}
205208
}
206209

210+
fn save_config(&mut self) {
211+
let clients = self.client_manager.clients();
212+
let clients = clients
213+
.into_iter()
214+
.map(|(c, s)| ConfigClient {
215+
ips: HashSet::from_iter(c.fix_ips),
216+
hostname: c.hostname,
217+
port: c.port,
218+
pos: c.pos,
219+
active: s.active,
220+
enter_hook: c.cmd,
221+
})
222+
.collect();
223+
self.config.set_clients(clients);
224+
let authorized_keys = self.authorized_keys.read().expect("lock").clone();
225+
self.config.set_authorized_keys(authorized_keys);
226+
self.config.write_back();
227+
}
228+
207229
async fn handle_frontend_pending(&mut self) {
208230
while let Some(event) = self.pending_frontend_events.pop_front() {
209231
self.frontend_listener.broadcast(event).await;

0 commit comments

Comments
 (0)