@@ -60,9 +60,7 @@ impl Adapter {
60
60
pub fn render ( & self , frame : & mut Frame , color_mode : ColorMode , focused_block : FocusedBlock ) {
61
61
match self . device . mode {
62
62
Mode :: Station => {
63
- if self . device . station . is_some ( ) {
64
- self . render_station_mode ( frame, color_mode, focused_block) ;
65
- }
63
+ self . render_station_mode ( frame, color_mode, focused_block) ;
66
64
}
67
65
Mode :: Ap => {
68
66
if self . device . access_point . is_some ( ) {
@@ -589,18 +587,15 @@ impl Adapter {
589
587
}
590
588
} ;
591
589
590
+ let mut station_state = "" . to_string ( ) ;
591
+ let mut station_is_scanning = "" . to_string ( ) ;
592
+ if let Some ( station) = self . device . station . as_ref ( ) {
593
+ station_state = station. state . clone ( ) ;
594
+ station_is_scanning = station. is_scanning . clone ( ) . to_string ( ) ;
595
+ }
592
596
let row = vec ! [
593
- Line :: from( self . device. station. as_ref( ) . unwrap( ) . state. clone( ) ) . centered( ) ,
594
- Line :: from(
595
- self . device
596
- . station
597
- . as_ref( )
598
- . unwrap( )
599
- . is_scanning
600
- . clone( )
601
- . to_string( ) ,
602
- )
603
- . centered( ) ,
597
+ Line :: from( station_state) . centered( ) ,
598
+ Line :: from( station_is_scanning) . centered( ) ,
604
599
Line :: from( station_frequency) . centered( ) ,
605
600
Line :: from( station_security) . centered( ) ,
606
601
] ;
@@ -699,13 +694,12 @@ impl Adapter {
699
694
frame. render_stateful_widget ( station_table, station_block, & mut station_state) ;
700
695
701
696
// Known networks
702
-
703
- let rows: Vec < Row > = self
704
- . device
705
- . station
706
- . as_ref ( )
707
- . unwrap ( )
708
- . known_networks
697
+ let known_networks = if let Some ( station) = self . device . station . as_ref ( ) {
698
+ & station. known_networks
699
+ } else {
700
+ & vec ! [ ]
701
+ } ;
702
+ let rows: Vec < Row > = known_networks
709
703
. iter ( )
710
704
. map ( |( net, signal) | {
711
705
let net = net. known_network . as_ref ( ) . unwrap ( ) ;
@@ -857,26 +851,24 @@ impl Adapter {
857
851
Style :: default ( )
858
852
} ) ;
859
853
854
+ let mut known_networks_state = if let Some ( station) = self . device . station . as_ref ( ) {
855
+ station. known_networks_state . clone ( )
856
+ } else {
857
+ TableState :: default ( )
858
+ } ;
860
859
frame. render_stateful_widget (
861
860
known_networks_table,
862
861
known_networks_block,
863
- & mut self
864
- . device
865
- . station
866
- . as_ref ( )
867
- . unwrap ( )
868
- . known_networks_state
869
- . clone ( ) ,
862
+ & mut known_networks_state,
870
863
) ;
871
864
872
865
// New networks
873
-
874
- let rows: Vec < Row > = self
875
- . device
876
- . station
877
- . as_ref ( )
878
- . unwrap ( )
879
- . new_networks
866
+ let new_networks = if let Some ( station) = self . device . station . as_ref ( ) {
867
+ & station. new_networks
868
+ } else {
869
+ & vec ! [ ]
870
+ } ;
871
+ let rows: Vec < Row > = new_networks
880
872
. iter ( )
881
873
. map ( |( net, signal) | {
882
874
Row :: new ( vec ! [
@@ -982,16 +974,15 @@ impl Adapter {
982
974
Style :: default ( )
983
975
} ) ;
984
976
977
+ let mut new_networks_state = if let Some ( station) = self . device . station . as_ref ( ) {
978
+ station. new_networks_state . clone ( )
979
+ } else {
980
+ TableState :: default ( )
981
+ } ;
985
982
frame. render_stateful_widget (
986
983
new_networks_table,
987
984
new_networks_block,
988
- & mut self
989
- . device
990
- . station
991
- . as_ref ( )
992
- . unwrap ( )
993
- . new_networks_state
994
- . clone ( ) ,
985
+ & mut new_networks_state,
995
986
) ;
996
987
}
997
988
0 commit comments