@@ -125,35 +125,14 @@ public HomePageViewModel(Settings settings, ActivityHistory history, MainViewMod
125125 _settings = settings ;
126126 _mainViewModel = mainViewModel ;
127127
128- // Get status
129128 LoadStatusCard ( ) ;
130-
131- // Get WiFi information
132- string ? ssid = NetworkHelper . GetCurrentWifiSSID ( ) ;
133- int signalQuality = ssid != null ? NetworkHelper . GetCurrentNetwork ( ) . SignalQuality : 0 ;
134- WiFiName = ssid ?? ( connected ? Properties . Resources . Ethernet : Properties . Resources . NotConnectedS ) ;
135- WiFiIcon = ssid != null ? GetWiFiIcon ( signalQuality ) : ( connected ? "\uF35A " : "\uFB69 " ) ;
136- WiFiStrengthText = $ "{ Properties . Resources . SignalQuality } - { ( ssid != null ? signalQuality : 100 ) } %";
137-
138- // Get IP address
129+ LoadWiFiInfo ( ) ;
139130 LoadIpAddress ( ) ;
140131
141132 // Network speed
142- Speed = $ "~{ NetworkHelper . GetCurrentSpeed ( ) } Mbps";
143-
144- // Load connection details
145- var networkInterface = NetworkInterface . GetAllNetworkInterfaces ( )
146- . Where ( x => x . OperationalStatus == OperationalStatus . Up )
147- . OrderByDescending ( x => x . GetIPStatistics ( ) . BytesReceived )
148- . FirstOrDefault ( ) ;
149- if ( networkInterface != null )
150- {
151- var ipProps = WindowsIpConfig . FromNetworkInterface ( networkInterface ) ;
133+ Speed = connected ? $ "~{ NetworkHelper . GetCurrentSpeed ( ) } Mbps" : Properties . Resources . Unknown ;
152134
153- LocalIp = ipProps ? . IPv4Address ?? Properties . Resources . Unknown ;
154- Gateway = ipProps ? . IPv4Gateway ?? Properties . Resources . Unknown ;
155- Dns = string . Join ( "\n " , networkInterface . GetIPProperties ( ) . DnsAddresses . Select ( x => x . ToString ( ) . Replace ( "%16" , "" ) ) ) ?? Properties . Resources . Unknown ;
156- }
135+ LoadConnectionDetails ( ) ;
157136
158137 // Load history
159138 History = new ( history . Activity . OrderByDescending ( x => x . Date ) . Select ( x => new HistoryItemViewModel ( x ) ) ) ;
@@ -183,9 +162,35 @@ internal async void LoadStatusCard()
183162 return ;
184163 }
185164
186- connected = await Internet . IsAvailableAsync ( _settings . TestSite ) ;
187- StatusText = connected ? Properties . Resources . ConnectedS : Properties . Resources . NotConnectedS ;
188- StatusColor = connected ? ThemeHelper . GetSolidColorBrush ( "Green" ) : ThemeHelper . GetSolidColorBrush ( "Red" ) ;
165+ try
166+ {
167+ connected = await Internet . IsAvailableAsync ( _settings . TestSite ) ;
168+ StatusText = connected ? Properties . Resources . ConnectedS : Properties . Resources . NotConnectedS ;
169+ StatusColor = connected ? ThemeHelper . GetSolidColorBrush ( "Green" ) : ThemeHelper . GetSolidColorBrush ( "Red" ) ;
170+ }
171+ catch
172+ {
173+ connected = false ;
174+ StatusText = connected ? Properties . Resources . ConnectedS : Properties . Resources . NotConnectedS ;
175+ StatusColor = connected ? ThemeHelper . GetSolidColorBrush ( "Green" ) : ThemeHelper . GetSolidColorBrush ( "Red" ) ;
176+ }
177+ }
178+
179+ private void LoadWiFiInfo ( )
180+ {
181+ try
182+ {
183+ string ? ssid = NetworkHelper . GetCurrentWifiSSID ( ) ;
184+ int signalQuality = ssid != null ? NetworkHelper . GetCurrentNetwork ( ) . SignalQuality : 0 ;
185+ WiFiName = ssid ?? ( connected ? Properties . Resources . Ethernet : Properties . Resources . NotConnectedS ) ;
186+ WiFiIcon = ssid != null ? GetWiFiIcon ( signalQuality ) : ( connected ? "\uF35A " : "\uFB69 " ) ;
187+ WiFiStrengthText = $ "{ Properties . Resources . SignalQuality } - { ( ssid != null ? signalQuality : 100 ) } %";
188+ }
189+ catch
190+ {
191+ WiFiName = connected ? Properties . Resources . Ethernet : Properties . Resources . NotConnectedS ;
192+ WiFiStrengthText = Properties . Resources . Unknown ;
193+ }
189194 }
190195
191196 private static string GetWiFiIcon ( int signalQuality ) => signalQuality switch
@@ -196,6 +201,31 @@ internal async void LoadStatusCard()
196201 _ => "\uF8B3 "
197202 } ;
198203
204+ private void LoadConnectionDetails ( )
205+ {
206+ try
207+ {
208+ var networkInterface = NetworkInterface . GetAllNetworkInterfaces ( )
209+ . Where ( x => x . OperationalStatus == OperationalStatus . Up )
210+ . OrderByDescending ( x => x . GetIPStatistics ( ) . BytesReceived )
211+ . FirstOrDefault ( ) ;
212+ if ( networkInterface != null )
213+ {
214+ var ipProps = WindowsIpConfig . FromNetworkInterface ( networkInterface ) ;
215+
216+ LocalIp = ipProps ? . IPv4Address ?? Properties . Resources . Unknown ;
217+ Gateway = ipProps ? . IPv4Gateway ?? Properties . Resources . Unknown ;
218+ Dns = string . Join ( "\n " , networkInterface . GetIPProperties ( ) . DnsAddresses . Select ( x => x . ToString ( ) . Replace ( "%16" , "" ) ) ) ?? Properties . Resources . Unknown ;
219+ }
220+ }
221+ catch
222+ {
223+ LocalIp = Properties . Resources . Unknown ;
224+ Gateway = Properties . Resources . Unknown ;
225+ Dns = Properties . Resources . Unknown ;
226+ }
227+ }
228+
199229 void ISensitiveViewModel . ToggleConfidentialMode ( bool confidentialMode )
200230 {
201231 ConfidentialMode = confidentialMode ;
0 commit comments