diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 0b0bd44837..d78a52c11e 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -110,7 +110,7 @@ public static List String2List(string str) catch (Exception ex) { Logging.SaveLog(ex.Message, ex); - return new List(); + return []; } } @@ -131,7 +131,7 @@ public static List String2ListSorted(string str) catch (Exception ex) { Logging.SaveLog(ex.Message, ex); - return new List(); + return []; } } @@ -640,29 +640,16 @@ public static string GetDownloadFileName(string url) return fileName; } - public static IPAddress? GetDefaultGateway() - { - return NetworkInterface - .GetAllNetworkInterfaces() - .Where(n => n.OperationalStatus == OperationalStatus.Up) - .Where(n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback) - .SelectMany(n => n.GetIPProperties()?.GatewayAddresses) - .Select(g => g?.Address) - .Where(a => a != null) - // .Where(a => a.AddressFamily == AddressFamily.InterNetwork) - // .Where(a => Array.FindIndex(a.GetAddressBytes(), b => b != 0) >= 0) - .FirstOrDefault(); - } - public static bool IsGuidByParse(string strSrc) { - return Guid.TryParse(strSrc, out Guid g); + return Guid.TryParse(strSrc, out _); } - public static void ProcessStart(string fileName, string arguments = "") + public static void ProcessStart(string? fileName, string arguments = "") { try { + if (fileName.IsNullOrEmpty()) { return; } Process.Start(new ProcessStartInfo(fileName, arguments) { UseShellExecute = true }); } catch (Exception ex) diff --git a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs index 1084cd4c8f..c27dda9ec5 100644 --- a/v2rayN/ServiceLib/Handler/ClashApiHandler.cs +++ b/v2rayN/ServiceLib/Handler/ClashApiHandler.cs @@ -10,12 +10,12 @@ public sealed class ClashApiHandler private Dictionary? _proxies; public Dictionary ProfileContent { get; set; } - public void GetClashProxies(Config config, Action update) + public void GetClashProxies(Config config, Action updateFunc) { - Task.Run(() => GetClashProxiesAsync(config, update)); + Task.Run(() => GetClashProxiesAsync(config, updateFunc)); } - private async Task GetClashProxiesAsync(Config config, Action update) + private async Task GetClashProxiesAsync(Config config, Action updateFunc) { for (var i = 0; i < 5; i++) { @@ -30,15 +30,15 @@ private async Task GetClashProxiesAsync(Config config, Action lstProxy, Action update) + public void ClashProxiesDelayTest(bool blAll, List lstProxy, Action updateFunc) { Task.Run(() => { @@ -90,13 +90,13 @@ public void ClashProxiesDelayTest(bool blAll, List lstProxy, Ac tasks.Add(Task.Run(async () => { var result = await HttpClientHelper.Instance.TryGetAsync(url); - update(it, result); + updateFunc?.Invoke(it, result); })); } Task.WaitAll(tasks.ToArray()); Task.Delay(1000).Wait(); - update(null, ""); + updateFunc?.Invoke(null, ""); }); } @@ -164,12 +164,12 @@ public async void ClashConfigReload(string filePath) } } - public void GetClashConnections(Config config, Action update) + public void GetClashConnections(Config config, Action updateFunc) { - Task.Run(() => GetClashConnectionsAsync(config, update)); + Task.Run(() => GetClashConnectionsAsync(config, updateFunc)); } - private async Task GetClashConnectionsAsync(Config config, Action update) + private async Task GetClashConnectionsAsync(Config config, Action updateFunc) { try { @@ -177,7 +177,7 @@ private async Task GetClashConnectionsAsync(Config config, Action(result); - update(clashConnections); + updateFunc?.Invoke(clashConnections); } catch (Exception ex) { diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 985eb1d6ff..3c2667e250 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -13,12 +13,12 @@ public class CoreHandler private Config _config; private Process? _process; private Process? _processPre; - private Action _updateFunc; + private Action? _updateFunc; - public void Init(Config config, Action update) + public void Init(Config config, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; Environment.SetEnvironmentVariable("v2ray.location.asset", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("xray.location.asset", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); @@ -267,7 +267,7 @@ private int CoreStartSpeedtest(string configPath, ECoreType coreType) private void ShowMsg(bool notify, string msg) { - _updateFunc(notify, msg); + _updateFunc?.Invoke(notify, msg); } #endregion Private diff --git a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs index 29f2ae706b..9ce5150a38 100644 --- a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs +++ b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs @@ -8,16 +8,16 @@ public class StatisticsHandler private Config _config; private ServerStatItem? _serverStatItem; private List _lstServerStat; - private Action _updateFunc; + private Action? _updateFunc; private StatisticsV2rayService? _statisticsV2Ray; private StatisticsSingboxService? _statisticsSingbox; public List ServerStat => _lstServerStat; - public void Init(Config config, Action update) + public void Init(Config config, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; if (!config.guiItem.enableStatistics) { return; @@ -95,7 +95,7 @@ private void UpdateServerStat(ServerSpeedItem server) server.todayDown = _serverStatItem.todayDown; server.totalUp = _serverStatItem.totalUp; server.totalDown = _serverStatItem.totalDown; - _updateFunc(server); + _updateFunc?.Invoke(server); } private void GetServerStatItem(string indexId) diff --git a/v2rayN/ServiceLib/Handler/TaskHandler.cs b/v2rayN/ServiceLib/Handler/TaskHandler.cs index 7ab5809215..a75470c2bd 100644 --- a/v2rayN/ServiceLib/Handler/TaskHandler.cs +++ b/v2rayN/ServiceLib/Handler/TaskHandler.cs @@ -9,13 +9,13 @@ public TaskHandler() { } - public void RegUpdateTask(Config config, Action update) + public void RegUpdateTask(Config config, Action updateFunc) { - Task.Run(() => UpdateTaskRunSubscription(config, update)); - Task.Run(() => UpdateTaskRunGeo(config, update)); + Task.Run(() => UpdateTaskRunSubscription(config, updateFunc)); + Task.Run(() => UpdateTaskRunGeo(config, updateFunc)); } - private async Task UpdateTaskRunSubscription(Config config, Action update) + private async Task UpdateTaskRunSubscription(Config config, Action updateFunc) { await Task.Delay(60000); Logging.SaveLog("UpdateTaskRunSubscription"); @@ -33,7 +33,7 @@ private async Task UpdateTaskRunSubscription(Config config, Action { updateHandle.UpdateSubscriptionProcess(config, item.id, true, (bool success, string msg) => { - update(success, msg); + updateFunc?.Invoke(success, msg); if (success) Logging.SaveLog("subscription" + msg); }); @@ -46,7 +46,7 @@ private async Task UpdateTaskRunSubscription(Config config, Action } } - private async Task UpdateTaskRunGeo(Config config, Action update) + private async Task UpdateTaskRunGeo(Config config, Action updateFunc) { var autoUpdateGeoTime = DateTime.Now; @@ -65,7 +65,7 @@ private async Task UpdateTaskRunGeo(Config config, Action update) { await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) => { - update(false, msg); + updateFunc?.Invoke(false, msg); }); autoUpdateGeoTime = dtNow; } diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index 8ff61685d1..ab44a0c9fd 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -8,14 +8,14 @@ - + - + diff --git a/v2rayN/ServiceLib/Services/DownloadService.cs b/v2rayN/ServiceLib/Services/DownloadService.cs index bd6dc3621d..97d1080ec1 100644 --- a/v2rayN/ServiceLib/Services/DownloadService.cs +++ b/v2rayN/ServiceLib/Services/DownloadService.cs @@ -26,7 +26,7 @@ public ResultEventArgs(bool success, string msg) } } - public async Task DownloadDataAsync(string url, WebProxy webProxy, int downloadTimeout, Action update) + public async Task DownloadDataAsync(string url, WebProxy webProxy, int downloadTimeout, Action updateFunc) { try { @@ -35,10 +35,10 @@ public async Task DownloadDataAsync(string url, WebProxy webProxy, int down var progress = new Progress(); progress.ProgressChanged += (sender, value) => { - if (update != null) + if (updateFunc != null) { string msg = $"{value}"; - update(false, msg); + updateFunc?.Invoke(false, msg); } }; @@ -49,10 +49,10 @@ await DownloaderHelper.Instance.DownloadDataAsync4Speed(webProxy, } catch (Exception ex) { - update(false, ex.Message); + updateFunc?.Invoke(false, ex.Message); if (ex.InnerException != null) { - update(false, ex.InnerException.Message); + updateFunc?.Invoke(false, ex.InnerException.Message); } } return 0; diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index a708416a52..588e2eef85 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -9,15 +9,15 @@ public class SpeedtestService private Config? _config; private List _selecteds; private ESpeedActionType _actionType; - private Action _updateFunc; + private Action? _updateFunc; private bool _exitLoop = false; - public SpeedtestService(Config config, List selecteds, ESpeedActionType actionType, Action update) + public SpeedtestService(Config config, List selecteds, ESpeedActionType actionType, Action updateFunc) { _config = config; _actionType = actionType; - _updateFunc = update; + _updateFunc = updateFunc; _selecteds = new List(); foreach (var it in selecteds) @@ -383,7 +383,7 @@ private string FormatOut(object time, string unit) private void UpdateFunc(string indexId, string delay, string speed = "") { - _updateFunc(new() { IndexId = indexId, Delay = delay, Speed = speed }); + _updateFunc?.Invoke(new() { IndexId = indexId, Delay = delay, Speed = speed }); } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs index fac3d1b77e..3b7d048406 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs @@ -9,12 +9,12 @@ public class StatisticsSingboxService private bool _exitFlag; private ClientWebSocket? webSocket; private string url = string.Empty; - private Action _updateFunc; + private Action? _updateFunc; - public StatisticsSingboxService(Config config, Action update) + public StatisticsSingboxService(Config config, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; _exitFlag = false; Task.Run(() => Run()); @@ -92,7 +92,7 @@ private async void Run() { ParseOutput(result, out ulong up, out ulong down); - _updateFunc(new ServerSpeedItem() + _updateFunc?.Invoke(new ServerSpeedItem() { proxyUp = (long)(up / 1000), proxyDown = (long)(down / 1000) diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs index a35266ef12..440a6772da 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs @@ -10,12 +10,12 @@ public class StatisticsV2rayService private GrpcChannel? _channel; private StatsService.StatsServiceClient? _client; private bool _exitFlag; - private Action _updateFunc; + private Action? _updateFunc; - public StatisticsV2rayService(Models.Config config, Action update) + public StatisticsV2rayService(Models.Config config, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; _exitFlag = false; GrpcInit(); @@ -70,7 +70,7 @@ private async void Run() if (res != null) { ParseOutput(res.Stat, out ServerSpeedItem server); - _updateFunc(server); + _updateFunc?.Invoke(server); } } if (_channel != null) diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index f9b7babc39..02d54f061f 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -7,7 +7,7 @@ namespace ServiceLib.Services { public class UpdateService { - private Action _updateFunc; + private Action? _updateFunc; private Config _config; private int _timeout = 30; @@ -25,10 +25,10 @@ public ResultEventArgs(bool success, string msg, string url = "") } } - public async Task CheckUpdateGuiN(Config config, Action update, bool preRelease) + public async Task CheckUpdateGuiN(Config config, Action updateFunc, bool preRelease) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; var url = string.Empty; var fileName = string.Empty; @@ -37,25 +37,25 @@ public async Task CheckUpdateGuiN(Config config, Action update, bo { if (args.Success) { - _updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully); - _updateFunc(true, Utils.UrlEncode(fileName)); + _updateFunc?.Invoke(false, ResUI.MsgDownloadV2rayCoreSuccessfully); + _updateFunc?.Invoke(true, Utils.UrlEncode(fileName)); } else { - _updateFunc(false, args.Msg); + _updateFunc?.Invoke(false, args.Msg); } }; downloadHandle.Error += (sender2, args) => { - _updateFunc(false, args.GetException().Message); + _updateFunc?.Invoke(false, args.GetException().Message); }; - _updateFunc(false, string.Format(ResUI.MsgStartUpdating, ECoreType.v2rayN)); + _updateFunc?.Invoke(false, string.Format(ResUI.MsgStartUpdating, ECoreType.v2rayN)); var args = await CheckUpdateAsync(downloadHandle, ECoreType.v2rayN, preRelease); if (args.Success) { - _updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, ECoreType.v2rayN)); - _updateFunc(false, args.Msg); + _updateFunc?.Invoke(false, string.Format(ResUI.MsgParsingSuccessfully, ECoreType.v2rayN)); + _updateFunc?.Invoke(false, args.Msg); url = args.Url; fileName = Utils.GetTempPath(Utils.GetGUID()); @@ -63,14 +63,14 @@ public async Task CheckUpdateGuiN(Config config, Action update, bo } else { - _updateFunc(false, args.Msg); + _updateFunc?.Invoke(false, args.Msg); } } - public async Task CheckUpdateCore(ECoreType type, Config config, Action update, bool preRelease) + public async Task CheckUpdateCore(ECoreType type, Config config, Action updateFunc, bool preRelease) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; var url = string.Empty; var fileName = string.Empty; @@ -79,34 +79,34 @@ public async Task CheckUpdateCore(ECoreType type, Config config, Action { - _updateFunc(false, args.GetException().Message); + _updateFunc?.Invoke(false, args.GetException().Message); }; - _updateFunc(false, string.Format(ResUI.MsgStartUpdating, type)); + _updateFunc?.Invoke(false, string.Format(ResUI.MsgStartUpdating, type)); var args = await CheckUpdateAsync(downloadHandle, type, preRelease); if (args.Success) { - _updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, type)); - _updateFunc(false, args.Msg); + _updateFunc?.Invoke(false, string.Format(ResUI.MsgParsingSuccessfully, type)); + _updateFunc?.Invoke(false, args.Msg); url = args.Url; var ext = Path.GetExtension(url); @@ -117,22 +117,22 @@ public async Task CheckUpdateCore(ECoreType type, Config config, Action update) + public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; - _updateFunc(false, ResUI.MsgUpdateSubscriptionStart); + _updateFunc?.Invoke(false, ResUI.MsgUpdateSubscriptionStart); var subItem = AppHandler.Instance.SubItems().OrderBy(t => t.sort).ToList(); if (subItem == null || subItem.Count <= 0) { - _updateFunc(false, ResUI.MsgNoValidSubscription); + _updateFunc?.Invoke(false, ResUI.MsgNoValidSubscription); return; } @@ -146,7 +146,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, string hashCode = $"{item.remarks}->"; if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || Utils.IsNotEmpty(subId) && item.id != subId) { - //_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}"); + //_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}"); continue; } if (!url.StartsWith(Global.HttpsProtocol) && !url.StartsWith(Global.HttpProtocol)) @@ -155,17 +155,17 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, } if (item.enabled == false) { - _updateFunc(false, $"{hashCode}{ResUI.MsgSkipSubscriptionUpdate}"); + _updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSkipSubscriptionUpdate}"); continue; } var downloadHandle = new DownloadService(); downloadHandle.Error += (sender2, args) => { - _updateFunc(false, $"{hashCode}{args.GetException().Message}"); + _updateFunc?.Invoke(false, $"{hashCode}{args.GetException().Message}"); }; - _updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}"); + _updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}"); //one url url = Utils.GetPunycode(url); @@ -227,14 +227,14 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, if (Utils.IsNullOrEmpty(result)) { - _updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}"); + _updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}"); } else { - _updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}"); + _updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}"); if (result?.Length < 99) { - _updateFunc(false, $"{hashCode}{result}"); + _updateFunc?.Invoke(false, $"{hashCode}{result}"); } int ret = ConfigHandler.AddBatchServers(config, result, id, true); @@ -243,29 +243,29 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, Logging.SaveLog("FailedImportSubscription"); Logging.SaveLog(result); } - _updateFunc(false, + _updateFunc?.Invoke(false, ret > 0 ? $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}" : $"{hashCode}{ResUI.MsgFailedImportSubscription}"); } - _updateFunc(false, "-------------------------------------------------------"); + _updateFunc?.Invoke(false, "-------------------------------------------------------"); } - _updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}"); + _updateFunc?.Invoke(true, $"{ResUI.MsgUpdateSubscriptionEnd}"); }); } - public async Task UpdateGeoFileAll(Config config, Action update) + public async Task UpdateGeoFileAll(Config config, Action updateFunc) { - await UpdateGeoFile("geosite", _config, update); - await UpdateGeoFile("geoip", _config, update); - _updateFunc(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo")); + await UpdateGeoFile("geosite", _config, updateFunc); + await UpdateGeoFile("geoip", _config, updateFunc); + _updateFunc?.Invoke(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo")); } - public async Task RunAvailabilityCheck(Action update) + public async Task RunAvailabilityCheck(Action updateFunc) { var time = await new DownloadService().RunAvailabilityCheck(null); - update(false, string.Format(ResUI.TestMeOutput, time)); + updateFunc?.Invoke(false, string.Format(ResUI.TestMeOutput, time)); } #region private @@ -290,7 +290,7 @@ private async Task CheckUpdateAsync(DownloadService downloadHan catch (Exception ex) { Logging.SaveLog(ex.Message, ex); - _updateFunc(false, ex.Message); + _updateFunc?.Invoke(false, ex.Message); return new ResultEventArgs(false, ex.Message); } } @@ -355,7 +355,7 @@ private SemanticVersion GetCoreVersion(ECoreType type) catch (Exception ex) { Logging.SaveLog(ex.Message, ex); - _updateFunc(false, ex.Message); + _updateFunc?.Invoke(false, ex.Message); return new SemanticVersion(""); } } @@ -419,7 +419,7 @@ private async Task ParseDownloadUrl(ECoreType type, string gitH catch (Exception ex) { Logging.SaveLog(ex.Message, ex); - _updateFunc(false, ex.Message); + _updateFunc?.Invoke(false, ex.Message); return new ResultEventArgs(false, ex.Message); } } @@ -457,10 +457,10 @@ private async Task ParseDownloadUrl(ECoreType type, string gitH return null; } - private async Task UpdateGeoFile(string geoName, Config config, Action update) + private async Task UpdateGeoFile(string geoName, Config config, Action updateFunc) { _config = config; - _updateFunc = update; + _updateFunc = updateFunc; var url = string.Format(Global.GeoUrl, geoName); var fileName = Utils.GetTempPath(Utils.GetGUID()); @@ -469,7 +469,7 @@ private async Task UpdateGeoFile(string geoName, Config config, Action { - _updateFunc(false, args.GetException().Message); + _updateFunc?.Invoke(false, args.GetException().Message); }; await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout); diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index e0e6f7da0f..4fc51b1ec1 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -32,7 +32,7 @@ public CheckUpdateViewModel(Func>? updateView) await CheckUpdate() .ContinueWith(t => { - UpdateFinished(); + _ = UpdateFinished(); }); }); EnableCheckPreReleaseUpdate = _config.guiItem.checkPreReleaseUpdate; diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index cccbc00d3c..13de1799f4 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -38,9 +38,9 @@ public DNSSettingViewModel(Func>? updateView) normalDNS2 = item2?.normalDNS ?? string.Empty; tunDNS2 = item2?.tunDNS ?? string.Empty; - SaveCmd = ReactiveCommand.Create(() => + SaveCmd = ReactiveCommand.CreateFromTask(async () => { - SaveSettingAsync(); + await SaveSettingAsync(); }); ImportDefConfig4V2rayCmd = ReactiveCommand.Create(() => @@ -65,7 +65,7 @@ private async Task SaveSettingAsync() } else { - if (normalDNS.Contains("{") || normalDNS.Contains("}")) + if (normalDNS.Contains('{') || normalDNS.Contains('}')) { NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText); return; diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 188d1810f0..b4ccc9d27f 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -453,7 +453,7 @@ private void AddHelpMenuItem() { var item = new MenuItem() { - Tag = it.Url.Replace(@"/releases", ""), + Tag = it.Url?.Replace(@"/releases", ""), Header = string.Format(ResUI.menuWebsiteItem, it.CoreType.ToString().Replace("_", " ")).UpperFirstChar() }; item.Click += MenuItem_Click; @@ -465,7 +465,7 @@ private void MenuItem_Click(object? sender, RoutedEventArgs e) { if (sender is MenuItem item) { - Utils.ProcessStart(item.Tag.ToString()); + Utils.ProcessStart(item.Tag?.ToString()); } } diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj index e0a8cb1e8d..e6b29cd2d2 100644 --- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj +++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj @@ -25,7 +25,7 @@ - + diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index aa20ee0edf..dcee491695 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -185,7 +185,7 @@ public void ChangePrimaryColor(System.Windows.Media.Color color) _paletteHelper.SetTheme(theme); } - public void RegisterSystemColorSet(Config config, Window window, Action update) + public void RegisterSystemColorSet(Config config, Window window, Action updateFunc) { var helper = new WindowInteropHelper(window); var hwndSource = HwndSource.FromHwnd(helper.EnsureHandle()); @@ -198,7 +198,7 @@ public void RegisterSystemColorSet(Config config, Window window, Action up { if (wParam == IntPtr.Zero && Marshal.PtrToStringUni(lParam) == "ImmersiveColorSet") { - update(!WindowsUtils.IsLightTheme()); + updateFunc?.Invoke(!WindowsUtils.IsLightTheme()); } } }