Skip to content

Commit defc82e

Browse files
committed
If there are many font files, opening the OptionSettingWindow will noticeably lag. The font loading logic can be changed to execute asynchronously.
1 parent 5857042 commit defc82e

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public OptionSettingWindow()
3030

3131
this.Owner = Application.Current.MainWindow;
3232
_config = LazyConfig.Instance.GetConfig();
33-
var lstFonts = GetFonts(Utils.GetFontsPath());
33+
3434

3535
ViewModel = new OptionSettingViewModel(this);
3636

@@ -90,8 +90,7 @@ public OptionSettingWindow()
9090
cmbSubConvertUrl.Items.Add(it);
9191
});
9292

93-
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
94-
cmbcurrentFontFamily.Items.Add(string.Empty);
93+
LoadFontsAsync(); //If there are many font files, opening the OptionSettingWindow will noticeably lag. The font loading logic can be changed to execute asynchronously.
9594

9695
this.WhenActivated(disposables =>
9796
{
@@ -213,5 +212,34 @@ private List<string> GetFonts(string path)
213212
}
214213
return lstFonts;
215214
}
215+
216+
private async void LoadFontsAsync()
217+
{
218+
try
219+
{
220+
await Task.Run(() => {
221+
return GetFonts(Utils.GetFontsPath());
222+
}).ContinueWith(t => {
223+
if (t.Exception == null)
224+
{
225+
Dispatcher.Invoke(() => {
226+
foreach (var font in t.Result)
227+
{
228+
cmbcurrentFontFamily.Items.Add(font);
229+
}
230+
});
231+
}
232+
else
233+
{
234+
// 处理异常
235+
Logging.SaveLog("fill fonts error", t.Exception);
236+
}
237+
});
238+
}
239+
catch (Exception ex)
240+
{
241+
Logging.SaveLog("Async font loading error", ex);
242+
}
243+
}
216244
}
217245
}

0 commit comments

Comments
 (0)