Gtk frontend rework (#276)

client configuration now applies immediately instead of after enabling / disabling clients.
Also fixes a potential feedback loop when changing settings.
This commit is contained in:
Ferdinand Schober
2025-03-15 01:21:53 +01:00
committed by GitHub
parent f247300f8c
commit 50a778452e
10 changed files with 363 additions and 245 deletions

View File

@@ -38,7 +38,6 @@ pub struct ConfigToml {
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct TomlClient {
pub capture_backend: Option<CaptureBackend>,
pub hostname: Option<String>,
pub host_name: Option<String>,
pub ips: Option<Vec<IpAddr>>,

View File

@@ -186,7 +186,6 @@ impl Service {
FrontendRequest::EnableCapture => self.capture.reenable(),
FrontendRequest::EnableEmulation => self.emulation.reenable(),
FrontendRequest::Enumerate() => self.enumerate(),
FrontendRequest::GetState(handle) => self.broadcast_client(handle),
FrontendRequest::UpdateFixIps(handle, fix_ips) => self.update_fix_ips(handle, fix_ips),
FrontendRequest::UpdateHostname(handle, host) => self.update_hostname(handle, host),
FrontendRequest::UpdatePort(handle, port) => self.update_port(handle, port),
@@ -283,7 +282,7 @@ impl Service {
handle
}
};
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
}
fn resolve(&self, handle: ClientHandle) {
@@ -399,7 +398,7 @@ impl Service {
log::debug!("deactivating client {handle}");
if self.client_manager.deactivate_client(handle) {
self.capture.destroy(handle);
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
log::info!("deactivated client {handle}");
}
}
@@ -425,7 +424,7 @@ impl Service {
if self.client_manager.activate_client(handle) {
/* notify capture and frontends */
self.capture.create(handle, pos, CaptureType::Default);
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
log::info!("activated client {handle} ({pos})");
}
}
@@ -452,19 +451,20 @@ impl Service {
fn update_fix_ips(&mut self, handle: ClientHandle, fix_ips: Vec<IpAddr>) {
self.client_manager.set_fix_ips(handle, fix_ips);
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
}
fn update_hostname(&mut self, handle: ClientHandle, hostname: Option<String>) {
log::info!("hostname changed: {hostname:?}");
if self.client_manager.set_hostname(handle, hostname.clone()) {
self.resolve(handle);
}
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
}
fn update_port(&mut self, handle: ClientHandle, port: u16) {
self.client_manager.set_port(handle, port);
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
}
fn update_pos(&mut self, handle: ClientHandle, pos: Position) {
@@ -473,7 +473,7 @@ impl Service {
self.deactivate_client(handle);
self.activate_client(handle);
}
self.notify_frontend(FrontendEvent::Changed(handle));
self.broadcast_client(handle);
}
fn broadcast_client(&mut self, handle: ClientHandle) {