mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-06-28 11:14:50 +03:00
automatically update config when changed (#402)
This commit is contained in:
committed by
GitHub
parent
aef05f386f
commit
a878c985f0
@@ -9,6 +9,8 @@ use slab::Slab;
|
||||
|
||||
use lan_mouse_ipc::{ClientConfig, ClientHandle, ClientState, Position};
|
||||
|
||||
use crate::config::ConfigClient;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ClientManager {
|
||||
clients: Rc<RefCell<Slab<(ClientConfig, ClientState)>>>,
|
||||
@@ -24,6 +26,25 @@ impl ClientManager {
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn add_with_config(&self, config_client: ConfigClient) -> ClientHandle {
|
||||
let config = ClientConfig {
|
||||
hostname: config_client.hostname,
|
||||
fix_ips: config_client.ips.into_iter().collect(),
|
||||
port: config_client.port,
|
||||
pos: config_client.pos,
|
||||
cmd: config_client.enter_hook,
|
||||
};
|
||||
let state = ClientState {
|
||||
active: config_client.active,
|
||||
ips: HashSet::from_iter(config.fix_ips.iter().cloned()),
|
||||
..Default::default()
|
||||
};
|
||||
let handle = self.add_client();
|
||||
self.set_config(handle, config);
|
||||
self.set_state(handle, state);
|
||||
handle
|
||||
}
|
||||
|
||||
/// add a new client to this manager
|
||||
pub fn add_client(&self) -> ClientHandle {
|
||||
self.clients.borrow_mut().insert(Default::default()) as ClientHandle
|
||||
@@ -230,6 +251,15 @@ impl ClientManager {
|
||||
.and_then(|(c, _)| c.cmd.clone())
|
||||
}
|
||||
|
||||
/// returns all clients that are currently registered
|
||||
pub(crate) fn registered_clients(&self) -> Vec<ClientHandle> {
|
||||
self.clients
|
||||
.borrow()
|
||||
.iter()
|
||||
.map(|(h, _)| h as ClientHandle)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// returns all clients that are currently active
|
||||
pub(crate) fn active_clients(&self) -> Vec<ClientHandle> {
|
||||
self.clients
|
||||
|
||||
Reference in New Issue
Block a user