|
1 | 1 | use crate::{ |
2 | 2 | capture::{Capture, CaptureType, ICaptureEvent}, |
3 | 3 | client::ClientManager, |
4 | | - config::Config, |
| 4 | + config::{Config, ConfigClient}, |
5 | 5 | connect::LanMouseConnection, |
6 | 6 | crypto, |
7 | 7 | dns::{DnsEvent, DnsResolver}, |
@@ -39,6 +39,8 @@ pub enum ServiceError { |
39 | 39 | } |
40 | 40 |
|
41 | 41 | pub struct Service { |
| 42 | + /// configuration |
| 43 | + config: Config, |
42 | 44 | /// input capture |
43 | 45 | capture: Capture, |
44 | 46 | /// input emulation |
@@ -122,6 +124,7 @@ impl Service { |
122 | 124 |
|
123 | 125 | let port = config.port(); |
124 | 126 | let service = Self { |
| 127 | + config, |
125 | 128 | capture, |
126 | 129 | emulation, |
127 | 130 | frontend_listener, |
@@ -200,10 +203,29 @@ impl Service { |
200 | 203 | FrontendRequest::UpdateEnterHook(handle, enter_hook) => { |
201 | 204 | self.update_enter_hook(handle, enter_hook) |
202 | 205 | } |
203 | | - FrontendRequest::SaveConfiguration => todo!(), |
| 206 | + FrontendRequest::SaveConfiguration => self.save_config(), |
204 | 207 | } |
205 | 208 | } |
206 | 209 |
|
| 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 | + |
207 | 229 | async fn handle_frontend_pending(&mut self) { |
208 | 230 | while let Some(event) = self.pending_frontend_events.pop_front() { |
209 | 231 | self.frontend_listener.broadcast(event).await; |
|
0 commit comments