@@ -123,7 +123,7 @@ await Execute.OnUIThreadAsync(() =>
123123 true => PingStatus . Success ,
124124 _ => PingStatus . Failed
125125 } ;
126- Task . Delay ( 200 ) . Wait ( ) ; // 避免界面关闭太快,根本看不清
126+ Task . Delay ( 200 , cts . Token ) . Wait ( cts . Token ) ; // 避免界面关闭太快,根本看不清
127127 return ret ;
128128 } , cts . Token ) ) ;
129129 }
@@ -212,46 +212,51 @@ await Execute.OnUIThreadAsync(() =>
212212 private static async Task < Credential ? > GetCredential ( ProtocolBaseWithAddressPort protocol , string assignCredentialName )
213213 {
214214 var newCredential = protocol . GetCredential ( ) ;
215- newCredential . Name = "default" ;
215+ newCredential . Name = protocol . DisplayName ;
216216 // use assign credential 应用指定的 credential
217217 var assignCredential = protocol . AlternateCredentials . FirstOrDefault ( x => x . Name == assignCredentialName ) ;
218218 if ( assignCredential != null )
219219 {
220220 SimpleLogHelper . Debug ( "using assign credential: " + assignCredentialName ) ;
221221 newCredential . SetCredential ( assignCredential ) ;
222+ newCredential . Name = $ "{ protocol . DisplayName } ({ assignCredentialName } )";
222223 }
223224
224-
225- // check if need to ping before connect
225+ // check if it needs to ping before connect
226226 bool isPingBeforeConnect = protocol . IsPingBeforeConnect == true
227227 // do not ping if rdp protocol and gateway is used
228228 && protocol is not RDP { GatewayMode : EGatewayMode . UseTheseGatewayServerSettings } ;
229+ // check if it needs to auto switch address
229230 var isAutoAlternateAddressSwitching = protocol . IsAutoAlternateAddressSwitching == true
230231 // if any host or port in assignCredential,then disabled `AutoAlternateAddressSwitching`
231232 && string . IsNullOrEmpty ( assignCredential ? . Address ) && string . IsNullOrEmpty ( assignCredential ? . Port )
232233 // if none of the alternate credential has host or port,then disabled `AutoAlternateAddressSwitching`
233234 && protocol . AlternateCredentials . Any ( x => ! string . IsNullOrEmpty ( x . Address ) || ! string . IsNullOrEmpty ( x . Port ) ) ;
234235
235- // if both `IsPingBeforeConnect` and `IsAutoAlternateAddressSwitching` are false, then return directly
236- if ( isPingBeforeConnect == false && isAutoAlternateAddressSwitching == false )
237- return newCredential ;
238-
239- if ( protocol is LocalApp app && app . ShowAddressInput ( ) == false )
236+ if (
237+ // if both `IsPingBeforeConnect` and `IsAutoAlternateAddressSwitching` are false, then return directly
238+ ( isPingBeforeConnect == false && isAutoAlternateAddressSwitching == false )
239+ // if LocalApp protocol are not showing address input, then return directly
240+ || ( protocol is LocalApp app && app . ShowAddressInput ( ) == false ) )
241+ {
240242 return newCredential ;
243+ }
241244
242245 // a quick test for the first credential, if pass return directly to avoid window pop
243246 var ret = await TcpHelper . TestConnectionAsync ( newCredential . Address , newCredential . Port , null , 100 ) ;
244247 if ( ret == true )
245248 return newCredential ;
246249
247250 var credentials = new List < Credential > { newCredential } ;
251+ // if `IsAutoAlternateAddressSwitching` is true, then add all alternate credentials, else only add the main address to ping
248252 if ( isAutoAlternateAddressSwitching )
249253 credentials . AddRange ( protocol . AlternateCredentials . Where ( x => ! string . IsNullOrEmpty ( x . Address ) || ! string . IsNullOrEmpty ( x . Port ) ) ) ;
250254
255+ // find the first response address from `credentials`
251256 var connectableAddress = await FindFirstConnectableAddressAsync ( credentials , protocol . DisplayName ) ;
252257 if ( connectableAddress != null )
253258 {
254- newCredential . Name = connectableAddress . Name ;
259+ newCredential . Name = $ " { protocol . DisplayName } ( { connectableAddress . Name } )" ;
255260 newCredential . SetAddress ( connectableAddress ) ;
256261 newCredential . SetPort ( connectableAddress ) ;
257262 return newCredential ;
0 commit comments