Skip to content

Commit 9df3ce4

Browse files
committed
fix: #868, When using the alternate address, append the display name with the alternate name.
1 parent 9bf4ffd commit 9df3ce4

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Create a report to help us improve
44
title: ''
55
labels: bug
66
assignees: VShawn
7-
type: Bug
87
---
98

109
**Describe the bug**

Ui/Service/SessionControlService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server)
128128
{
129129
if (!server.IsOnlyOneInstance()) return false;
130130
var connectionId = server.BuildConnectionId();
131-
// if is OnlyOneInstance Protocol and it is connected now, activate it and return.
131+
// if is `OnlyOneInstance Protocol`, and it is connected, activate it and return.
132132
if (!_connectionId2Hosts.ContainsKey(connectionId))
133133
return false;
134134

135135
SimpleLogHelper.Debug($"_connectionId2Hosts ContainsKey {connectionId}");
136-
// Activate
136+
// Find activate
137137
if (_connectionId2Hosts[connectionId].ParentWindow is { } win)
138138
{
139139
if (win is TabWindowView tab)

Ui/Service/SessionControlService_AlternateCredential.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

Ui/Service/SessionControlService_OpenConnection.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,23 @@ private async Task<string> Connect(ProtocolBase protocol, string fromView, strin
216216
}
217217

218218
p.SetCredential(c);
219-
if (string.IsNullOrEmpty(assignCredentialName) == false)
220-
p.DisplayName += $" ({c.Name})";
219+
p.DisplayName = c.Name;
221220
}
222221
}
223222

224223

225224

226-
// check if need to input password
225+
// check if it needs password
227226
if (protocolClone is ProtocolBaseWithAddressPortUserPwd { AskPasswordWhenConnect: true } pb)
228227
{
229228
bool flag = false;
230229
Execute.OnUIThreadSync(() =>
231230
{
232-
var pwdDlg = new PasswordPopupDialogViewModel(protocolClone is SSH or SFTP);
233-
pwdDlg.Title = $"[{pb.ProtocolDisplayName}]({pb.DisplayName}) -> {pb.Address}:{pb.Port}";
234-
pwdDlg.UserName = pb.UserName;
231+
var pwdDlg = new PasswordPopupDialogViewModel(protocolClone is SSH or SFTP)
232+
{
233+
Title = $"[{pb.ProtocolDisplayName}]({pb.DisplayName}) -> {pb.Address}:{pb.Port}",
234+
UserName = pb.UserName
235+
};
235236
if (pb.UsePrivateKeyForConnect == true)
236237
{
237238
pwdDlg.CanUsePrivateKeyForConnect = true;

Ui/View/ServerList/ServerListPageView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@
690690
<Setter Property="Margin" Value="0 0 5 0"></Setter>
691691
</Style>
692692
</StackPanel.Resources>
693-
<TextBlock Text="{Binding SelectedServerViewModelListItem.Server.DisplayName}" Style="{StaticResource TextBlockBase}"></TextBlock>
693+
<TextBlock Text="{Binding SelectedServerViewModelListItem.Server.DisplayName}" Style="{StaticResource TextBlockBase}" Margin="5 0"></TextBlock>
694694
<TextBlock Text="{Binding SelectedServerViewModelListItem.Server.SubTitle}" Style="{StaticResource TextBlockBase}"></TextBlock>
695695
</StackPanel>
696696
</Grid>

0 commit comments

Comments
 (0)