Skip to content

Commit 9561358

Browse files
committed
Populate dashboard lazily; add wasm wrapper code
1 parent bffaa44 commit 9561358

File tree

8 files changed

+299
-175
lines changed

8 files changed

+299
-175
lines changed

alvr/dashboard/src/dashboard/components/connections.rs

Lines changed: 104 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
theme::{self, log_colors},
44
};
55
use alvr_packets::ClientListAction;
6-
use alvr_session::SessionDesc;
6+
use alvr_session::{ClientConnectionDesc, SessionDesc};
77
use eframe::{
88
egui::{Frame, Grid, Layout, RichText, TextEdit, Ui, Window},
99
emath::{Align, Align2},
@@ -18,23 +18,38 @@ struct EditPopupState {
1818
}
1919

2020
pub struct ConnectionsTab {
21+
new_clients: Option<Vec<(String, ClientConnectionDesc)>>,
22+
trusted_clients: Option<Vec<(String, ClientConnectionDesc)>>,
2123
edit_popup_state: Option<EditPopupState>,
2224
}
2325

2426
impl ConnectionsTab {
2527
pub fn new() -> Self {
2628
Self {
29+
new_clients: None,
30+
trusted_clients: None,
2731
edit_popup_state: None,
2832
}
2933
}
3034

31-
pub fn ui(
32-
&mut self,
33-
ui: &mut Ui,
34-
session: &SessionDesc,
35-
connected_to_server: bool,
36-
) -> Option<ServerRequest> {
37-
let mut response = None;
35+
pub fn update_client_list(&mut self, session: &SessionDesc) {
36+
let (trusted_clients, untrusted_clients) =
37+
session
38+
.client_connections
39+
.clone()
40+
.into_iter()
41+
.partition::<Vec<_>, _>(|(_, data)| data.trusted);
42+
43+
self.trusted_clients = Some(trusted_clients);
44+
self.new_clients = Some(untrusted_clients);
45+
}
46+
47+
pub fn ui(&mut self, ui: &mut Ui, connected_to_server: bool) -> Vec<ServerRequest> {
48+
let mut requests = vec![];
49+
50+
if self.new_clients.is_none() {
51+
requests.push(ServerRequest::GetSession);
52+
}
3853

3954
if !connected_to_server {
4055
Frame::group(ui.style())
@@ -61,91 +76,90 @@ impl ConnectionsTab {
6176
});
6277
}
6378

64-
// Get the different types of clients from the session
65-
let (trusted_clients, untrusted_clients) = session
66-
.client_connections
67-
.iter()
68-
.partition::<Vec<_>, _>(|(_, data)| data.trusted);
69-
7079
ui.vertical_centered_justified(|ui| {
71-
Frame::group(ui.style())
72-
.fill(theme::SECTION_BG)
73-
.show(ui, |ui| {
74-
ui.vertical_centered_justified(|ui| {
75-
ui.add_space(5.0);
76-
ui.heading("New clients");
77-
});
80+
if let Some(clients) = &self.new_clients {
81+
Frame::group(ui.style())
82+
.fill(theme::SECTION_BG)
83+
.show(ui, |ui| {
84+
ui.vertical_centered_justified(|ui| {
85+
ui.add_space(5.0);
86+
ui.heading("New clients");
87+
});
7888

79-
Grid::new(1).num_columns(2).show(ui, |ui| {
80-
for (hostname, _) in untrusted_clients {
81-
ui.horizontal(|ui| {
82-
ui.add_space(10.0);
83-
ui.label(hostname);
84-
});
85-
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
86-
if ui.button("Trust").clicked() {
87-
response = Some(ServerRequest::UpdateClientList {
88-
hostname: hostname.clone(),
89-
action: ClientListAction::Trust,
90-
});
91-
};
92-
});
93-
ui.end_row();
94-
}
95-
})
96-
});
89+
Grid::new(1).num_columns(2).show(ui, |ui| {
90+
for (hostname, _) in clients {
91+
ui.horizontal(|ui| {
92+
ui.add_space(10.0);
93+
ui.label(hostname);
94+
});
95+
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
96+
if ui.button("Trust").clicked() {
97+
requests.push(ServerRequest::UpdateClientList {
98+
hostname: hostname.clone(),
99+
action: ClientListAction::Trust,
100+
});
101+
};
102+
});
103+
ui.end_row();
104+
}
105+
})
106+
});
107+
}
97108

98109
ui.add_space(10.0);
99110

100-
Frame::group(ui.style())
101-
.fill(theme::SECTION_BG)
102-
.show(ui, |ui| {
103-
ui.vertical_centered_justified(|ui| {
104-
ui.add_space(5.0);
105-
ui.heading("Trusted clients");
106-
});
111+
if let Some(clients) = &self.trusted_clients {
112+
Frame::group(ui.style())
113+
.fill(theme::SECTION_BG)
114+
.show(ui, |ui| {
115+
ui.vertical_centered_justified(|ui| {
116+
ui.add_space(5.0);
117+
ui.heading("Trusted clients");
118+
});
107119

108-
Grid::new(2).num_columns(2).show(ui, |ui| {
109-
for (hostname, data) in trusted_clients {
110-
ui.horizontal(|ui| {
111-
ui.add_space(10.0);
112-
ui.label(format!(
113-
"{hostname}: {} ({})",
114-
data.current_ip.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
115-
data.display_name
116-
));
117-
});
118-
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
119-
if ui.button("Remove").clicked() {
120-
response = Some(ServerRequest::UpdateClientList {
121-
hostname: hostname.clone(),
122-
action: ClientListAction::RemoveEntry,
123-
});
124-
}
125-
if ui.button("Edit").clicked() {
126-
self.edit_popup_state = Some(EditPopupState {
127-
new_client: false,
128-
hostname: hostname.to_owned(),
129-
ips: data
130-
.manual_ips
131-
.iter()
132-
.map(|addr| addr.to_string())
133-
.collect::<Vec<String>>(),
134-
});
135-
}
120+
Grid::new(2).num_columns(2).show(ui, |ui| {
121+
for (hostname, data) in clients {
122+
ui.horizontal(|ui| {
123+
ui.add_space(10.0);
124+
ui.label(format!(
125+
"{hostname}: {} ({})",
126+
data.current_ip
127+
.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
128+
data.display_name
129+
));
130+
});
131+
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
132+
if ui.button("Remove").clicked() {
133+
requests.push(ServerRequest::UpdateClientList {
134+
hostname: hostname.clone(),
135+
action: ClientListAction::RemoveEntry,
136+
});
137+
}
138+
if ui.button("Edit").clicked() {
139+
self.edit_popup_state = Some(EditPopupState {
140+
new_client: false,
141+
hostname: hostname.to_owned(),
142+
ips: data
143+
.manual_ips
144+
.iter()
145+
.map(|addr| addr.to_string())
146+
.collect::<Vec<String>>(),
147+
});
148+
}
149+
});
150+
ui.end_row();
151+
}
152+
});
153+
154+
if ui.button("Add client manually").clicked() {
155+
self.edit_popup_state = Some(EditPopupState {
156+
hostname: "XXXX.client.alvr".into(),
157+
new_client: true,
158+
ips: Vec::new(),
136159
});
137-
ui.end_row();
138160
}
139161
});
140-
141-
if ui.button("Add client manually").clicked() {
142-
self.edit_popup_state = Some(EditPopupState {
143-
hostname: "XXXX.client.alvr".into(),
144-
new_client: true,
145-
ips: Vec::new(),
146-
});
147-
}
148-
});
162+
}
149163
});
150164

