Skip to content

Commit c1ace6b

Browse files
committed
asynchronous font loading
1 parent d748e6e commit c1ace6b

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs

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

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

3534
ViewModel = new OptionSettingViewModel(this);
3635

@@ -42,7 +41,7 @@ public OptionSettingWindow()
4241
_config.inbound[0].destOverride?.ForEach(it =>
4342
{
4443
clbdestOverride.SelectedItems.Add(it);
45-
});
44+
});
4645
Global.IEProxyProtocols.ForEach(it =>
4746
{
4847
cmbsystemProxyAdvancedProtocol.Items.Add(it);
@@ -99,8 +98,7 @@ public OptionSettingWindow()
9998
cmbSubConvertUrl.Items.Add(it);
10099
});
101100

102-
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
103-
cmbcurrentFontFamily.Items.Add(string.Empty);
101+
cmbcurrentFontFamily.Items.Add("默认字体");
104102

105103
this.WhenActivated(disposables =>
106104
{
@@ -147,7 +145,8 @@ public OptionSettingWindow()
147145
this.Bind(ViewModel, vm => vm.DoubleClick2Activate, v => v.togDoubleClick2Activate.IsChecked).DisposeWith(disposables);
148146
this.Bind(ViewModel, vm => vm.AutoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables);
149147
this.Bind(ViewModel, vm => vm.TrayMenuServersLimit, v => v.txttrayMenuServersLimit.Text).DisposeWith(disposables);
150-
this.Bind(ViewModel, vm => vm.CurrentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables);
148+
// this.Bind(ViewModel, vm => vm.CurrentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables);
149+
LoadFontsAsync(disposables);
151150
this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.Text).DisposeWith(disposables);
152151
this.Bind(ViewModel, vm => vm.SpeedTestUrl, v => v.cmbSpeedTestUrl.Text).DisposeWith(disposables);
153152
this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.Text).DisposeWith(disposables);
@@ -227,5 +226,25 @@ private void ClbdestOverride_SelectionChanged(object sender, System.Windows.Cont
227226
{
228227
ViewModel.destOverride = clbdestOverride.SelectedItems.Cast<string>().ToList();
229228
}
229+
230+
private async void LoadFontsAsync(CompositeDisposable disposables)
231+
{
232+
try
233+
{
234+
var fonts = await Task.Run(() => GetFonts(Utils.GetFontsPath()));
235+
Dispatcher.Invoke(() =>
236+
{
237+
foreach (var font in fonts)
238+
{
239+
cmbcurrentFontFamily.Items.Add(font);
240+
}
241+
this.Bind(ViewModel, vm => vm.CurrentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables);
242+
});
243+
}
244+
catch (Exception e)
245+
{
246+
Logging.SaveLog("Async font loading error", e);
247+
}
248+
}
230249
}
231250
}

0 commit comments

Comments
 (0)