mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-26 06:30:56 +03:00
add setters for clients and authorized keys
This commit is contained in:
committed by
Ferdinand Schober
parent
a987f93133
commit
6d16747c19
@@ -253,6 +253,8 @@ pub enum FrontendRequest {
|
|||||||
RemoveAuthorizedKey(String),
|
RemoveAuthorizedKey(String),
|
||||||
/// change the hook command
|
/// change the hook command
|
||||||
UpdateEnterHook(u64, Option<String>),
|
UpdateEnterHook(u64, Option<String>),
|
||||||
|
/// save config file
|
||||||
|
SaveConfiguration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ fn default_path() -> Result<PathBuf, VarError> {
|
|||||||
Ok(PathBuf::from(default_path))
|
Ok(PathBuf::from(default_path))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
struct ConfigToml {
|
struct ConfigToml {
|
||||||
capture_backend: Option<CaptureBackend>,
|
capture_backend: Option<CaptureBackend>,
|
||||||
emulation_backend: Option<EmulationBackend>,
|
emulation_backend: Option<EmulationBackend>,
|
||||||
@@ -274,6 +274,33 @@ impl From<TomlClient> for ConfigClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ConfigClient> for TomlClient {
|
||||||
|
fn from(client: ConfigClient) -> Self {
|
||||||
|
let hostname = client.hostname;
|
||||||
|
let host_name = None;
|
||||||
|
let mut ips = client.ips.into_iter().collect::<Vec<_>>();
|
||||||
|
ips.sort();
|
||||||
|
let ips = Some(ips);
|
||||||
|
let port = if client.port == DEFAULT_PORT {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(client.port)
|
||||||
|
};
|
||||||
|
let position = Some(client.pos);
|
||||||
|
let activate_on_startup = if client.active { Some(true) } else { None };
|
||||||
|
let enter_hook = client.enter_hook;
|
||||||
|
Self {
|
||||||
|
hostname,
|
||||||
|
host_name,
|
||||||
|
ips,
|
||||||
|
port,
|
||||||
|
position,
|
||||||
|
activate_on_startup,
|
||||||
|
enter_hook,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
@@ -384,4 +411,24 @@ impl Config {
|
|||||||
.and_then(|c| c.release_bind.clone())
|
.and_then(|c| c.release_bind.clone())
|
||||||
.unwrap_or(Vec::from_iter(DEFAULT_RELEASE_KEYS.iter().cloned()))
|
.unwrap_or(Vec::from_iter(DEFAULT_RELEASE_KEYS.iter().cloned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// set configured clients
|
||||||
|
pub fn set_clients(&mut self, clients: Vec<ConfigClient>) {
|
||||||
|
if self.config_toml.is_none() {
|
||||||
|
self.config_toml = Default::default();
|
||||||
|
}
|
||||||
|
self.config_toml.as_mut().expect("config").clients =
|
||||||
|
clients.into_iter().map(|c| c.into()).collect::<Vec<_>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// set authorized keys
|
||||||
|
pub fn set_authorized_keys(&mut self, fingerprints: HashMap<String, String>) {
|
||||||
|
if self.config_toml.is_none() {
|
||||||
|
self.config_toml = Default::default();
|
||||||
|
}
|
||||||
|
self.config_toml
|
||||||
|
.as_mut()
|
||||||
|
.expect("config")
|
||||||
|
.authorized_fingerprints = Some(fingerprints);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ 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!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user