151165
if let Some(mut state) = self.edit_popup_state.take() {
@@ -165,7 +179,7 @@ impl ConnectionsTab {
165179
ui[1].text_edit_singleline(address);
166180
}
167181
if ui[1].button("Add new").clicked() {
168-
state.ips.push("192.168.1.2".to_string());
182+
state.ips.push("192.168.X.X".to_string());
169183
}
170184
});
171185
ui.columns(2, |ui| {
@@ -174,16 +188,16 @@ impl ConnectionsTab {
174188
state.ips.iter().filter_map(|s| s.parse().ok()).collect();
175189

176190
if state.new_client {
177-
response = Some(ServerRequest::UpdateClientList {
178-
hostname: state.hostname.clone(),
191+
requests.push(ServerRequest::UpdateClientList {
192+
hostname: state.hostname,
179193
action: ClientListAction::AddIfMissing {
180194
trusted: true,
181195
manual_ips,
182196
},
183197
});
184198
} else {
185-
response = Some(ServerRequest::UpdateClientList {
186-
hostname: state.hostname.clone(),
199+
requests.push(ServerRequest::UpdateClientList {
200+
hostname: state.hostname,
187201
action: ClientListAction::SetManualIps(manual_ips),
188202
});
189203
}
@@ -194,6 +208,6 @@ impl ConnectionsTab {
194208
});
195209
}
196210

197-
response
211+
requests
198212
}
199213
}

alvr/dashboard/src/dashboard/components/installation.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use eframe::{
44
egui::{Frame, Grid, Layout, RichText, Ui},
55
emath::Align,
66
};
7-
use std::path::PathBuf;
7+
use std::{
8+
path::PathBuf,
9+
time::{Duration, Instant},
10+
};
11+
12+
const DRIVER_UPDATE_INTERVAL: Duration = Duration::from_secs(1);
813

914
pub enum InstallationTabRequest {
1015
OpenSetupWizard,
@@ -13,11 +18,15 @@ pub enum InstallationTabRequest {
1318

1419
pub struct InstallationTab {
1520
drivers: Vec<PathBuf>,
21+
last_update_instant: Instant,
1622
}
1723

1824
impl InstallationTab {
1925
pub fn new() -> Self {
20-
Self { drivers: vec![] }
26+
Self {
27+
drivers: vec![],
28+
last_update_instant: Instant::now(),
29+
}
2130
}
2231

2332
pub fn update_drivers(&mut self, list: Vec<PathBuf>) {
@@ -26,6 +35,16 @@ impl InstallationTab {
2635

2736
pub fn ui(&mut self, ui: &mut Ui) -> Vec<InstallationTabRequest> {
2837
let mut requests = vec![];
38+
39+
let now = Instant::now();
40+
if now > self.last_update_instant + DRIVER_UPDATE_INTERVAL {
41+
requests.push(InstallationTabRequest::ServerRequest(
42+
ServerRequest::GetDriverList,
43+
));
44+
45+
self.last_update_instant = now;
46+
}
47+
2948
ui.vertical_centered_justified(|ui| {
3049
if ui.button("Run setup wizard").clicked() {
3150
requests.push(InstallationTabRequest::OpenSetupWizard);
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
mod about;
22
mod connections;
33
mod debug;
4-
mod installation;
54
mod logs;
65
mod notifications;
76
mod settings;
87
mod settings_controls;
98
mod setup_wizard;
109
mod statistics;
1110

11+
#[cfg(not(target_arch = "wasm32"))]
12+
mod installation;
13+
1214
pub use about::*;
1315
pub use connections::*;
1416
pub use debug::*;
15-
pub use installation::*;
1617
pub use logs::*;
1718
pub use notifications::*;
1819
pub use settings::*;
1920
pub use settings_controls::*;
2021
pub use setup_wizard::*;
2122
pub use statistics::*;
23+
24+
#[cfg(not(target_arch = "wasm32"))]
25+
pub use installation::*;

0 commit comments

Comments
 (0)