Skip to content

Commit 2c7daaa

Browse files
committed
Optimize startup with asynchronous IP configuration list loading
1 parent 7cf69ad commit 2c7daaa

File tree

5 files changed

+78
-31
lines changed

5 files changed

+78
-31
lines changed

IPConfig/Languages/Lang.Designer.cs

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPConfig/Languages/Lang.en.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@
333333
<data name="Gateway" xml:space="preserve">
334334
<value>Gateway</value>
335335
</data>
336+
<data name="GettingAdapterInfo" xml:space="preserve">
337+
<value>Getting Network Adapter Information...</value>
338+
</data>
336339
<data name="GoBack_" xml:space="preserve">
337340
<value>_Back</value>
338341
</data>
@@ -441,6 +444,9 @@
441444
<data name="Light" xml:space="preserve">
442445
<value>Light</value>
443446
</data>
447+
<data name="LoadingIPConfigurations" xml:space="preserve">
448+
<value>Loading IP Configurations...</value>
449+
</data>
444450
<data name="LoadLastUsedConfiguration_" xml:space="preserve">
445451
<value>_Load Last Used Configuration</value>
446452
</data>
@@ -633,7 +639,4 @@
633639
<data name="YouAreUpToDate" xml:space="preserve">
634640
<value>You're up to date</value>
635641
</data>
636-
<data name="GettingAdapterInfo" xml:space="preserve">
637-
<value>Getting Network Adapter Information...</value>
638-
</data>
639642
</root>

IPConfig/Languages/Lang.resx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@
381381
<value>默认网关</value>
382382
<comment>NicConfigDetailView</comment>
383383
</data>
384+
<data name="GettingAdapterInfo" xml:space="preserve">
385+
<value>正在获取网卡/适配器...</value>
386+
<comment>NicViewModel</comment>
387+
</data>
384388
<data name="GoBack_" xml:space="preserve">
385389
<value>返回(_B)</value>
386390
<comment>NicConfigDetailView</comment>
@@ -525,6 +529,10 @@
525529
<value>浅色</value>
526530
<comment>ThemeSwitchButtonView</comment>
527531
</data>
532+
<data name="LoadingIPConfigurations" xml:space="preserve">
533+
<value>正在加载 IP 配置...</value>
534+
<comment>IPConfigListView</comment>
535+
</data>
528536
<data name="LoadLastUsedConfiguration_" xml:space="preserve">
529537
<value>加载上次使用的配置(_L)</value>
530538
<comment>NicInfoCardView</comment>
@@ -779,8 +787,4 @@
779787
<value>你使用的是最新版本</value>
780788
<comment>VersionInfoViewModel</comment>
781789
</data>
782-
<data name="GettingAdapterInfo" xml:space="preserve">
783-
<value>正在获取网卡/适配器...</value>
784-
<comment>NicViewModel</comment>
785-
</data>
786790
</root>

IPConfig/ViewModels/IPConfigListViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ private void DeleteIPConfig()
265265
}
266266

267267
[RelayCommand]
268-
private void Loaded()
268+
private async Task LoadedAsync()
269269
{
270-
var col = LiteDbHelper.Query();
271-
IPConfigList.AddRange(col.OrderBy(x => x.Order).ToEnumerable());
270+
var col = await Task.Run(() => LiteDbHelper.Query().OrderBy(x => x.Order).ToList());
271+
272+
IPConfigList.AddRange(col);
272273
}
273274

274275
[RelayCommand(CanExecute = nameof(HasSelected))]

IPConfig/Views/IPConfigListView.xaml

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,28 +219,48 @@
219219
</ListBox.ItemContainerStyle>
220220
</ListBox>
221221

222-
<hc:Empty Grid.Row="1"
223-
d:Visibility="Visible"
224-
hc:Empty.ShowEmpty="True"
225-
IsHitTestVisible="False"
226-
Visibility="{Binding ElementName=lbIPConfigs, Path=HasItems, Converter={StaticResource Boolean2VisibilityReConverter}}">
227-
<hc:Empty.Logo>
228-
<Viewbox Width="36"
229-
Height="36">
230-
<Path Data="{StaticResource DataGeometry}"
231-
Stroke="{DynamicResource EmptyBrush}"
232-
StrokeThickness="2"
233-
Style="{StaticResource IconParkStyle}" />
234-
</Viewbox>
235-
</hc:Empty.Logo>
222+
<hc:ToggleBlock Grid.Row="1"
223+
d:IsChecked="True"
224+
IsChecked="{Binding LoadedCommand.IsRunning, Mode=OneWay}"
225+
IsHitTestVisible="False">
226+
<hc:ToggleBlock.UnCheckedContent>
227+
<hc:Empty d:Visibility="Visible"
228+
hc:Empty.ShowEmpty="True"
229+
Visibility="{Binding ElementName=lbIPConfigs, Path=HasItems, Converter={StaticResource Boolean2VisibilityReConverter}}">
230+
<hc:Empty.Logo>
231+
<Viewbox Width="36"
232+
Height="36">
233+
<Path Data="{StaticResource DataGeometry}"
234+
Stroke="{DynamicResource EmptyBrush}"
235+
StrokeThickness="2"
236+
Style="{StaticResource IconParkStyle}" />
237+
</Viewbox>
238+
</hc:Empty.Logo>
236239

237-
<hc:Empty.Description>
238-
<TextBlock Margin="0,8"
239-
HorizontalAlignment="Center"
240-
Foreground="{DynamicResource EmptyBrush}"
241-
Text="{lang:Lang {x:Static lang:LangKey.NoConfiguration}}" />
242-
</hc:Empty.Description>
243-
</hc:Empty>
240+
<hc:Empty.Description>
241+
<TextBlock Margin="0,8"
242+
HorizontalAlignment="Center"
243+
Foreground="{DynamicResource EmptyBrush}"
244+
Text="{lang:Lang {x:Static lang:LangKey.NoConfiguration}}" />
245+
</hc:Empty.Description>
246+
</hc:Empty>
247+
</hc:ToggleBlock.UnCheckedContent>
248+
249+
<hc:ToggleBlock.CheckedContent>
250+
<hc:Empty hc:Empty.ShowEmpty="True">
251+
<hc:Empty.Logo>
252+
<hc:LoadingCircle />
253+
</hc:Empty.Logo>
254+
255+
<hc:Empty.Description>
256+
<TextBlock Margin="0,8"
257+
HorizontalAlignment="Center"
258+
Foreground="{DynamicResource EmptyBrush}"
259+
Text="{lang:Lang {x:Static lang:LangKey.LoadingIPConfigurations}}" />
260+
</hc:Empty.Description>
261+
</hc:Empty>
262+
</hc:ToggleBlock.CheckedContent>
263+
</hc:ToggleBlock>
244264

245265
<UniformGrid Grid.Row="2"
246266
Margin="0,4,0,0"

0 commit comments

Comments
 (0)