mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 22:36:20 +00:00
If there are many font files, opening the OptionSettingWindow will noticeably lag. The font loading logic can be changed to execute asynchronously.
This commit is contained in:
parent
5857042963
commit
defc82eee3
1 changed files with 31 additions and 3 deletions
|
@ -30,7 +30,7 @@ namespace v2rayN.Views
|
||||||
|
|
||||||
this.Owner = Application.Current.MainWindow;
|
this.Owner = Application.Current.MainWindow;
|
||||||
_config = LazyConfig.Instance.GetConfig();
|
_config = LazyConfig.Instance.GetConfig();
|
||||||
var lstFonts = GetFonts(Utils.GetFontsPath());
|
|
||||||
|
|
||||||
ViewModel = new OptionSettingViewModel(this);
|
ViewModel = new OptionSettingViewModel(this);
|
||||||
|
|
||||||
|
@ -90,8 +90,7 @@ namespace v2rayN.Views
|
||||||
cmbSubConvertUrl.Items.Add(it);
|
cmbSubConvertUrl.Items.Add(it);
|
||||||
});
|
});
|
||||||
|
|
||||||
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
|
LoadFontsAsync(); //If there are many font files, opening the OptionSettingWindow will noticeably lag. The font loading logic can be changed to execute asynchronously.
|
||||||
cmbcurrentFontFamily.Items.Add(string.Empty);
|
|
||||||
|
|
||||||
this.WhenActivated(disposables =>
|
this.WhenActivated(disposables =>
|
||||||
{
|
{
|
||||||
|
@ -213,5 +212,34 @@ namespace v2rayN.Views
|
||||||
}
|
}
|
||||||
return lstFonts;
|
return lstFonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void LoadFontsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Run(() => {
|
||||||
|
return GetFonts(Utils.GetFontsPath());
|
||||||
|
}).ContinueWith(t => {
|
||||||
|
if (t.Exception == null)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() => {
|
||||||
|
foreach (var font in t.Result)
|
||||||
|
{
|
||||||
|
cmbcurrentFontFamily.Items.Add(font);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 处理异常
|
||||||
|
Logging.SaveLog("fill fonts error", t.Exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog("Async font loading error", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue