Optimized code

pull/5550/head
2dust 2024-08-15 21:03:00 +08:00
parent 30ff9d0ea9
commit a9860418ba
36 changed files with 46 additions and 54 deletions

View File

@ -59,6 +59,7 @@ namespace v2rayN
Environment.Exit(0);
return;
}
LazyConfig.Instance.SetConfig(_config);
//Under Win10
if (Environment.OSVersion.Version.Major < 10)

View File

@ -11,7 +11,7 @@ namespace v2rayN.Converters
{
try
{
var fontFamily = LazyConfig.Instance.GetConfig().uiItem.currentFontFamily;
var fontFamily = LazyConfig.Instance.Config.uiItem.currentFontFamily;
if (!Utils.IsNullOrEmpty(fontFamily))
{
var fontPath = Utils.GetFontsPath();

View File

@ -87,7 +87,7 @@ namespace v2rayN.Handler
return;
}
var urlBase = $"{GetApiUrl()}/proxies";
urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.GetConfig().speedTestItem.speedPingTestUrl;
urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.Config.speedTestItem.speedPingTestUrl;
List<Task> tasks = new List<Task>();
foreach (var it in lstProxy)

View File

@ -206,7 +206,6 @@ namespace v2rayN.Handler
};
}
LazyConfig.Instance.SetConfig(config);
return 0;
}

View File

@ -20,7 +20,7 @@ namespace v2rayN.Handler.CoreConfig
msg = ResUI.CheckServerSettings;
return -1;
}
var config = LazyConfig.Instance.GetConfig();
var config = LazyConfig.Instance.Config;
msg = ResUI.InitialConfiguration;
if (node.configType == EConfigType.Custom)

View File

