diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index 9fbaf10f..05087494 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -54,7 +54,7 @@ namespace v2rayN { if (ConfigHandler.LoadConfig(ref _config) != 0) { - UI.ShowWarning($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用"); + UI.Show($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用"); Application.Current.Shutdown(); Environment.Exit(0); return; diff --git a/v2rayN/v2rayN/Common/UI.cs b/v2rayN/v2rayN/Common/UI.cs index 226757c4..7b608e96 100644 --- a/v2rayN/v2rayN/Common/UI.cs +++ b/v2rayN/v2rayN/Common/UI.cs @@ -12,11 +12,6 @@ namespace v2rayN MessageBox.Show(msg, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); } - public static void ShowWarning(string msg) - { - MessageBox.Show(msg, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); - } - public static MessageBoxResult ShowYesNo(string msg) { return MessageBox.Show(msg, caption, MessageBoxButton.YesNo, MessageBoxImage.Question); diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 6eb700f3..c8bc583e 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -1186,7 +1186,7 @@ namespace v2rayN.Handler ProfileItem profileItem = new(); //Is v2ray configuration - V2rayConfig? v2rayConfig = JsonUtile.Deserialize(clipboardData); + var v2rayConfig = JsonUtile.Deserialize(clipboardData); if (v2rayConfig?.inbounds?.Count > 0 && v2rayConfig.outbounds?.Count > 0) { diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 7fb3d4ad..75897885 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; +using Splat; using System.Drawing; using System.IO; using System.Windows.Media.Imaging; @@ -125,7 +126,7 @@ namespace v2rayN.Handler } if (item.configType == EConfigType.Custom) { - UI.Show(ResUI.NonVmessService); + Locator.Current.GetService()?.Enqueue(ResUI.NonVmessService); return; } @@ -146,11 +147,12 @@ namespace v2rayN.Handler } if (CoreConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0) { - UI.Show(msg); + Locator.Current.GetService()?.Enqueue(msg); } else { - UI.ShowWarning(string.Format(ResUI.SaveClientConfigurationIn, fileName)); + msg = string.Format(ResUI.SaveClientConfigurationIn, fileName); + Locator.Current.GetService()?.SendMessageAndEnqueue(msg); } } diff --git a/v2rayN/v2rayN/Handler/NoticeHandler.cs b/v2rayN/v2rayN/Handler/NoticeHandler.cs index 3402bf42..570308f6 100644 --- a/v2rayN/v2rayN/Handler/NoticeHandler.cs +++ b/v2rayN/v2rayN/Handler/NoticeHandler.cs @@ -29,5 +29,11 @@ namespace v2rayN.Handler msg = $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {msg}"; MessageBus.Current.SendMessage(msg, Global.CommandSendMsgView); } + + public void SendMessageAndEnqueue(string msg) + { + _snackbarMessageQueue?.Enqueue(msg); + MessageBus.Current.SendMessage(msg, Global.CommandSendMsgView); + } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs index f1f2c374..02204701 100644 --- a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs @@ -64,13 +64,13 @@ namespace v2rayN.ViewModels string remarks = SelectedSource.remarks; if (Utile.IsNullOrEmpty(remarks)) { - UI.Show(ResUI.PleaseFillRemarks); + _noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); return; } if (Utile.IsNullOrEmpty(SelectedSource.address)) { - UI.Show(ResUI.FillServerAddressCustom); + _noticeHandler?.Enqueue(ResUI.FillServerAddressCustom); return; } @@ -95,13 +95,13 @@ namespace v2rayN.ViewModels } else { - UI.Show(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } private void BrowseServer() { - //UI.Show(ResUI.CustomServerTips); + //_noticeHandler?.Enqueue(ResUI.CustomServerTips); if (UI.OpenFileDialog(out string fileName, "Config|*.json|YAML|*.yaml;*.yml|All|*.*") != true) @@ -127,7 +127,7 @@ namespace v2rayN.ViewModels } else { - UI.ShowWarning(ResUI.FailedImportedCustomServer); + _noticeHandler?.Enqueue(ResUI.FailedImportedCustomServer); } } @@ -136,7 +136,7 @@ namespace v2rayN.ViewModels var address = SelectedSource.address; if (Utile.IsNullOrEmpty(address)) { - UI.Show(ResUI.FillServerAddressCustom); + _noticeHandler?.Enqueue(ResUI.FillServerAddressCustom); return; } diff --git a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs index bc1b8f24..2c63007b 100644 --- a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs @@ -51,32 +51,32 @@ namespace v2rayN.ViewModels { if (Utile.IsNullOrEmpty(SelectedSource.remarks)) { - UI.Show(ResUI.PleaseFillRemarks); + _noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); return; } if (Utile.IsNullOrEmpty(SelectedSource.address)) { - UI.Show(ResUI.FillServerAddress); + _noticeHandler?.Enqueue(ResUI.FillServerAddress); return; } var port = SelectedSource.port.ToString(); if (Utile.IsNullOrEmpty(port) || !Utile.IsNumeric(port) || SelectedSource.port <= 0 || SelectedSource.port >= Global.MaxPort) { - UI.Show(ResUI.FillCorrectServerPort); + _noticeHandler?.Enqueue(ResUI.FillCorrectServerPort); return; } if (SelectedSource.configType == EConfigType.Shadowsocks) { if (Utile.IsNullOrEmpty(SelectedSource.id)) { - UI.Show(ResUI.FillPassword); + _noticeHandler?.Enqueue(ResUI.FillPassword); return; } if (Utile.IsNullOrEmpty(SelectedSource.security)) { - UI.Show(ResUI.PleaseSelectEncryption); + _noticeHandler?.Enqueue(ResUI.PleaseSelectEncryption); return; } } @@ -84,7 +84,7 @@ namespace v2rayN.ViewModels { if (Utile.IsNullOrEmpty(SelectedSource.id)) { - UI.Show(ResUI.FillUUID); + _noticeHandler?.Enqueue(ResUI.FillUUID); return; } } @@ -143,7 +143,7 @@ namespace v2rayN.ViewModels } else { - UI.Show(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } } diff --git a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs index 169ce11c..65460921 100644 --- a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs @@ -71,7 +71,7 @@ namespace v2rayN.ViewModels { if (normalDNS.Contains("{") || normalDNS.Contains("}")) { - UI.Show(ResUI.FillCorrectDNSText); + _noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); return; } } @@ -81,7 +81,7 @@ namespace v2rayN.ViewModels var obj2 = JsonUtile.Deserialize(normalDNS2); if (obj2 == null) { - UI.Show(ResUI.FillCorrectDNSText); + _noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); return; } } @@ -90,7 +90,7 @@ namespace v2rayN.ViewModels var obj2 = JsonUtile.Deserialize(tunDNS2); if (obj2 == null) { - UI.Show(ResUI.FillCorrectDNSText); + _noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); return; } } diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index a373a70a..0606d51e 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -1434,11 +1434,11 @@ namespace v2rayN.ViewModels InitSubscriptionView(); RefreshServers(); Reload(); - UI.Show(ResUI.OperationSuccess); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); } else { - _noticeHandler.Enqueue(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index f860055d..abf5620c 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -252,7 +252,7 @@ namespace v2rayN.ViewModels if (Utile.IsNullOrEmpty(localPort.ToString()) || !Utile.IsNumeric(localPort.ToString()) || localPort <= 0 || localPort >= Global.MaxPort) { - UI.Show(ResUI.FillLocalListeningPort); + _noticeHandler?.Enqueue(ResUI.FillLocalListeningPort); return; } @@ -263,7 +263,7 @@ namespace v2rayN.ViewModels // || Utile.IsNullOrEmpty(KcpreadBufferSize.ToString()) || !Utile.IsNumeric(KcpreadBufferSize.ToString()) // || Utile.IsNullOrEmpty(KcpwriteBufferSize.ToString()) || !Utile.IsNumeric(KcpwriteBufferSize.ToString())) //{ - // UI.Show(ResUI.FillKcpParameters); + // _noticeHandler?.Enqueue(ResUI.FillKcpParameters); // return; //} @@ -342,7 +342,7 @@ namespace v2rayN.ViewModels } else { - UI.ShowWarning(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs index 997ff002..cb728361 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs @@ -94,7 +94,7 @@ namespace v2rayN.ViewModels if (!hasRule) { - UI.ShowWarning(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP/Process")); + _noticeHandler?.Enqueue(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP/Process")); return; } //_noticeHandler?.Enqueue(ResUI.OperationSuccess); diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs index 7884437a..419ca3c0 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs @@ -169,7 +169,7 @@ namespace v2rayN.ViewModels { if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) { - UI.Show(ResUI.PleaseSelectRules); + _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No) @@ -192,7 +192,7 @@ namespace v2rayN.ViewModels { if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) { - UI.Show(ResUI.PleaseSelectRules); + _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } @@ -208,7 +208,7 @@ namespace v2rayN.ViewModels if (lst.Count > 0) { Utile.SetClipboardData(JsonUtile.Serialize(lst)); - //UI.Show(ResUI.OperationSuccess")); + //_noticeHandler?.Enqueue(ResUI.OperationSuccess")); } } @@ -216,7 +216,7 @@ namespace v2rayN.ViewModels { if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) { - UI.Show(ResUI.PleaseSelectRules); + _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } @@ -237,7 +237,7 @@ namespace v2rayN.ViewModels string remarks = SelectedRouting.remarks; if (Utile.IsNullOrEmpty(remarks)) { - UI.Show(ResUI.PleaseFillRemarks); + _noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); return; } var item = SelectedRouting; @@ -255,7 +255,7 @@ namespace v2rayN.ViewModels } else { - UI.ShowWarning(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } @@ -282,7 +282,7 @@ namespace v2rayN.ViewModels if (AddBatchRoutingRules(SelectedRouting, result) == 0) { RefreshRulesItems(); - UI.Show(ResUI.OperationSuccess); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } @@ -292,7 +292,7 @@ namespace v2rayN.ViewModels if (AddBatchRoutingRules(SelectedRouting, clipboardData) == 0) { RefreshRulesItems(); - UI.Show(ResUI.OperationSuccess); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } @@ -301,7 +301,7 @@ namespace v2rayN.ViewModels var url = SelectedRouting.url; if (Utile.IsNullOrEmpty(url)) { - UI.Show(ResUI.MsgNeedUrl); + _noticeHandler?.Enqueue(ResUI.MsgNeedUrl); return; } @@ -313,7 +313,7 @@ namespace v2rayN.ViewModels { RefreshRulesItems(); })); - UI.Show(ResUI.OperationSuccess); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index bb08a4ec..49685466 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -214,7 +214,7 @@ namespace v2rayN.ViewModels } else { - UI.ShowWarning(ResUI.OperationFailed); + _noticeHandler?.Enqueue(ResUI.OperationFailed); } } @@ -229,7 +229,7 @@ namespace v2rayN.ViewModels BlockDomain = "geosite:category-ads-all"; //_noticeHandler?.Enqueue(ResUI.OperationSuccess); - UI.Show(ResUI.OperationSuccess); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); } public void RoutingAdvancedEdit(bool blNew) @@ -259,7 +259,7 @@ namespace v2rayN.ViewModels { if (SelectedSource is null || SelectedSource.remarks.IsNullOrEmpty()) { - UI.Show(ResUI.PleaseSelectRules); + _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No) @@ -284,7 +284,7 @@ namespace v2rayN.ViewModels var item = LazyConfig.Instance.GetRoutingItem(SelectedSource?.id); if (item is null) { - UI.Show(ResUI.PleaseSelectRules); + _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } diff --git a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs index 5098c7f3..ce20356f 100644 --- a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs @@ -48,7 +48,7 @@ namespace v2rayN.ViewModels string remarks = SelectedSource.remarks; if (string.IsNullOrEmpty(remarks)) { - UI.Show(ResUI.PleaseFillRemarks); + _noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); return; } diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index f34907f5..151fb60f 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -119,7 +119,7 @@ namespace v2rayN.Views } else { - UI.ShowWarning(ResUI.OperationFailed); + UI.Show(ResUI.OperationFailed); } }