Added basic toggle - cabled mode for devices (#1877)

* Added basic toggle cabled mode for devices

* Remove unnecessary imports. Change link to specific adb topic.

* Reformat

* Reformat server_io lib.rs

* Changed cabled toggle wording

* WIP work on ui, better state handling

* Changed import, added mut to trusted clients

* Improved ui margins. Fixed toggle state being unused.

* Removed unused imports

* Added darker frame to New clients
This commit is contained in:
Meister1593 2023-11-02 08:07:29 +05:00 committed by GitHub
parent 7d627ca8fa
commit 0b47edc1b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 64 deletions

View File

@ -1,4 +1,4 @@
use crate::dashboard::ServerRequest;
use crate::dashboard::{basic_components, ServerRequest};
use alvr_gui_common::theme::{self, log_colors};
use alvr_packets::ClientListAction;
use alvr_session::{ClientConnectionConfig, ConnectionState, SessionConfig};
@ -83,30 +83,33 @@ impl ConnectionsTab {
ui.add_space(5.0);
ui.heading("New clients");
});
Grid::new(1).num_columns(2).show(ui, |ui| {
for (hostname, _) in clients {
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label(hostname);
for (hostname, _) in clients {
Frame::group(ui.style())
.fill(theme::DARKER_BG)
.show(ui, |ui| {
Grid::new(format!("{}-new-clients", hostname)).num_columns(2).show(ui, |ui| {
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label(hostname);
});
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.button("Trust").clicked() {
requests.push(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::Trust,
});
};
});
ui.end_row();
});
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.button("Trust").clicked() {
requests.push(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::Trust,
});
};
});
ui.end_row();
}
})
});
}
});
}
ui.add_space(10.0);
if let Some(clients) = &self.trusted_clients {
if let Some(clients) = &mut self.trusted_clients {
Frame::group(ui.style())
.fill(theme::SECTION_BG)
.show(ui, |ui| {
@ -115,54 +118,68 @@ impl ConnectionsTab {
ui.heading("Trusted clients");
});
Grid::new(2).num_columns(2).show(ui, |ui| {
for (hostname, data) in clients {
ui.horizontal(|ui| {
ui.vertical(|ui| {
for (hostname,data) in clients {
Frame::group(ui.style())
.fill(theme::DARKER_BG)
.show(ui, |ui| {
ui.add_space(10.0);
ui.label(format!(
"{hostname}: {} ({})",
data.current_ip
.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
data.display_name
));
match data.connection_state {
ConnectionState::Disconnected => {
ui.colored_label(Color32::GRAY, "Disconnected")
}
ConnectionState::Connecting => ui
.colored_label(log_colors::WARNING_LIGHT, "Connecting"),
ConnectionState::Connected => {
ui.colored_label(theme::OK_GREEN, "Connected")
}
ConnectionState::Streaming => {
ui.colored_label(theme::OK_GREEN, "Streaming")
}
ConnectionState::Disconnecting { .. } => ui.colored_label(
log_colors::WARNING_LIGHT,
"Disconnecting",
),
}
});
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.button("Remove").clicked() {
requests.push(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::RemoveEntry,
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label(format!("{hostname}: {} ({})", data.current_ip.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)), data.display_name));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add_space(10.0);
match data.connection_state {
ConnectionState::Disconnected => {
ui.colored_label(Color32::GRAY, "Disconnected")
}
ConnectionState::Connecting => ui
.colored_label(log_colors::WARNING_LIGHT, "Connecting"),
ConnectionState::Connected => {
ui.colored_label(theme::OK_GREEN, "Connected")
}
ConnectionState::Streaming => {
ui.colored_label(theme::OK_GREEN, "Streaming")
}
ConnectionState::Disconnecting { .. } => ui.colored_label(
log_colors::WARNING_LIGHT,
"Disconnecting",
),
}
});
}
if ui.button("Edit").clicked() {
self.edit_popup_state = Some(EditPopupState {
new_client: false,
hostname: hostname.to_owned(),
ips: data
.manual_ips
.iter()
.map(|addr| addr.to_string())
.collect::<Vec<String>>(),
});
Grid::new(format!("{}-clients", hostname)).num_columns(2).show(ui, |ui| {
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.hyperlink_to("Use Cable:", "https://github.com/alvr-org/ALVR/wiki/ALVR-wired-setup-(ALVR-over-USB)#letting-your-pc-communicate-with-your-hmd");
if basic_components::switch(ui, &mut data.cabled).changed() {
requests.push(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::SetCabled(data.cabled),
});
}
});
}
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add_space(10.0);
if ui.button("Remove").clicked() {
requests.push(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::RemoveEntry,
});
}
if ui.button("Edit").clicked() {
self.edit_popup_state = Some(EditPopupState {
new_client: false,
hostname: hostname.to_owned(),
ips: data.manual_ips
.iter()
.map(|addr| addr.to_string())
.collect::<Vec<String>>(),
});
}
});
});
});
ui.end_row();
}
});

View File

@ -188,6 +188,7 @@ pub enum ClientListAction {
RemoveEntry,
UpdateCurrentIp(Option<IpAddr>),
SetConnectionState(ConnectionState),
SetCabled(bool),
}
#[derive(Serialize, Deserialize, Default, Clone)]

View File

@ -12,12 +12,15 @@ use alvr_common::{
};
use alvr_events::EventType;
use alvr_packets::{AudioDevicesList, ClientListAction, PathSegment, PathValuePair};
use alvr_session::{ClientConnectionConfig, ConnectionState, SessionConfig, Settings};
use alvr_session::{
ClientConnectionConfig, ConnectionState, SessionConfig, Settings, SocketProtocolDefaultVariant,
};
use cpal::traits::{DeviceTrait, HostTrait};
use serde_json as json;
use std::{
collections::{hash_map::Entry, HashMap},
fs,
net::{IpAddr, Ipv4Addr},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
};
@ -203,6 +206,7 @@ impl ServerDataManager {
manual_ips: manual_ips.into_iter().collect(),
trusted,
connection_state: ConnectionState::Disconnected,
cabled: false,
};
new_entry.insert(client_connection_desc);
@ -255,6 +259,40 @@ impl ServerDataManager {
}
}
}
ClientListAction::SetCabled(state) => {
if let Entry::Occupied(mut entry) = maybe_client_entry {
entry.get_mut().cabled = state;
if entry.get().cabled {
entry
.get_mut()
.manual_ips
.insert(IpAddr::V4(Ipv4Addr::LOCALHOST));
self.session
.session_settings
.connection
.client_discovery
.enabled = false;
self.session
.session_settings
.connection
.stream_protocol
.variant = SocketProtocolDefaultVariant::Tcp;
} else {
entry
.get_mut()
.manual_ips
.remove(&IpAddr::V4(Ipv4Addr::LOCALHOST));
self.session
.session_settings
.connection
.client_discovery
.enabled = true;
}
updated = true;
}
}
}
if updated {

View File

@ -116,6 +116,7 @@ pub struct ClientConnectionConfig {
pub manual_ips: HashSet<IpAddr>,
pub trusted: bool,
pub connection_state: ConnectionState,
pub cabled: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug)]