@ -34,7 +34,7 @@ namespace v2rayN.Handler
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
var progress = new Progress<string>();
progress.ProgressChanged += (sender, value) =>
@ -66,7 +66,7 @@ namespace v2rayN.Handler
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}"));
var progress = new Progress<double>();
@ -96,7 +96,7 @@ namespace v2rayN.Handler
public async Task<string?> UrlRedirectAsync(string url, bool blProxy)
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
var webRequestHandler = new SocketsHttpHandler
{
AllowAutoRedirect = false,
@ -185,7 +185,7 @@ namespace v2rayN.Handler
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
var webProxy = GetWebProxy(blProxy);
var client = new HttpClient(new SocketsHttpHandler()
{
@ -230,7 +230,7 @@ namespace v2rayN.Handler
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
var webProxy = GetWebProxy(blProxy);
@ -264,7 +264,7 @@ namespace v2rayN.Handler
try
{
var config = LazyConfig.Instance.GetConfig();
var config = LazyConfig.Instance.Config;
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
return responseTime;
}

View File

@ -19,7 +19,7 @@ namespace v2rayN.Handler
private Config _config
{
get => LazyConfig.Instance.GetConfig();
get => LazyConfig.Instance.Config;
}
private Dictionary<int, List<EGlobalHotkey>> _hotkeyTriggerDic;

View File

@ -7,12 +7,12 @@ namespace v2rayN.Handler
{
private static readonly Lazy<LazyConfig> _instance = new(() => new());
private Config _config;
public static LazyConfig Instance => _instance.Value;
private int? _statePort;
private int? _statePort2;
public static LazyConfig Instance => _instance.Value;
public Config Config => _config;
public int StatePort
{
get
@ -45,15 +45,7 @@ namespace v2rayN.Handler
#region Config
public void SetConfig(Config config)
{
_config = config;
}
public Config GetConfig()
{
return _config;
}
public void SetConfig(Config config) => _config = config;
public int GetLocalPort(EInboundProtocol protocol)
{

View File

@ -548,7 +548,7 @@ namespace v2rayN.Handler
//}
//if (blDownload)
//{
await downloadHandle.DownloadFileAsync(url, true, 600);
await downloadHandle.DownloadFileAsync(url, true, 600);
//}
}

View File

@ -24,7 +24,7 @@ namespace v2rayN.ViewModels
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, bool>? updateView)
{
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_updateView = updateView;
if (profileItem.indexId.IsNullOrEmpty())

View File

@ -19,7 +19,7 @@ namespace v2rayN.ViewModels
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -31,7 +31,7 @@ namespace v2rayN.ViewModels
public ClashConnectionsViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_updateView = updateView;
SortingSelected = _config.clashUIItem.connectionsSorting;
AutoRefresh = _config.clashUIItem.connectionsAutoRefresh;

View File

@ -50,7 +50,7 @@ namespace v2rayN.ViewModels
public ClashProxiesViewModel(Func<EViewAction, object?, bool>? updateView)
{
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_updateView = updateView;
SelectedGroup = new();

View File

@ -28,7 +28,7 @@ namespace v2rayN.ViewModels
public DNSSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -159,7 +159,7 @@ namespace v2rayN.ViewModels
public MainWindowViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -107,7 +107,7 @@ namespace v2rayN.ViewModels
public OptionSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
@ -301,7 +301,7 @@ namespace v2rayN.ViewModels
_config.hysteriaItem.up_mbps = hyUpMbps;
_config.hysteriaItem.down_mbps = hyDownMbps;
_config.coreBasicItem.enableFragment = enableFragment;
_config.guiItem.autoRun = AutoRun;
_config.guiItem.enableStatistics = EnableStatistics;
_config.guiItem.keepOlderDedupl = KeepOlderDedupl;

View File

@ -101,7 +101,7 @@ namespace v2rayN.ViewModels
public ProfilesViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -34,7 +34,7 @@ namespace v2rayN.ViewModels
public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -41,7 +41,7 @@ namespace v2rayN.ViewModels
public RoutingRuleSettingViewModel(RoutingItem routingItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
SelectedSource = new();

View File

@ -72,7 +72,7 @@ namespace v2rayN.ViewModels
public RoutingSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
SelectedSource = new();

View File

@ -19,7 +19,7 @@ namespace v2rayN.ViewModels
public SubEditViewModel(SubItem subItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -30,7 +30,7 @@ namespace v2rayN.ViewModels
public SubSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;

View File

@ -38,7 +38,7 @@ namespace v2rayN.ViewModels
public ThemeSettingViewModel()
{
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
MainFormHandler.Instance.RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); });

View File

@ -38,7 +38,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.EditServerCmd, v => v.btnEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveServerCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -222,7 +222,7 @@ namespace v2rayN.Views
});
this.Title = $"{profileItem.configType}";
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -17,7 +17,7 @@ namespace v2rayN.Views
InitializeComponent();
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
ViewModel = new DNSSettingViewModel(UpdateViewHandler);
@ -54,7 +54,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4V2rayCmd, v => v.btnImportDefConfig4V2ray).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4SingboxCmd, v => v.btnImportDefConfig4Singbox).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -19,7 +19,7 @@ namespace v2rayN.Views
InitializeComponent();
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
_config.globalHotkeys ??= new List<KeyEventItem>();
txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_PreviewKeyDown;

View File

@ -25,7 +25,7 @@ namespace v2rayN.Views
{
InitializeComponent();
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
App.Current.SessionEnding += Current_SessionEnding;
this.Closing += MainWindow_Closing;

View File

@ -17,7 +17,7 @@ namespace v2rayN.Views
public MsgView()
{
InitializeComponent();
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
MessageBus.Current.Listen<string>(Global.CommandSendMsgView).Subscribe(x => DelegateAppendText(x));
Global.PresetMsgFilters.ForEach(it =>
{

View File

@ -20,7 +20,7 @@ namespace v2rayN.Views
InitializeComponent();
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
var lstFonts = GetFonts(Utils.GetFontsPath());
ViewModel = new OptionSettingViewModel(UpdateViewHandler);
@ -169,7 +169,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -27,7 +27,7 @@ namespace v2rayN.Views
InitializeComponent();
lstGroup.MaxHeight = Math.Floor(SystemParameters.WorkArea.Height * 0.20 / 40) * 40;
_config = LazyConfig.Instance.GetConfig();
_config = LazyConfig.Instance.Config;
Application.Current.Exit += Current_Exit;
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;

View File

@ -61,7 +61,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -62,7 +62,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -69,7 +69,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -40,7 +40,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)

View File

@ -35,7 +35,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SubEditCmd, v => v.menuSubEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubShareCmd, v => v.menuSubShare).DisposeWith(disposables);
});
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action, object? obj)