Skip to content

Commit 8ddda3b

Browse files
committed
feat: remake available detect view, close #420
1 parent f2d0db2 commit 8ddda3b

File tree

4 files changed

+72
-36
lines changed

4 files changed

+72
-36
lines changed

Ui/Service/SessionControlService_AlternateCredential.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,35 @@ namespace _1RM.Service
1414
{
1515
public partial class SessionControlService
1616
{
17+
#if DEBUG
1718
public static void CredentialTest()
1819
{
1920
var pingCredentials = new List<Credential>
2021
{
22+
new Credential()
23+
{
24+
Name = "asfasdas12312312312",
25+
Address = "127.012311.131231231", Port = "5000",
26+
},
2127
new Credential()
2228
{
2329
Name = "asfasdas",
2430
Address = "127.0.1.1", Port = "5000",
2531
},
26-
//new Credential()
27-
//{
28-
// Address = "127.0.0.1", Port = "5000",
29-
//},
32+
new Credential()
33+
{
34+
Address = "127.0.0.1", Port = "5000",
35+
},
3036
new Credential()
3137
{
3238
Name = "xcv1",
3339
Address = "192.168.100.1", Port = "3389",
3440
},
35-
//new Credential()
36-
//{
37-
// Address = "172.20.65.31", Port = "3389",
38-
//},
41+
new Credential()
42+
{
43+
Name = "asfasdxxxxxxxxxxxxxxxxas12312312312",
44+
Address = "172.20.65.31", Port = "3389",
45+
},
3946
new Credential()
4047
{
4148
Name = "98vs",
@@ -61,20 +68,24 @@ public static void CredentialTest()
6168
}
6269
});
6370
}
71+
#endif
72+
6473

6574
/// <summary>
6675
/// Find the first connectable address from the given credentials. if return null then no address is connectable.
6776
/// </summary>
6877
private static async Task<Credential?> FindFirstConnectableAddressAsync(IEnumerable<Credential> pingCredentials, string protocolDisplayName)
6978
{
70-
var credentials = pingCredentials.ToList();
71-
const int maxWaitSeconds = 10;
79+
var credentials = pingCredentials.Select(x => x.CloneMe()).ToList();
80+
const int maxWaitSeconds = 5;
7281
var cts = new CancellationTokenSource();
7382

7483
var uiPingItems = new List<PingTestItem>();
7584
foreach (var credential in credentials)
7685
{
77-
uiPingItems.Add(new PingTestItem(credential.Name, credential.Address)
86+
credential.Address = string.IsNullOrEmpty(credential.Address) ? credentials.First().Address : credential.Address;
87+
credential.Port = string.IsNullOrEmpty(credential.Port) ? credentials.First().Port : credential.Port;
88+
uiPingItems.Add(new PingTestItem(credential.Name, credential.Address + ":" + credential.Port)
7889
{
7990
Status = PingStatus.None,
8091
});
@@ -135,7 +146,7 @@ await Execute.OnUIThreadAsync(() =>
135146
while (ts.Any())
136147
{
137148
var completedTask = await Task.WhenAny(ts);
138-
if (completedTask?.Result == true)
149+
if (completedTask.IsCanceled == false && completedTask?.Result == true)
139150
{
140151
completedTaskIndex = tasks.IndexOf(completedTask);
141152
SimpleLogHelper.DebugInfo($"Task{completedTaskIndex} completed first. Cancelling remaining tasks.");
@@ -169,7 +180,7 @@ await Execute.OnUIThreadAsync(() =>
169180
if (completedTaskIndex >= 0 && completedTaskIndex < tasks.Count)
170181
{
171182
// close the pop window
172-
await Execute.OnUIThreadAsync(() => { dlg.RequestClose(); });
183+
//await Execute.OnUIThreadAsync(() => { dlg.RequestClose(); });
173184
return credentials[completedTaskIndex].CloneMe();
174185
}
175186
else
@@ -191,6 +202,7 @@ await Execute.OnUIThreadAsync(() =>
191202
private static async Task<Credential?> GetCredential(ProtocolBaseWithAddressPort protocol, string assignCredentialName)
192203
{
193204
var newCredential = protocol.GetCredential();
205+
newCredential.Name = "default";
194206
// use assign credential 应用指定的 credential
195207
var assignCredential = protocol.AlternateCredentials.FirstOrDefault(x => x.Name == assignCredentialName);
196208
if (assignCredential != null)
@@ -202,7 +214,7 @@ await Execute.OnUIThreadAsync(() =>
202214
// check if need to ping before connect
203215
bool isPingBeforeConnect = protocol.IsPingBeforeConnect == true
204216
// do not ping if rdp protocol and gateway is used
205-
&& protocol is not RDP { GatewayMode: EGatewayMode.DoNotUseGateway };
217+
&& protocol is not RDP { GatewayMode: EGatewayMode.UseTheseGatewayServerSettings };
206218
var isAutoAlternateAddressSwitching = protocol.IsAutoAlternateAddressSwitching == true
207219
// if any host or port in assignCredential,then disabled `AutoAlternateAddressSwitching`
208220
&& string.IsNullOrEmpty(assignCredential?.Address) && string.IsNullOrEmpty(assignCredential?.Port)

Ui/View/Host/TabWindowView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@
569569
Grid.Column="2"
570570
Command="{x:Static dragablz:TabablzControl.AddItemCommand}"
571571
Visibility="{TemplateBinding ShowDefaultAddButton, Converter={StaticResource BooleanToVisibilityConverter}}" />
572-
572+
573573
<ContentControl Grid.Column="3" x:Name="SuffixContentControl"
574574
Content="{TemplateBinding HeaderSuffixContent}"
575575
ContentStringFormat="{TemplateBinding HeaderSuffixContentStringFormat}"

Ui/View/MainWindowViewModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ public RelayCommand CmdExit
327327
{
328328
return _cmdExit ??= new RelayCommand((o) =>
329329
{
330-
#if DEBUG
331-
// TODO REMOVE
332-
SessionControlService.CredentialTest();
333-
return;
334-
#endif
335330
App.Close();
336331
});
337332
}

Ui/View/Utils/AlternateAddressSwitchingView.xaml

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,45 +99,74 @@
9999
</ItemsControl.Template>
100100
<ItemsControl.ItemTemplate>
101101
<DataTemplate>
102-
<Grid Margin="5 5 10 0" Background="Transparent">
102+
<Grid Margin="0 5 10 0" Background="Transparent">
103103
<Grid.Style>
104104
<Style TargetType="Grid">
105105
<Setter Property="Opacity" Value="0.6"></Setter>
106106
<Style.Triggers>
107107
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Success}">
108108
<Setter Property="Opacity" Value="1"></Setter>
109109
</DataTrigger>
110+
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Failed}">
111+
<Setter Property="Opacity" Value="0.8"></Setter>
112+
</DataTrigger>
110113
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Canceled}">
111-
<Setter Property="Opacity" Value="0.3"></Setter>
114+
<Setter Property="Opacity" Value="0.1"></Setter>
112115
</DataTrigger>
113116
</Style.Triggers>
114117
</Style>
115118
</Grid.Style>
116119

117120
<Grid.ColumnDefinitions>
118-
<ColumnDefinition Width="Auto" SharedSizeGroup="A"></ColumnDefinition>
119-
<ColumnDefinition Width="Auto" SharedSizeGroup="B"></ColumnDefinition>
121+
<ColumnDefinition Width="80"></ColumnDefinition>
120122
<ColumnDefinition Width="*"></ColumnDefinition>
121-
<ColumnDefinition Width="Auto" SharedSizeGroup="D"></ColumnDefinition>
123+
<ColumnDefinition Width="20"></ColumnDefinition>
122124
</Grid.ColumnDefinitions>
123125

124126
<TextBlock Text="{Binding Name}"
125-
MaxWidth="80"
126127
ToolTip="{Binding Name}"
127128
TextTrimming="CharacterEllipsis"
128-
Margin="2 0"
129-
Foreground="{DynamicResource PrimaryTextBrush}"/>
129+
Margin="5 0 0 0">
130+
<TextBlock.Style>
131+
<Style TargetType="TextBlock">
132+
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"></Setter>
133+
<Style.Triggers>
134+
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Success}">
135+
<Setter Property="Foreground" Value="Green"></Setter>
136+
</DataTrigger>
137+
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Failed}">
138+
<Setter Property="Foreground" Value="Red"></Setter>
139+
</DataTrigger>
140+
</Style.Triggers>
141+
</Style>
142+
</TextBlock.Style>
143+
</TextBlock>
130144

131145
<TextBlock Grid.Column="1" Text="{Binding Address}"
132146
TextTrimming="CharacterEllipsis"
133-
Margin="5 0"
134-
Foreground="{DynamicResource PrimaryTextBrush}"/>
147+
ToolTip="{Binding Address}"
148+
Margin="5 0">
149+
<TextBlock.Style>
150+
<Style TargetType="TextBlock">
151+
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"></Setter>
152+
<Style.Triggers>
153+
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Success}">
154+
<Setter Property="Foreground" Value="Green"></Setter>
155+
</DataTrigger>
156+
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Failed}">
157+
<Setter Property="Foreground" Value="Red"></Setter>
158+
</DataTrigger>
159+
</Style.Triggers>
160+
</Style>
161+
</TextBlock.Style>
162+
</TextBlock>
135163

136-
<TextBlock Grid.Column="2" Text="{Binding Ping, StringFormat={}0ms}"
137-
Opacity="0.5" FontSize="10" VerticalAlignment="Center"
138-
TextTrimming="CharacterEllipsis"
164+
<TextBlock Grid.Column="1" Text="{Binding Ping, StringFormat={} 0ms}"
165+
Opacity="0.8" FontSize="10"
166+
VerticalAlignment="Center"
139167
HorizontalAlignment="Right"
140-
Margin="5 0" Foreground="{DynamicResource PrimaryTextBrush}">
168+
Background="{DynamicResource PrimaryMidBrush}"
169+
Foreground="{DynamicResource PrimaryTextBrush}">
141170
<TextBlock.Style>
142171
<Style TargetType="TextBlock">
143172
<Setter Property="Visibility" Value="Collapsed"></Setter>
@@ -150,7 +179,7 @@
150179
</TextBlock.Style>
151180
</TextBlock>
152181

153-
<Grid Grid.Column="3" Height="16" Width="16" Background="Transparent" ToolTip="{Binding Status}">
182+
<Grid Grid.Column="2" Height="16" Width="16" Background="Transparent" ToolTip="{Binding Status}">
154183
<Path Height="12" Width="12" UseLayoutRounding="True" Stretch="Uniform">
155184
<Path.Style>
156185
<Style TargetType="Path">
@@ -182,7 +211,7 @@
182211
<DataTrigger Binding="{Binding Status}" Value="{x:Static utils:PingStatus.Canceled}">
183212
<Setter Property="Data" Value="{StaticResource GeometrySandClock}"></Setter>
184213
<Setter Property="Fill" Value="{DynamicResource PrimaryTextBrush}"></Setter>
185-
<Setter Property="Opacity" Value="0.3"></Setter>
214+
<!--<Setter Property="Opacity" Value="0.3"></Setter>-->
186215
<Setter Property="ToolTip" Value="Canceled"></Setter>
187216
</DataTrigger>
188217
</Style.Triggers>

0 commit comments

Comments
 (0)