From 3bdef4d6d8d84deb39c3c93c509807626681cd67 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:51:41 +0800 Subject: [PATCH] Rename LazyConfig to AppHandler --- .../Handler/{LazyConfig.cs => AppHandler.cs} | 49 +++++++++++++++---- v2rayN/ServiceLib/Handler/ClashApiHandler.cs | 4 +- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 36 +++++++------- .../Handler/CoreConfig/CoreConfigClash.cs | 6 +-- .../Handler/CoreConfig/CoreConfigHandler.cs | 4 +- .../Handler/CoreConfig/CoreConfigSingbox.cs | 20 ++++---- .../Handler/CoreConfig/CoreConfigV2ray.cs | 18 +++---- v2rayN/ServiceLib/Handler/CoreHandler.cs | 6 +-- v2rayN/ServiceLib/Handler/DownloadHandler.cs | 14 +++--- v2rayN/ServiceLib/Handler/SpeedtestHandler.cs | 4 +- .../Handler/Statistics/StatisticsSingbox.cs | 2 +- .../Handler/Statistics/StatisticsV2ray.cs | 2 +- v2rayN/ServiceLib/Handler/TaskHandler.cs | 2 +- v2rayN/ServiceLib/Handler/UpdateHandler.cs | 2 +- v2rayN/ServiceLib/Handler/WebDavHandler.cs | 2 +- v2rayN/ServiceLib/Models/ConfigItems.cs | 2 - .../ViewModels/AddServer2ViewModel.cs | 4 +- .../ViewModels/AddServerViewModel.cs | 2 +- .../ViewModels/BackupAndRestoreViewModel.cs | 2 +- .../ViewModels/CheckUpdateViewModel.cs | 2 +- .../ViewModels/ClashConnectionsViewModel.cs | 2 +- .../ViewModels/ClashProxiesViewModel.cs | 2 +- .../ViewModels/DNSSettingViewModel.cs | 10 ++-- .../ViewModels/MainWindowViewModel.cs | 18 +++---- v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 2 +- .../ViewModels/OptionSettingViewModel.cs | 2 +- .../ViewModels/ProfilesViewModel.cs | 18 +++---- .../ViewModels/RoutingRuleDetailsViewModel.cs | 2 +- .../ViewModels/RoutingRuleSettingViewModel.cs | 2 +- .../ViewModels/RoutingSettingViewModel.cs | 10 ++-- .../ServiceLib/ViewModels/SubEditViewModel.cs | 2 +- .../ViewModels/SubSettingViewModel.cs | 6 +-- v2rayN/v2rayN.Desktop/App.axaml.cs | 33 +++---------- .../v2rayN.Desktop/Handler/SysProxyHandler.cs | 6 +-- .../v2rayN.Desktop/ViewModels/AppViewModel.cs | 2 +- .../ViewModels/ThemeSettingViewModel.cs | 2 +- .../Views/AddServerWindow.axaml.cs | 2 +- .../Views/DNSSettingWindow.axaml.cs | 2 +- .../Views/GlobalHotkeySettingWindow.axaml.cs | 2 +- .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 2 +- .../Views/OptionSettingWindow.axaml.cs | 2 +- .../Views/ProfilesView.axaml.cs | 2 +- v2rayN/v2rayN/App.xaml.cs | 28 ++--------- .../v2rayN/Converters/MaterialDesignFonts.cs | 2 +- v2rayN/v2rayN/Handler/HotkeyHandler.cs | 2 +- v2rayN/v2rayN/Handler/SysProxyHandler.cs | 6 +-- .../ViewModels/ThemeSettingViewModel.cs | 2 +- v2rayN/v2rayN/Views/AddServer2Window.xaml.cs | 2 +- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 4 +- .../Views/GlobalHotkeySettingWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 2 +- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 2 +- .../Views/RoutingRuleDetailsWindow.xaml.cs | 2 +- .../Views/RoutingRuleSettingWindow.xaml.cs | 2 +- .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 2 +- 59 files changed, 186 insertions(+), 198 deletions(-) rename v2rayN/ServiceLib/Handler/{LazyConfig.cs => AppHandler.cs} (86%) diff --git a/v2rayN/ServiceLib/Handler/LazyConfig.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs similarity index 86% rename from v2rayN/ServiceLib/Handler/LazyConfig.cs rename to v2rayN/ServiceLib/Handler/AppHandler.cs index afc1f7295ff..9fa7c59b6ec 100644 --- a/v2rayN/ServiceLib/Handler/LazyConfig.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -1,13 +1,15 @@ -namespace ServiceLib.Handler +using Splat; + +namespace ServiceLib.Handler { - public sealed class LazyConfig + public sealed class AppHandler { - private static readonly Lazy _instance = new(() => new()); + private static readonly Lazy _instance = new(() => new()); private Config _config; private int? _statePort; private int? _statePort2; - - public static LazyConfig Instance => _instance.Value; + private Job? _processJob; + public static AppHandler Instance => _instance.Value; public Config Config => _config; public int StatePort @@ -28,21 +30,50 @@ public int StatePort2 } } - private Job? _processJob; + #region Init + + public AppHandler() + { + } + + public bool InitApp() + { + if (ConfigHandler.LoadConfig(ref _config) != 0) + { + return false; + } + Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler)); + Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); + + //Under Win10 + if (Utils.IsWindows() && Environment.OSVersion.Version.Major < 10) + { + Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User); + } + return true; + } - public LazyConfig() + public bool InitComponents() { + Logging.Setup(); + Logging.LoggingEnabled(true); + Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); + Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}"); + Logging.ClearLogs(); + SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); + + return true; } - #region Config + #endregion Init - public void SetConfig(Config config) => _config = config; + #region Config public int GetLocalPort(EInboundProtocol protocol) { diff --git a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs index a85b4b5cd49..1084cd4c8f3 100644 --- a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs +++ b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs @@ -76,7 +76,7 @@ public void ClashProxiesDelayTest(bool blAll, List lstProxy, Ac return; } var urlBase = $"{GetApiUrl()}/proxies"; - urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.Config.speedTestItem.speedPingTestUrl; + urlBase += @"/{0}/delay?timeout=10000&url=" + AppHandler.Instance.Config.speedTestItem.speedPingTestUrl; List tasks = new List(); foreach (var it in lstProxy) @@ -200,7 +200,7 @@ public async void ClashConnectionClose(string id) private string GetApiUrl() { - return $"{Global.HttpProtocol}{Global.Loopback}:{LazyConfig.Instance.StatePort2}"; + return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}"; } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 2a4d97a41e4..5dd97d631bb 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -364,7 +364,7 @@ private static void ToJsonFile(Config config) public static int AddServer(Config config, ProfileItem profileItem) { - var item = LazyConfig.Instance.GetProfileItem(profileItem.indexId); + var item = AppHandler.Instance.GetProfileItem(profileItem.indexId); if (item is null) { item = profileItem; @@ -476,7 +476,7 @@ public static int CopyServer(Config config, List indexes) { foreach (var it in indexes) { - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (item is null) { continue; @@ -541,7 +541,7 @@ public static int SetDefaultServer(Config config, List lstProf public static ProfileItem? GetDefaultServer(Config config) { - var item = LazyConfig.Instance.GetProfileItem(config.indexId); + var item = AppHandler.Instance.GetProfileItem(config.indexId); if (item is null) { var item2 = SQLiteHelper.Instance.Table().FirstOrDefault(); @@ -677,7 +677,7 @@ public static int AddCustomServer(Config config, ProfileItem profileItem, bool b /// public static int EditCustomServer(Config config, ProfileItem profileItem) { - var item = LazyConfig.Instance.GetProfileItem(profileItem.indexId); + var item = AppHandler.Instance.GetProfileItem(profileItem.indexId); if (item is null) { item = profileItem; @@ -717,7 +717,7 @@ public static int AddShadowsocksServer(Config config, ProfileItem profileItem, b profileItem.id = profileItem.id.TrimEx(); profileItem.security = profileItem.security.TrimEx(); - if (!LazyConfig.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security)) + if (!AppHandler.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security)) { return -1; } @@ -894,7 +894,7 @@ public static int AddWireguardServer(Config config, ProfileItem profileItem, boo public static int SortServers(Config config, string subId, string colName, bool asc) { - var lstModel = LazyConfig.Instance.ProfileItems(subId, ""); + var lstModel = AppHandler.Instance.ProfileItems(subId, ""); if (lstModel.Count <= 0) { return -1; @@ -1026,7 +1026,7 @@ public static int AddVlessServer(Config config, ProfileItem profileItem, bool to public static Tuple DedupServerList(Config config, string subId) { - var lstProfile = LazyConfig.Instance.ProfileItems(subId); + var lstProfile = AppHandler.Instance.ProfileItems(subId); List lstKeep = new(); List lstRemove = new(); @@ -1126,7 +1126,7 @@ private static int RemoveProfileItem(Config config, string indexId) { try { - var item = LazyConfig.Instance.GetProfileItem(indexId); + var item = AppHandler.Instance.GetProfileItem(indexId); if (item == null) { return 0; @@ -1161,7 +1161,7 @@ public static int AddCustomServer4Multiple(Config config, List sele return -1; } - var profileItem = LazyConfig.Instance.GetProfileItem(indexId) ?? new(); + var profileItem = AppHandler.Instance.GetProfileItem(indexId) ?? new(); profileItem.indexId = indexId; profileItem.remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer; profileItem.address = Global.CoreMultipleLoadConfigFileName; @@ -1196,7 +1196,7 @@ private static int AddBatchServers(Config config, string strData, string subid, if (isSub && Utils.IsNotEmpty(subid)) { RemoveServerViaSubid(config, subid, isSub); - subFilter = LazyConfig.Instance.GetSubItem(subid)?.filter ?? ""; + subFilter = AppHandler.Instance.GetSubItem(subid)?.filter ?? ""; } int countServers = 0; @@ -1235,7 +1235,7 @@ private static int AddBatchServers(Config config, string strData, string subid, //Check for duplicate indexId if (lstDbIndexId is null) { - lstDbIndexId = LazyConfig.Instance.ProfileItemIndexes(""); + lstDbIndexId = AppHandler.Instance.ProfileItemIndexes(""); } if (lstAdd.Any(t => t.indexId == existItem.indexId) || lstDbIndexId.Any(t => t == existItem.indexId)) @@ -1295,7 +1295,7 @@ private static int AddBatchServers4Custom(Config config, string strData, string return -1; } - var subItem = LazyConfig.Instance.GetSubItem(subid); + var subItem = AppHandler.Instance.GetSubItem(subid); var subRemarks = subItem?.remarks; var preSocksPort = subItem?.preSocksPort; @@ -1430,7 +1430,7 @@ public static int AddBatchServers(Config config, string strData, string subid, b List? lstOriSub = null; if (isSub && Utils.IsNotEmpty(subid)) { - lstOriSub = LazyConfig.Instance.ProfileItems(subid); + lstOriSub = AppHandler.Instance.ProfileItems(subid); } var counter = 0; @@ -1500,7 +1500,7 @@ public static int AddSubItem(Config config, string url) public static int AddSubItem(Config config, SubItem subItem) { - var item = LazyConfig.Instance.GetSubItem(subItem.id); + var item = AppHandler.Instance.GetSubItem(subItem.id); if (item is null) { item = subItem; @@ -1577,7 +1577,7 @@ public static int RemoveServerViaSubid(Config config, string subid, bool isSub) public static int DeleteSubItem(Config config, string id) { - var item = LazyConfig.Instance.GetSubItem(id); + var item = AppHandler.Instance.GetSubItem(id); if (item is null) { return 0; @@ -1752,7 +1752,7 @@ public static int SetDefaultRouting(Config config, RoutingItem routingItem) public static RoutingItem GetDefaultRouting(Config config) { - var item = LazyConfig.Instance.GetRoutingItem(config.routingBasicItem.routingIndexId); + var item = AppHandler.Instance.GetRoutingItem(config.routingBasicItem.routingIndexId); if (item is null) { var item2 = SQLiteHelper.Instance.Table().FirstOrDefault(t => t.locked == false); @@ -1766,7 +1766,7 @@ public static RoutingItem GetDefaultRouting(Config config) public static int InitBuiltinRouting(Config config, bool blImportAdvancedRules = false) { var ver = "V3-"; - var items = LazyConfig.Instance.RoutingItems(); + var items = AppHandler.Instance.RoutingItems(); if (blImportAdvancedRules || items.Where(t => t.remarks.StartsWith(ver)).ToList().Count <= 0) { var maxSort = items.Count; @@ -1832,7 +1832,7 @@ public static void RemoveRoutingItem(RoutingItem routingItem) public static int InitBuiltinDNS(Config config) { - var items = LazyConfig.Instance.DNSItems(); + var items = AppHandler.Instance.DNSItems(); if (items.Count <= 0) { var item = new DNSItem() diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs index 95647599ada..b81ad37b29e 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs @@ -78,14 +78,14 @@ public int GenerateClientCustomConfig(ProfileItem node, string? fileName, out st } //port - fileContent["port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); + fileContent["port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); //socks-port - fileContent["socks-port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); + fileContent["socks-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); //log-level fileContent["log-level"] = GetLogLevel(_config.coreBasicItem.loglevel); //external-controller - fileContent["external-controller"] = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}"; + fileContent["external-controller"] = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}"; //allow-lan if (_config.inbound[0].allowLANConn) { diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigHandler.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigHandler.cs index 72cea3d7e2f..ab42da0bd3f 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigHandler.cs @@ -15,7 +15,7 @@ public static int GenerateClientConfig(ProfileItem node, string? fileName, out s msg = ResUI.CheckServerSettings; return -1; } - var config = LazyConfig.Instance.Config; + var config = AppHandler.Instance.Config; msg = ResUI.InitialConfiguration; if (node.configType == EConfigType.Custom) @@ -35,7 +35,7 @@ public static int GenerateClientConfig(ProfileItem node, string? fileName, out s return GenerateClientCustomConfig(node, fileName, out msg); } } - else if (LazyConfig.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box) + else if (AppHandler.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box) { var configGenSingbox = new CoreConfigSingbox(config); if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0) diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs index 823c0b29619..712a0a572ae 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs @@ -120,7 +120,7 @@ public int GenerateClientSpeedtestConfig(List selecteds, out Sin singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. singboxConfig.outbounds.RemoveAt(0); - int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest); + int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); foreach (var it in selecteds) { @@ -132,7 +132,7 @@ public int GenerateClientSpeedtestConfig(List selecteds, out Sin { continue; } - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (it.configType is EConfigType.VMess or EConfigType.VLESS) { if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) @@ -282,7 +282,7 @@ public int GenerateClientMultipleLoadConfig(List selecteds, out Sin { continue; } - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (item is null) { continue; @@ -486,7 +486,7 @@ private int GenInbounds(SingboxConfig singboxConfig) }; singboxConfig.inbounds.Add(inbound); - inbound.listen_port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); + inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); inbound.sniff = _config.inbound[0].sniffingEnabled; inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled; inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null : _config.routingBasicItem.domainStrategy4Singbox; @@ -600,7 +600,7 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound) } case EConfigType.Shadowsocks: { - outbound.method = LazyConfig.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : Global.None; + outbound.method = AppHandler.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : Global.None; outbound.password = node.id; GenOutboundMux(node, outbound); @@ -854,7 +854,7 @@ private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig) } try { - var subItem = LazyConfig.Instance.GetSubItem(node.subid); + var subItem = AppHandler.Instance.GetSubItem(node.subid); if (subItem is null) { return 0; @@ -865,7 +865,7 @@ private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig) var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound); //Previous proxy - var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile); + var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile); if (prevNode is not null && prevNode.configType != EConfigType.Custom) { @@ -878,7 +878,7 @@ private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig) } //Next proxy - var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile); + var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile); if (nextNode is not null && nextNode.configType != EConfigType.Custom) { @@ -1173,7 +1173,7 @@ private int GenDns(ProfileItem? node, SingboxConfig singboxConfig) { try { - var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); + var item = AppHandler.Instance.GetDNSItem(ECoreType.sing_box); var strDNS = string.Empty; if (_config.tunModeItem.enableTun) { @@ -1260,7 +1260,7 @@ private int GenExperimental(SingboxConfig singboxConfig) singboxConfig.experimental ??= new Experimental4Sbox(); singboxConfig.experimental.clash_api = new Clash_Api4Sbox() { - external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}", + external_controller = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}", }; } diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs index 582b67fc5f4..14f4df67062 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs @@ -118,7 +118,7 @@ public int GenerateClientMultipleLoadConfig(List selecteds, out V2r { continue; } - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (item is null) { continue; @@ -236,7 +236,7 @@ public int GenerateClientSpeedtestConfig(List selecteds, out V2r v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. v2rayConfig.outbounds.RemoveAt(0); - int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest); + int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); foreach (var it in selecteds) { @@ -248,7 +248,7 @@ public int GenerateClientSpeedtestConfig(List selecteds, out V2r { continue; } - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (it.configType is EConfigType.VMess or EConfigType.VLESS) { if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) @@ -637,7 +637,7 @@ private int GenOutbound(ProfileItem node, Outbounds4Ray outbound) serversItem.address = node.address; serversItem.port = node.port; serversItem.password = node.id; - serversItem.method = LazyConfig.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : "none"; + serversItem.method = AppHandler.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : "none"; serversItem.ota = false; serversItem.level = 1; @@ -1029,7 +1029,7 @@ private int GenDns(ProfileItem? node, V2rayConfig v2rayConfig) { try { - var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); + var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray); var normalDNS = item?.normalDNS; var domainStrategy4Freedom = item?.domainStrategy4Freedom; if (Utils.IsNullOrEmpty(normalDNS)) @@ -1136,7 +1136,7 @@ private int GenStatistic(V2rayConfig v2rayConfig) Inboundsettings4Ray apiInboundSettings = new(); apiInbound.tag = tag; apiInbound.listen = Global.Loopback; - apiInbound.port = LazyConfig.Instance.StatePort; + apiInbound.port = AppHandler.Instance.StatePort; apiInbound.protocol = Global.InboundAPIProtocol; apiInboundSettings.address = Global.Loopback; apiInbound.settings = apiInboundSettings; @@ -1193,7 +1193,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig) } try { - var subItem = LazyConfig.Instance.GetSubItem(node.subid); + var subItem = AppHandler.Instance.GetSubItem(node.subid); if (subItem is null) { return 0; @@ -1204,7 +1204,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig) var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); //Previous proxy - var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile); + var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile); if (prevNode is not null && prevNode.configType != EConfigType.Custom && prevNode.configType != EConfigType.Hysteria2 @@ -1223,7 +1223,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig) } //Next proxy - var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile); + var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile); if (nextNode is not null && nextNode.configType != EConfigType.Custom && nextNode.configType != EConfigType.Hysteria2 diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 0dc9c5fec56..9b48b35a54c 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -182,7 +182,7 @@ private void CoreStart(ProfileItem node) //{ // coreType = LazyConfig.Instance.GetCoreType(node, node.configType); //} - var coreType = LazyConfig.Instance.GetCoreType(node, node.configType); + var coreType = AppHandler.Instance.GetCoreType(node, node.configType); _config.runningCoreType = coreType; var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType); @@ -207,7 +207,7 @@ private void CoreStart(ProfileItem node) configType = EConfigType.SOCKS, address = Global.Loopback, sni = node.address, //Tun2SocksAddress - port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks) + port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks) }; } else if ((node.configType == EConfigType.Custom && node.preSocksPort > 0)) @@ -339,7 +339,7 @@ private void ShowMsg(bool notify, string msg) startUpSuccessful = true; } - LazyConfig.Instance.AddProcess(proc.Handle); + AppHandler.Instance.AddProcess(proc.Handle); return proc; } catch (Exception ex) diff --git a/v2rayN/ServiceLib/Handler/DownloadHandler.cs b/v2rayN/ServiceLib/Handler/DownloadHandler.cs index c05b992874b..8b7832d56ba 100644 --- a/v2rayN/ServiceLib/Handler/DownloadHandler.cs +++ b/v2rayN/ServiceLib/Handler/DownloadHandler.cs @@ -30,7 +30,7 @@ public async Task DownloadDataAsync(string url, WebProxy webProxy, int down { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13); var progress = new Progress(); progress.ProgressChanged += (sender, value) => @@ -62,7 +62,7 @@ public async Task DownloadFileAsync(string url, string fileName, bool blProxy, i { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13); UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}")); var progress = new Progress(); @@ -92,7 +92,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, public async Task UrlRedirectAsync(string url, bool blProxy) { - Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13); var webRequestHandler = new SocketsHttpHandler { AllowAutoRedirect = false, @@ -181,7 +181,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13); var webProxy = GetWebProxy(blProxy); var client = new HttpClient(new SocketsHttpHandler() { @@ -226,7 +226,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13); var webProxy = GetWebProxy(blProxy); @@ -260,7 +260,7 @@ public async Task RunAvailabilityCheck(IWebProxy? webProxy) try { - var config = LazyConfig.Instance.Config; + var config = AppHandler.Instance.Config; int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10); return responseTime; } @@ -314,7 +314,7 @@ public async Task GetRealPingTime(string url, IWebProxy? webProxy, int down { return null; } - var httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); + var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); if (!SocketCheck(Global.Loopback, httpPort)) { return null; diff --git a/v2rayN/ServiceLib/Handler/SpeedtestHandler.cs b/v2rayN/ServiceLib/Handler/SpeedtestHandler.cs index 07636cb181d..b7d124b1023 100644 --- a/v2rayN/ServiceLib/Handler/SpeedtestHandler.cs +++ b/v2rayN/ServiceLib/Handler/SpeedtestHandler.cs @@ -236,7 +236,7 @@ private async Task RunSpeedTestAsync() ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); UpdateFunc(it.indexId, "", ResUI.Speedtesting); - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (item is null) continue; WebProxy webProxy = new(Global.Loopback, it.port); @@ -299,7 +299,7 @@ private async Task RunSpeedTestMulti() ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); UpdateFunc(it.indexId, "", ResUI.Speedtesting); - var item = LazyConfig.Instance.GetProfileItem(it.indexId); + var item = AppHandler.Instance.GetProfileItem(it.indexId); if (item is null) continue; WebProxy webProxy = new(Global.Loopback, it.port); diff --git a/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs b/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs index 2052121646b..60aca1579ed 100644 --- a/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs +++ b/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs @@ -26,7 +26,7 @@ private async void Init() try { - url = $"ws://{Global.Loopback}:{LazyConfig.Instance.StatePort2}/traffic"; + url = $"ws://{Global.Loopback}:{AppHandler.Instance.StatePort2}/traffic"; if (webSocket == null) { diff --git a/v2rayN/ServiceLib/Handler/Statistics/StatisticsV2ray.cs b/v2rayN/ServiceLib/Handler/Statistics/StatisticsV2ray.cs index 55b15b30959..32399f4e43c 100644 --- a/v2rayN/ServiceLib/Handler/Statistics/StatisticsV2ray.cs +++ b/v2rayN/ServiceLib/Handler/Statistics/StatisticsV2ray.cs @@ -29,7 +29,7 @@ private void GrpcInit() { try { - _channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{LazyConfig.Instance.StatePort}"); + _channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}"); _client = new StatsService.StatsServiceClient(_channel); } catch (Exception ex) diff --git a/v2rayN/ServiceLib/Handler/TaskHandler.cs b/v2rayN/ServiceLib/Handler/TaskHandler.cs index 3d2df325d62..61cddeffcd7 100644 --- a/v2rayN/ServiceLib/Handler/TaskHandler.cs +++ b/v2rayN/ServiceLib/Handler/TaskHandler.cs @@ -24,7 +24,7 @@ private async Task UpdateTaskRunSubscription(Config config, Action while (true) { var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); - var lstSubs = LazyConfig.Instance.SubItems() + var lstSubs = AppHandler.Instance.SubItems() .Where(t => t.autoUpdateInterval > 0) .Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60) .ToList(); diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs index f26a1d6e213..35db828efc3 100644 --- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs +++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs @@ -128,7 +128,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, _updateFunc = update; _updateFunc(false, ResUI.MsgUpdateSubscriptionStart); - var subItem = LazyConfig.Instance.SubItems().OrderBy(t => t.sort).ToList(); + var subItem = AppHandler.Instance.SubItems().OrderBy(t => t.sort).ToList(); if (subItem == null || subItem.Count <= 0) { diff --git a/v2rayN/ServiceLib/Handler/WebDavHandler.cs b/v2rayN/ServiceLib/Handler/WebDavHandler.cs index 85d9922f2b4..ea9b714a628 100644 --- a/v2rayN/ServiceLib/Handler/WebDavHandler.cs +++ b/v2rayN/ServiceLib/Handler/WebDavHandler.cs @@ -17,7 +17,7 @@ public sealed class WebDavHandler public WebDavHandler() { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; } private async Task GetClient() diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index 589cc628f5e..bee32971e63 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -103,8 +103,6 @@ public class GUIItem public int trayMenuServersLimit { get; set; } = 20; public bool enableHWA { get; set; } = false; - - public bool enableLog { get; set; } = true; } [Serializable] diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index 5f198da7c2c..8c1545b8c87 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -21,7 +21,7 @@ public class AddServer2ViewModel : MyReactiveObject public AddServer2ViewModel(ProfileItem profileItem, Func>? updateView) { _noticeHandler = Locator.Current.GetService(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; if (profileItem.indexId.IsNullOrEmpty()) @@ -84,7 +84,7 @@ public void BrowseServer(string fileName) return; } - var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId); + var item = AppHandler.Instance.GetProfileItem(SelectedSource.indexId); item ??= SelectedSource; item.address = fileName; if (ConfigHandler.AddCustomServer(_config, item, false) == 0) diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index f0176f90f25..574eed8cfbf 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -17,7 +17,7 @@ public class AddServerViewModel : MyReactiveObject public AddServerViewModel(ProfileItem profileItem, Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs index e83abe1f5cc..0ddceeb4452 100644 --- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs @@ -22,7 +22,7 @@ public class BackupAndRestoreViewModel : MyReactiveObject public BackupAndRestoreViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; _noticeHandler = Locator.Current.GetService(); diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index b757f856dcb..26d4720bea0 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -22,7 +22,7 @@ public class CheckUpdateViewModel : MyReactiveObject public CheckUpdateViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; _noticeHandler = Locator.Current.GetService(); diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index caa776dc4e5..7016a43a169 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -30,7 +30,7 @@ public class ClashConnectionsViewModel : MyReactiveObject public ClashConnectionsViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; SortingSelected = _config.clashUIItem.connectionsSorting; AutoRefresh = _config.clashUIItem.connectionsAutoRefresh; diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 782ac5dc57a..822ec95e5f6 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -45,7 +45,7 @@ public class ClashProxiesViewModel : MyReactiveObject public ClashProxiesViewModel(Func>? updateView) { _noticeHandler = Locator.Current.GetService(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; SelectedGroup = new(); diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index 3541ff043cf..e283a915969 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -23,17 +23,17 @@ public class DNSSettingViewModel : MyReactiveObject public DNSSettingViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; - var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); + var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray); useSystemHosts = item.useSystemHosts; domainStrategy4Freedom = item?.domainStrategy4Freedom ?? string.Empty; domainDNSAddress = item?.domainDNSAddress ?? string.Empty; normalDNS = item?.normalDNS ?? string.Empty; - var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); + var item2 = AppHandler.Instance.GetDNSItem(ECoreType.sing_box); domainStrategy4Freedom2 = item2?.domainStrategy4Freedom ?? string.Empty; domainDNSAddress2 = item2?.domainDNSAddress ?? string.Empty; normalDNS2 = item2?.normalDNS ?? string.Empty; @@ -92,14 +92,14 @@ private async Task SaveSettingAsync() } } - var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); + var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray); item.domainStrategy4Freedom = domainStrategy4Freedom; item.domainDNSAddress = domainDNSAddress; item.useSystemHosts = useSystemHosts; item.normalDNS = normalDNS; ConfigHandler.SaveDNSItems(_config, item); - var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); + var item2 = AppHandler.Instance.GetDNSItem(ECoreType.sing_box); item2.domainStrategy4Freedom = domainStrategy4Freedom2; item2.domainDNSAddress = domainDNSAddress2; item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2)); diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 10e67403b44..b6e6ac7b66a 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -146,7 +146,7 @@ public class MainWindowViewModel : MyReactiveObject public MainWindowViewModel(bool isAdministrator, Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; _isAdministrator = isAdministrator; @@ -486,7 +486,7 @@ public void RefreshServersBiz() private void RefreshServersMenu() { - var lstModel = LazyConfig.Instance.ProfileItems(_config.subIndexId, ""); + var lstModel = AppHandler.Instance.ProfileItems(_config.subIndexId, ""); _servers.Clear(); if (lstModel.Count > _config.guiItem.trayMenuServersLimit) @@ -591,7 +591,7 @@ private void SetDefaultServer(string indexId) { return; } - var item = LazyConfig.Instance.GetProfileItem(indexId); + var item = AppHandler.Instance.GetProfileItem(indexId); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); @@ -809,7 +809,7 @@ private void RefreshRoutingsMenu() } BlRouting = true; - var routings = LazyConfig.Instance.RoutingItems(); + var routings = AppHandler.Instance.RoutingItems(); foreach (var item in routings) { _routingItems.Add(item); @@ -832,7 +832,7 @@ private async Task RoutingSelectedChangedAsync(bool c) return; } - var item = LazyConfig.Instance.GetRoutingItem(SelectedRouting?.id); + var item = AppHandler.Instance.GetRoutingItem(SelectedRouting?.id); if (item is null) { return; @@ -887,7 +887,7 @@ private void DoEnableTun(bool c) public void InboundDisplayStaus() { StringBuilder sb = new(); - sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]"); + sb.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]"); sb.Append(" | "); //if (_config.systemProxyItem.sysProxyType == ESysProxyType.ForcedChange) //{ @@ -895,7 +895,7 @@ public void InboundDisplayStaus() //} //else //{ - sb.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http)}]"); + sb.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http)}]"); //} InboundDisplay = $"{ResUI.LabLocal}:{sb}"; @@ -904,9 +904,9 @@ public void InboundDisplayStaus() if (_config.inbound[0].newPort4LAN) { StringBuilder sb2 = new(); - sb2.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); + sb2.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); sb2.Append(" | "); - sb2.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http2)}]"); + sb2.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http2)}]"); InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}"; } else diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index 0f924c36c1e..bbf72308ca9 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -22,7 +22,7 @@ public class MsgViewModel : MyReactiveObject public MsgViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _updateView = updateView; _noticeHandler = Locator.Current.GetService(); diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index a2221486a1b..fde0ff907c6 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -102,7 +102,7 @@ public class OptionSettingViewModel : MyReactiveObject public OptionSettingViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index dca473fa589..59085a2e668 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -97,7 +97,7 @@ public class ProfilesViewModel : MyReactiveObject public ProfilesViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; @@ -350,7 +350,7 @@ public void RefreshServers() public void RefreshServersBiz() { - var lstModel = LazyConfig.Instance.ProfileItemsEx(_config.subIndexId, _serverFilter); + var lstModel = AppHandler.Instance.ProfileItemsEx(_config.subIndexId, _serverFilter); _lstProfile = JsonUtils.Deserialize>(JsonUtils.Serialize(lstModel)) ?? []; _profileItems.Clear(); @@ -374,7 +374,7 @@ public void RefreshSubscriptions() _subItems.Clear(); _subItems.Add(new SubItem { remarks = ResUI.AllGroupServers }); - foreach (var item in LazyConfig.Instance.SubItems().OrderBy(t => t.sort)) + foreach (var item in AppHandler.Instance.SubItems().OrderBy(t => t.sort)) { _subItems.Add(item); } @@ -405,7 +405,7 @@ private int GetProfileItems(out List lstSelecteds, bool latest) { foreach (var profile in orderProfiles) { - var item = LazyConfig.Instance.GetProfileItem(profile.indexId); + var item = AppHandler.Instance.GetProfileItem(profile.indexId); if (item is not null) { lstSelecteds.Add(item); @@ -426,7 +426,7 @@ public async Task EditServerAsync(EConfigType eConfigType) { return; } - var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); + var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); @@ -515,7 +515,7 @@ private void SetDefaultServer(string indexId) { return; } - var item = LazyConfig.Instance.GetProfileItem(indexId); + var item = AppHandler.Instance.GetProfileItem(indexId); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); @@ -548,7 +548,7 @@ private void ServerSelectedChanged(bool c) public async Task ShareServerAsync() { - var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); + var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); @@ -681,7 +681,7 @@ public void ServerSpeedtestStop() private async Task Export2ClientConfigAsync(bool blClipboard) { - var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); + var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); @@ -767,7 +767,7 @@ private async Task EditSubAsync(bool blNew) } else { - item = LazyConfig.Instance.GetSubItem(_config.subIndexId); + item = AppHandler.Instance.GetSubItem(_config.subIndexId); if (item is null) { return; diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs index 4c9f03db258..c6b7e0b654d 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs @@ -29,7 +29,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index 3adfa633114..ef988c7418b 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -36,7 +36,7 @@ public class RoutingRuleSettingViewModel : MyReactiveObject public RoutingRuleSettingViewModel(RoutingItem routingItem, Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; SelectedSource = new(); diff --git a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs index ce0ba953554..0e7eb84a2ed 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs @@ -67,7 +67,7 @@ public class RoutingSettingViewModel : MyReactiveObject public RoutingSettingViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; SelectedSource = new(); @@ -165,7 +165,7 @@ public void RefreshRoutingItems() { _routingItems.Clear(); - var routings = LazyConfig.Instance.RoutingItems(); + var routings = AppHandler.Instance.RoutingItems(); foreach (var item in routings) { bool def = false; @@ -232,7 +232,7 @@ public async Task RoutingAdvancedEditAsync(bool blNew) } else { - item = LazyConfig.Instance.GetRoutingItem(SelectedSource?.id); + item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id); if (item is null) { return; @@ -258,7 +258,7 @@ public async Task RoutingAdvancedRemoveAsync() } foreach (var it in SelectedSources ?? [SelectedSource]) { - var item = LazyConfig.Instance.GetRoutingItem(it?.id); + var item = AppHandler.Instance.GetRoutingItem(it?.id); if (item != null) { ConfigHandler.RemoveRoutingItem(item); @@ -271,7 +271,7 @@ public async Task RoutingAdvancedRemoveAsync() public void RoutingAdvancedSetDefault() { - var item = LazyConfig.Instance.GetRoutingItem(SelectedSource?.id); + var item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id); if (item is null) { _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); diff --git a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs index 487f34cea7a..a8dfa0138f8 100644 --- a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs @@ -14,7 +14,7 @@ public class SubEditViewModel : MyReactiveObject public SubEditViewModel(SubItem subItem, Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; diff --git a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs index 632cddf4f22..d98229423c9 100644 --- a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs @@ -25,7 +25,7 @@ public class SubSettingViewModel : MyReactiveObject public SubSettingViewModel(Func>? updateView) { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; @@ -58,7 +58,7 @@ public SubSettingViewModel(Func>? updateView) public void RefreshSubItems() { _subItems.Clear(); - _subItems.AddRange(LazyConfig.Instance.SubItems().OrderBy(t => t.sort)); + _subItems.AddRange(AppHandler.Instance.SubItems().OrderBy(t => t.sort)); } public async Task EditSubAsync(bool blNew) @@ -70,7 +70,7 @@ public async Task EditSubAsync(bool blNew) } else { - item = LazyConfig.Instance.GetSubItem(SelectedSource?.id); + item = AppHandler.Instance.GetSubItem(SelectedSource?.id); if (item is null) { return; diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index dbd26f537c1..308a200c68e 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Splat; using v2rayN.Desktop.ViewModels; using v2rayN.Desktop.Views; @@ -10,11 +9,14 @@ namespace v2rayN.Desktop; public partial class App : Application { //public static EventWaitHandle ProgramStarted; - private static Config _config; public override void Initialize() { - Init(); + if (!AppHandler.Instance.InitApp()) + { + Environment.Exit(0); + return; + } AvaloniaXamlLoader.Load(this); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; @@ -49,30 +51,7 @@ private void OnStartup(string[]? Args) // return; //} - Logging.Setup(); - Logging.LoggingEnabled(_config.guiItem.enableLog); - Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); - Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}"); - Logging.ClearLogs(); - } - - private void Init() - { - if (ConfigHandler.LoadConfig(ref _config) != 0) - { - //Logging.SaveLog($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}����GUI�����ļ��쳣,������Ӧ��"); - Environment.Exit(0); - return; - } - LazyConfig.Instance.SetConfig(_config); - Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler)); - Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); - - //Under Win10 - if (Utils.IsWindows() && Environment.OSVersion.Version.Major < 10) - { - Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User); - } + AppHandler.Instance.InitComponents(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) diff --git a/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs b/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs index b635e97e9d0..26163db2e1f 100644 --- a/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs +++ b/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs @@ -16,9 +16,9 @@ public static async Task UpdateSysProxy(Config config, bool forceDisable) try { - int port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); - int portSocks = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); - int portPac = LazyConfig.Instance.GetLocalPort(EInboundProtocol.pac); + int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); + int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); + int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac); if (port <= 0) { return false; diff --git a/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs index e38132295bd..9842e06611b 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs @@ -16,7 +16,7 @@ public class AppViewModel : MyReactiveObject public AppViewModel() { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); AddServerViaClipboardCmd = ReactiveCommand.Create(() => diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs index 86b0529298e..2638f556167 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs @@ -21,7 +21,7 @@ public class ThemeSettingViewModel : MyReactiveObject public ThemeSettingViewModel() { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); BindingUI(); diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs index 010cceb027b..e7f35643bf0 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs @@ -79,7 +79,7 @@ public AddServerWindow(ProfileItem profileItem) case EConfigType.Shadowsocks: gridSs.IsVisible = true; - LazyConfig.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => + AppHandler.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => { cmbSecurity3.Items.Add(it); }); diff --git a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs index 6287a4088a8..5e05b10d295 100644 --- a/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/DNSSettingWindow.axaml.cs @@ -13,7 +13,7 @@ public DNSSettingWindow() { InitializeComponent(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; btnCancel.Click += (s, e) => this.Close(); ViewModel = new DNSSettingViewModel(UpdateViewHandler); diff --git a/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs index a24423d6b85..2bfb7d897da 100644 --- a/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs @@ -12,7 +12,7 @@ public GlobalHotkeySettingWindow() InitializeComponent(); btnCancel.Click += (s, e) => this.Close(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; //_config.globalHotkeys ??= new List(); //txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_PreviewKeyDown; diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 7010f5aa13d..f5406798abb 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -27,7 +27,7 @@ public MainWindow() { InitializeComponent(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight }; //ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 56771b2db94..dd52aa92190 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -14,7 +14,7 @@ public OptionSettingWindow() InitializeComponent(); btnCancel.Click += (s, e) => this.Close(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; // var lstFonts = GetFonts(Utils.GetFontsPath()); ViewModel = new OptionSettingViewModel(UpdateViewHandler); diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index d2ae87b2860..018482e832e 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -21,7 +21,7 @@ public ProfilesView(Window window) { InitializeComponent(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _window = window; menuSelectAll.Click += menuSelectAll_Click; diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index d66ac929b0f..43ce041ab51 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -1,5 +1,4 @@ -using Splat; -using System.Diagnostics; +using System.Diagnostics; using System.Windows; using System.Windows.Threading; @@ -38,34 +37,15 @@ protected override void OnStartup(StartupEventArgs e) return; } - Logging.Setup(); - Init(); - Logging.LoggingEnabled(_config.guiItem.enableLog); - Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); - Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}"); - Logging.ClearLogs(); - - Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); - - base.OnStartup(e); - } - - private void Init() - { - if (ConfigHandler.LoadConfig(ref _config) != 0) + if (!AppHandler.Instance.InitApp()) { UI.Show($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用"); Environment.Exit(0); return; } - LazyConfig.Instance.SetConfig(_config); - Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler)); - //Under Win10 - if (Environment.OSVersion.Version.Major < 10) - { - Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User); - } + AppHandler.Instance.InitComponents(); + base.OnStartup(e); } private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index 0be5bade539..84e6182367b 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -10,7 +10,7 @@ static MaterialDesignFonts() { try { - var fontFamily = LazyConfig.Instance.Config.uiItem.currentFontFamily; + var fontFamily = AppHandler.Instance.Config.uiItem.currentFontFamily; if (Utils.IsNotEmpty(fontFamily)) { var fontPath = Utils.GetFontsPath(); diff --git a/v2rayN/v2rayN/Handler/HotkeyHandler.cs b/v2rayN/v2rayN/Handler/HotkeyHandler.cs index d3010fa75fd..42c4092fbd3 100644 --- a/v2rayN/v2rayN/Handler/HotkeyHandler.cs +++ b/v2rayN/v2rayN/Handler/HotkeyHandler.cs @@ -16,7 +16,7 @@ public sealed class HotkeyHandler private Config _config { - get => LazyConfig.Instance.Config; + get => AppHandler.Instance.Config; } private Dictionary> _hotkeyTriggerDic; diff --git a/v2rayN/v2rayN/Handler/SysProxyHandler.cs b/v2rayN/v2rayN/Handler/SysProxyHandler.cs index 1374bac614a..b61f0317da8 100644 --- a/v2rayN/v2rayN/Handler/SysProxyHandler.cs +++ b/v2rayN/v2rayN/Handler/SysProxyHandler.cs @@ -15,9 +15,9 @@ public static bool UpdateSysProxy(Config config, bool forceDisable) try { - int port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); - int portSocks = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); - int portPac = LazyConfig.Instance.GetLocalPort(EInboundProtocol.pac); + int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); + int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); + int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac); if (port <= 0) { return false; diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index f64b416ffc5..bce52e8ca38 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -37,7 +37,7 @@ public class ThemeSettingViewModel : MyReactiveObject public ThemeSettingViewModel() { - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _noticeHandler = Locator.Current.GetService(); RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); }); diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index 3bee918268a..aac024641bc 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -34,7 +34,7 @@ public AddServer2Window(ProfileItem profileItem) 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.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 03de4390547..7eff73a2339 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -73,7 +73,7 @@ public AddServerWindow(ProfileItem profileItem) case EConfigType.Shadowsocks: gridSs.Visibility = Visibility.Visible; - LazyConfig.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => + AppHandler.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => { cmbSecurity3.Items.Add(it); }); @@ -219,7 +219,7 @@ public AddServerWindow(ProfileItem profileItem) }); this.Title = $"{profileItem.configType}"; - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index 0b029e3562b..1868fc2e246 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -13,7 +13,7 @@ public DNSSettingWindow() InitializeComponent(); this.Owner = Application.Current.MainWindow; - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; ViewModel = new DNSSettingViewModel(UpdateViewHandler); @@ -50,7 +50,7 @@ public DNSSettingWindow() 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.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index df6547382d0..cb168658a0e 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -16,7 +16,7 @@ public GlobalHotkeySettingWindow() InitializeComponent(); this.Owner = Application.Current.MainWindow; - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; _config.globalHotkeys ??= new List(); btnReset.Click += btnReset_Click; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 7bdb8206015..e9eb6761f66 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -23,7 +23,7 @@ public MainWindow() { InitializeComponent(); - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); App.Current.SessionEnding += Current_SessionEnding; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 0bdd2d353e1..cc70ddd0b6f 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -16,7 +16,7 @@ public OptionSettingWindow() InitializeComponent(); this.Owner = Application.Current.MainWindow; - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; var lstFonts = GetFonts(Utils.GetFontsPath()); ViewModel = new OptionSettingViewModel(UpdateViewHandler); @@ -165,7 +165,7 @@ public OptionSettingWindow() this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 49ad8ade83b..de1dc7e4c65 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -22,7 +22,7 @@ public ProfilesView() InitializeComponent(); lstGroup.MaxHeight = Math.Floor(SystemParameters.WorkArea.Height * 0.20 / 40) * 40; - _config = LazyConfig.Instance.Config; + _config = AppHandler.Instance.Config; Application.Current.Exit += Current_Exit; btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 4e1f301bd0b..c5069638252 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -58,7 +58,7 @@ public RoutingRuleDetailsWindow(RulesItem rulesItem) this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 31de968d6c7..0423341e9c2 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -60,7 +60,7 @@ public RoutingRuleSettingWindow(RoutingItem routingItem) this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index a31a645f7e0..ee8adcd007f 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -66,7 +66,7 @@ public RoutingSettingWindow() this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index 1773ee57a55..f23081e6cd6 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -37,7 +37,7 @@ public SubEditWindow(SubItem subItem) this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj) diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index 800a76f9a03..472c8b60a48 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -31,7 +31,7 @@ public SubSettingWindow() 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.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); + WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark); } private async Task UpdateViewHandler(EViewAction action, object? obj)