@@ -3,7 +3,7 @@ use crate::{
3
3
theme:: { self , log_colors} ,
4
4
} ;
5
5
use alvr_packets:: ClientListAction ;
6
- use alvr_session:: SessionDesc ;
6
+ use alvr_session:: { ClientConnectionDesc , SessionDesc } ;
7
7
use eframe:: {
8
8
egui:: { Frame , Grid , Layout , RichText , TextEdit , Ui , Window } ,
9
9
emath:: { Align , Align2 } ,
@@ -18,23 +18,38 @@ struct EditPopupState {
18
18
}
19
19
20
20
pub struct ConnectionsTab {
21
+ new_clients : Option < Vec < ( String , ClientConnectionDesc ) > > ,
22
+ trusted_clients : Option < Vec < ( String , ClientConnectionDesc ) > > ,
21
23
edit_popup_state : Option < EditPopupState > ,
22
24
}
23
25
24
26
impl ConnectionsTab {
25
27
pub fn new ( ) -> Self {
26
28
Self {
29
+ new_clients : None ,
30
+ trusted_clients : None ,
27
31
edit_popup_state : None ,
28
32
}
29
33
}
30
34
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
+ }
38
53
39
54
if !connected_to_server {
40
55
Frame :: group ( ui. style ( ) )
@@ -61,91 +76,90 @@ impl ConnectionsTab {
61
76
} ) ;
62
77
}
63
78
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
-
70
79
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
+ } ) ;
78
88
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
+ }
97
108
98
109
ui. add_space ( 10.0 ) ;
99
110
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
+ } ) ;
107
119
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 ( ) ,
136
159
} ) ;
137
- ui. end_row ( ) ;
138
160
}
139
161
} ) ;
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
+ }
149
163
} ) ;
150
164
151
165
if let Some ( mut state) = self . edit_popup_state . take ( ) {
@@ -165,7 +179,7 @@ impl ConnectionsTab {
165
179
ui[ 1 ] . text_edit_singleline ( address) ;
166
180
}
167
181
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 ( ) ) ;
169
183
}
170
184
} ) ;
171
185
ui. columns ( 2 , |ui| {
@@ -174,16 +188,16 @@ impl ConnectionsTab {
174
188
state. ips . iter ( ) . filter_map ( |s| s. parse ( ) . ok ( ) ) . collect ( ) ;
175
189
176
190
if state. new_client {
177
- response = Some ( ServerRequest :: UpdateClientList {
178
- hostname : state. hostname . clone ( ) ,
191
+ requests . push ( ServerRequest :: UpdateClientList {
192
+ hostname : state. hostname ,
179
193
action : ClientListAction :: AddIfMissing {
180
194
trusted : true ,
181
195
manual_ips,
182
196
} ,
183
197
} ) ;
184
198
} else {
185
- response = Some ( ServerRequest :: UpdateClientList {
186
- hostname : state. hostname . clone ( ) ,
199
+ requests . push ( ServerRequest :: UpdateClientList {
200
+ hostname : state. hostname ,
187
201
action : ClientListAction :: SetManualIps ( manual_ips) ,
188
202
} ) ;
189
203
}
@@ -194,6 +208,6 @@ impl ConnectionsTab {
194
208
} ) ;
195
209
}
196
210
197
- response
211
+ requests
198
212
}
199
213
}
0 commit comments