From 1273d2aee11a0aa0d83072e9edfcd67052dcd88c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:57:45 +0800 Subject: [PATCH] Improved font settings --- v2rayN/ServiceLib/Enums/EViewAction.cs | 1 + .../ViewModels/OptionSettingViewModel.cs | 2 ++ .../v2rayN/Views/OptionSettingWindow.xaml.cs | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/v2rayN/ServiceLib/Enums/EViewAction.cs b/v2rayN/ServiceLib/Enums/EViewAction.cs index e19a4d4a..c37e1212 100644 --- a/v2rayN/ServiceLib/Enums/EViewAction.cs +++ b/v2rayN/ServiceLib/Enums/EViewAction.cs @@ -19,6 +19,7 @@ Shutdown, BrowseServer, ImportRulesFromFile, + InitSettingFont, SubEditWindow, RoutingRuleSettingWindow, RoutingRuleDetailsWindow, diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index a10f301e..54ae03ab 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -117,6 +117,8 @@ namespace ServiceLib.ViewModels private async Task Init() { + await _updateView?.Invoke(EViewAction.InitSettingFont, null); + #region Core var inbound = _config.Inbound[0]; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 5a1e1b3f..508365b0 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -17,7 +17,6 @@ namespace v2rayN.Views this.Owner = Application.Current.MainWindow; _config = AppHandler.Instance.Config; - var lstFonts = GetFonts(Utils.GetFontsPath()); ViewModel = new OptionSettingViewModel(UpdateViewHandler); @@ -102,9 +101,6 @@ namespace v2rayN.Views cmbMainGirdOrientation.Items.Add(it.ToString()); } - lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); }); - cmbcurrentFontFamily.Items.Add(string.Empty); - this.WhenActivated(disposables => { this.Bind(ViewModel, vm => vm.localPort, v => v.txtlocalPort.Text).DisposeWith(disposables); @@ -191,11 +187,22 @@ namespace v2rayN.Views WindowsUtils.SetAutoRun(Global.AutoRunRegPath, Global.AutoRunName, togAutoRun.IsChecked ?? false); this.DialogResult = true; break; + + case EViewAction.InitSettingFont: + await InitSettingFont(); + break; } return await Task.FromResult(true); } - private List GetFonts(string path) + private async Task InitSettingFont() + { + var lstFonts = await GetFonts(Utils.GetFontsPath()); + lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); }); + cmbcurrentFontFamily.Items.Add(string.Empty); + } + + private async Task> GetFonts(string path) { var lstFonts = new List(); try @@ -241,7 +248,7 @@ namespace v2rayN.Views { Logging.SaveLog("fill fonts error", ex); } - return lstFonts; + return lstFonts.OrderBy(t => t).ToList(); } private void ClbdestOverride_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)