From b57cdd31bdc919b17f218a21b1da19541358de2e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:51:10 +0800 Subject: [PATCH] Refactor_updateView to add task --- v2rayN/ServiceLib/Base/MyReactiveObject.cs | 2 +- .../ViewModels/AddServer2ViewModel.cs | 12 +- .../ViewModels/AddServerViewModel.cs | 8 +- .../ViewModels/ClashConnectionsViewModel.cs | 6 +- .../ViewModels/ClashProxiesViewModel.cs | 10 +- .../ViewModels/DNSSettingViewModel.cs | 8 +- .../ViewModels/MainWindowViewModel.cs | 116 +++++++++--------- .../ViewModels/OptionSettingViewModel.cs | 8 +- .../ViewModels/ProfilesViewModel.cs | 64 +++++----- .../ViewModels/RoutingRuleDetailsViewModel.cs | 8 +- .../ViewModels/RoutingRuleSettingViewModel.cs | 56 +++++---- .../ViewModels/RoutingSettingViewModel.cs | 20 +-- .../ServiceLib/ViewModels/SubEditViewModel.cs | 8 +- .../ViewModels/SubSettingViewModel.cs | 22 ++-- v2rayN/v2rayN/Views/AddServer2Window.xaml.cs | 4 +- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 4 +- .../v2rayN/Views/ClashConnectionsView.xaml.cs | 4 +- v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs | 4 +- v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 12 +- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 14 +-- .../Views/RoutingRuleDetailsWindow.xaml.cs | 4 +- .../Views/RoutingRuleSettingWindow.xaml.cs | 14 +-- .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 8 +- v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 6 +- 27 files changed, 218 insertions(+), 216 deletions(-) diff --git a/v2rayN/ServiceLib/Base/MyReactiveObject.cs b/v2rayN/ServiceLib/Base/MyReactiveObject.cs index 8d7c3521..7a0a304f 100644 --- a/v2rayN/ServiceLib/Base/MyReactiveObject.cs +++ b/v2rayN/ServiceLib/Base/MyReactiveObject.cs @@ -5,7 +5,7 @@ namespace ServiceLib.Base public class MyReactiveObject : ReactiveObject { protected static Config? _config; - protected Func? _updateView; + protected Func>? _updateView; protected NoticeHandler? _noticeHandler; } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index 9f11cebb..f313e79c 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -15,7 +15,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveServerCmd { get; } public bool IsModified { get; set; } - public AddServer2ViewModel(ProfileItem profileItem, Func? updateView) + public AddServer2ViewModel(ProfileItem profileItem, Func>? updateView) { _noticeHandler = Locator.Current.GetService(); _config = LazyConfig.Instance.Config; @@ -30,9 +30,9 @@ namespace ServiceLib.ViewModels SelectedSource = JsonUtils.DeepCopy(profileItem); } - BrowseServerCmd = ReactiveCommand.Create(() => + BrowseServerCmd = ReactiveCommand.CreateFromTask(async () => { - _updateView?.Invoke(EViewAction.BrowseServer, null); + await _updateView?.Invoke(EViewAction.BrowseServer, null); }); EditServerCmd = ReactiveCommand.Create(() => @@ -42,11 +42,11 @@ namespace ServiceLib.ViewModels SaveServerCmd = ReactiveCommand.Create(() => { - SaveServer(); + SaveServerAsync(); }); } - private void SaveServer() + private async Task SaveServerAsync() { string remarks = SelectedSource.remarks; if (Utils.IsNullOrEmpty(remarks)) @@ -64,7 +64,7 @@ namespace ServiceLib.ViewModels if (ConfigHandler.EditCustomServer(_config, SelectedSource) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 889de9b2..f1dcee79 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -12,7 +12,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveCmd { get; } - public AddServerViewModel(ProfileItem profileItem, Func? updateView) + public AddServerViewModel(ProfileItem profileItem, Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -33,11 +33,11 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveServer(); + SaveServerAsync(); }); } - private void SaveServer() + private async Task SaveServerAsync() { if (Utils.IsNullOrEmpty(SelectedSource.remarks)) { @@ -83,7 +83,7 @@ namespace ServiceLib.ViewModels if (ConfigHandler.AddServer(_config, SelectedSource) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index e733ce6a..5adf7fc9 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -25,7 +25,7 @@ namespace ServiceLib.ViewModels [Reactive] public bool AutoRefresh { get; set; } - public ClashConnectionsViewModel(Func? updateView) + public ClashConnectionsViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _updateView = updateView; @@ -99,14 +99,14 @@ namespace ServiceLib.ViewModels private void GetClashConnections() { - ClashApiHandler.Instance.GetClashConnections(_config, (it) => + ClashApiHandler.Instance.GetClashConnections(_config, async (it) => { if (it == null) { return; } - _updateView?.Invoke(EViewAction.DispatcherRefreshConnections, it?.connections); + await _updateView?.Invoke(EViewAction.DispatcherRefreshConnections, it?.connections); }); } diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index ffdd8562..5fb095c1 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -42,7 +42,7 @@ namespace ServiceLib.ViewModels [Reactive] public bool AutoRefresh { get; set; } - public ClashProxiesViewModel(Func? updateView) + public ClashProxiesViewModel(Func>? updateView) { _noticeHandler = Locator.Current.GetService(); _config = LazyConfig.Instance.Config; @@ -167,7 +167,7 @@ namespace ServiceLib.ViewModels private void GetClashProxies(bool refreshUI) { - ClashApiHandler.Instance.GetClashProxies(_config, (it, it2) => + ClashApiHandler.Instance.GetClashProxies(_config, async (it, it2) => { //UpdateHandler(false, "Refresh Clash Proxies"); _proxies = it?.proxies; @@ -179,7 +179,7 @@ namespace ServiceLib.ViewModels } if (refreshUI) { - _updateView?.Invoke(EViewAction.DispatcherRefreshProxyGroups, null); + await _updateView?.Invoke(EViewAction.DispatcherRefreshProxyGroups, null); } }); } @@ -386,7 +386,7 @@ namespace ServiceLib.ViewModels { //UpdateHandler(false, "Clash Proxies Latency Test"); - ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), (item, result) => + ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) => { if (item == null) { @@ -398,7 +398,7 @@ namespace ServiceLib.ViewModels return; } - _updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.name, Delay = result }); + await _updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.name, Delay = result }); }); } diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index 42a4f5a4..b5bbb399 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -21,7 +21,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand ImportDefConfig4V2rayCmd { get; } public ReactiveCommand ImportDefConfig4SingboxCmd { get; } - public DNSSettingViewModel(Func? updateView) + public DNSSettingViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -41,7 +41,7 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveSetting(); + SaveSettingAsync(); }); ImportDefConfig4V2rayCmd = ReactiveCommand.Create(() => @@ -56,7 +56,7 @@ namespace ServiceLib.ViewModels }); } - private void SaveSetting() + private async Task SaveSettingAsync() { if (!Utils.IsNullOrEmpty(normalDNS)) { @@ -107,7 +107,7 @@ namespace ServiceLib.ViewModels ConfigHandler.SaveDNSItems(_config, item2); _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 6073e9b2..b80db103 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -152,13 +152,13 @@ namespace ServiceLib.ViewModels #region Init - public MainWindowViewModel(Func? updateView) + public MainWindowViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; - MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(x => _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); + MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); SelectedRouting = new(); SelectedServer = new(); @@ -170,7 +170,7 @@ namespace ServiceLib.ViewModels this.WhenAnyValue( x => x.SelectedRouting, y => y != null && !y.remarks.IsNullOrEmpty()) - .Subscribe(c => RoutingSelectedChanged(c)); + .Subscribe(c => RoutingSelectedChangedAsync(c)); this.WhenAnyValue( x => x.SelectedServer, @@ -191,57 +191,57 @@ namespace ServiceLib.ViewModels //servers AddVmessServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.VMess); + AddServerAsync(true, EConfigType.VMess); }); AddVlessServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.VLESS); + AddServerAsync(true, EConfigType.VLESS); }); AddShadowsocksServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Shadowsocks); + AddServerAsync(true, EConfigType.Shadowsocks); }); AddSocksServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Socks); + AddServerAsync(true, EConfigType.Socks); }); AddHttpServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Http); + AddServerAsync(true, EConfigType.Http); }); AddTrojanServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Trojan); + AddServerAsync(true, EConfigType.Trojan); }); AddHysteria2ServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Hysteria2); + AddServerAsync(true, EConfigType.Hysteria2); }); AddTuicServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Tuic); + AddServerAsync(true, EConfigType.Tuic); }); AddWireguardServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Wireguard); + AddServerAsync(true, EConfigType.Wireguard); }); AddCustomServerCmd = ReactiveCommand.Create(() => { - AddServer(true, EConfigType.Custom); + AddServerAsync(true, EConfigType.Custom); }); AddServerViaClipboardCmd = ReactiveCommand.Create(() => { - AddServerViaClipboard(null); + AddServerViaClipboardAsync(null); }); - AddServerViaScanCmd = ReactiveCommand.Create(() => + AddServerViaScanCmd = ReactiveCommand.CreateFromTask(async () => { - _updateView?.Invoke(EViewAction.ScanScreenTask, null); + await _updateView?.Invoke(EViewAction.ScanScreenTask, null); }); //Subscription SubSettingCmd = ReactiveCommand.Create(() => { - SubSetting(); + SubSettingAsync(); }); SubUpdateCmd = ReactiveCommand.Create(() => @@ -264,19 +264,19 @@ namespace ServiceLib.ViewModels //Setting OptionSettingCmd = ReactiveCommand.Create(() => { - OptionSetting(); + OptionSettingAsync(); }); RoutingSettingCmd = ReactiveCommand.Create(() => { - RoutingSetting(); + RoutingSettingAsync(); }); DNSSettingCmd = ReactiveCommand.Create(() => { - DNSSetting(); + DNSSettingAsync(); }); - GlobalHotkeySettingCmd = ReactiveCommand.Create(() => + GlobalHotkeySettingCmd = ReactiveCommand.CreateFromTask(async () => { - if (_updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true) + if (await _updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); } @@ -322,9 +322,9 @@ namespace ServiceLib.ViewModels Reload(); }); - NotifyLeftClickCmd = ReactiveCommand.Create(() => + NotifyLeftClickCmd = ReactiveCommand.CreateFromTask(async () => { - _updateView?.Invoke(EViewAction.ShowHideWindow, null); + await _updateView?.Invoke(EViewAction.ShowHideWindow, null); }); //System proxy @@ -369,7 +369,7 @@ namespace ServiceLib.ViewModels //RefreshServers(); Reload(); - ChangeSystemProxyStatus(_config.systemProxyItem.sysProxyType, true); + ChangeSystemProxyStatusAsync(_config.systemProxyItem.sysProxyType, true); } #endregion Init @@ -402,7 +402,7 @@ namespace ServiceLib.ViewModels } if (_config.uiItem.enableAutoAdjustMainLvColWidth) { - Locator.Current.GetService()?.AutofitColumnWidth(); + Locator.Current.GetService()?.AutofitColumnWidthAsync(); } } } @@ -434,13 +434,13 @@ namespace ServiceLib.ViewModels } } - public void MyAppExit(bool blWindowsShutDown) + public async Task MyAppExitAsync(bool blWindowsShutDown) { try { Logging.SaveLog("MyAppExit Begin"); //if (blWindowsShutDown) - _updateView?.Invoke(EViewAction.UpdateSysProxy, true); + await _updateView?.Invoke(EViewAction.UpdateSysProxy, true); ConfigHandler.SaveConfig(_config); ProfileExHandler.Instance.SaveTo(); @@ -453,7 +453,7 @@ namespace ServiceLib.ViewModels catch { } finally { - _updateView?.Invoke(EViewAction.Shutdown, null); + await _updateView?.Invoke(EViewAction.Shutdown, null); } } @@ -519,7 +519,7 @@ namespace ServiceLib.ViewModels #region Add Servers - public void AddServer(bool blNew, EConfigType eConfigType) + public async Task AddServerAsync(bool blNew, EConfigType eConfigType) { ProfileItem item = new() { @@ -531,11 +531,11 @@ namespace ServiceLib.ViewModels bool? ret = false; if (eConfigType == EConfigType.Custom) { - ret = _updateView?.Invoke(EViewAction.AddServer2Window, item); + ret = await _updateView?.Invoke(EViewAction.AddServer2Window, item); } else { - ret = _updateView?.Invoke(EViewAction.AddServerWindow, item); + ret = await _updateView?.Invoke(EViewAction.AddServerWindow, item); } if (ret == true) { @@ -547,11 +547,11 @@ namespace ServiceLib.ViewModels } } - public void AddServerViaClipboard(string? clipboardData) + public async Task AddServerViaClipboardAsync(string? clipboardData) { if (clipboardData == null) { - _updateView?.Invoke(EViewAction.AddServerViaClipboard, null); + await _updateView?.Invoke(EViewAction.AddServerViaClipboard, null); return; } int ret = ConfigHandler.AddBatchServers(_config, clipboardData, _config.subIndexId, false); @@ -629,7 +629,7 @@ namespace ServiceLib.ViewModels { return; } - (new UpdateHandler()).RunAvailabilityCheck((bool success, string msg) => + (new UpdateHandler()).RunAvailabilityCheck(async (bool success, string msg) => { _noticeHandler?.SendMessage(msg, true); @@ -637,7 +637,7 @@ namespace ServiceLib.ViewModels { return; } - _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); + await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); }); } @@ -650,9 +650,9 @@ namespace ServiceLib.ViewModels #region Subscription - private void SubSetting() + private async Task SubSettingAsync() { - if (_updateView?.Invoke(EViewAction.SubSettingWindow, null) == true) + if (await _updateView?.Invoke(EViewAction.SubSettingWindow, null) == true) { RefreshSubscriptions(); } @@ -667,9 +667,9 @@ namespace ServiceLib.ViewModels #region Setting - private void OptionSetting() + private async Task OptionSettingAsync() { - var ret = _updateView?.Invoke(EViewAction.OptionSettingWindow, null); + var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null); if (ret == true) { //RefreshServers(); @@ -677,9 +677,9 @@ namespace ServiceLib.ViewModels } } - private void RoutingSetting() + private async Task RoutingSettingAsync() { - var ret = _updateView?.Invoke(EViewAction.RoutingSettingWindow, null); + var ret = await _updateView?.Invoke(EViewAction.RoutingSettingWindow, null); if (ret == true) { ConfigHandler.InitBuiltinRouting(_config); @@ -689,9 +689,9 @@ namespace ServiceLib.ViewModels } } - private void DNSSetting() + private async Task DNSSettingAsync() { - var ret = _updateView?.Invoke(EViewAction.DNSSettingWindow, null); + var ret = await _updateView?.Invoke(EViewAction.DNSSettingWindow, null); if (ret == true) { Reload(); @@ -711,7 +711,7 @@ namespace ServiceLib.ViewModels try { Process.Start(startInfo); - MyAppExit(false); + MyAppExitAsync(false); } catch { } } @@ -742,7 +742,7 @@ namespace ServiceLib.ViewModels process.Start(); if (process.Id > 0) { - MyAppExit(false); + MyAppExitAsync(false); } } catch (Exception ex) @@ -796,17 +796,17 @@ namespace ServiceLib.ViewModels { BlReloadEnabled = false; - LoadCore().ContinueWith(task => + LoadCore().ContinueWith(async task => { TestServerAvailability(); - _updateView?.Invoke(EViewAction.DispatcherReload, null); + await _updateView?.Invoke(EViewAction.DispatcherReload, null); }); } public void ReloadResult() { - ChangeSystemProxyStatus(_config.systemProxyItem.sysProxyType, false); + ChangeSystemProxyStatusAsync(_config.systemProxyItem.sysProxyType, false); BlReloadEnabled = true; ShowClashUI = _config.IsRunningCore(ECoreType.clash); if (ShowClashUI) @@ -835,7 +835,7 @@ namespace ServiceLib.ViewModels { ConfigHandler.SaveConfig(_config, false); - ChangeSystemProxyStatus(ESysProxyType.ForcedClear, false); + ChangeSystemProxyStatusAsync(ESysProxyType.ForcedClear, false); _coreHandler.CoreStop(); } @@ -851,15 +851,15 @@ namespace ServiceLib.ViewModels return; } _config.systemProxyItem.sysProxyType = type; - ChangeSystemProxyStatus(type, true); + ChangeSystemProxyStatusAsync(type, true); SystemProxySelected = (int)_config.systemProxyItem.sysProxyType; ConfigHandler.SaveConfig(_config, false); } - private void ChangeSystemProxyStatus(ESysProxyType type, bool blChange) + private async Task ChangeSystemProxyStatusAsync(ESysProxyType type, bool blChange) { - _updateView?.Invoke(EViewAction.UpdateSysProxy, _config.tunModeItem.enableTun ? true : false); + await _updateView?.Invoke(EViewAction.UpdateSysProxy, _config.tunModeItem.enableTun ? true : false); _noticeHandler?.SendMessage($"{ResUI.TipChangeSystemProxy} - {_config.systemProxyItem.sysProxyType.ToString()}", true); BlSystemProxyClear = (type == ESysProxyType.ForcedClear); @@ -871,7 +871,7 @@ namespace ServiceLib.ViewModels if (blChange) { - _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null); + await _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null); } } @@ -896,7 +896,7 @@ namespace ServiceLib.ViewModels } } - private void RoutingSelectedChanged(bool c) + private async Task RoutingSelectedChangedAsync(bool c) { if (!c) { @@ -922,7 +922,7 @@ namespace ServiceLib.ViewModels { _noticeHandler?.SendMessage(ResUI.TipChangeRouting, true); Reload(); - _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null); + await _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null); } } @@ -1001,9 +1001,9 @@ namespace ServiceLib.ViewModels { Observable.Range(1, 1) .Delay(TimeSpan.FromSeconds(1)) - .Subscribe(x => + .Subscribe(async x => { - _updateView?.Invoke(EViewAction.ShowHideWindow, false); + await _updateView?.Invoke(EViewAction.ShowHideWindow, false); }); } } diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 8dc332f3..a2221486 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -100,7 +100,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveCmd { get; } - public OptionSettingViewModel(Func? updateView) + public OptionSettingViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -190,7 +190,7 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveSetting(); + SaveSettingAsync(); }); } @@ -246,7 +246,7 @@ namespace ServiceLib.ViewModels }); } - private void SaveSetting() + private async Task SaveSettingAsync() { if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString()) || localPort <= 0 || localPort >= Global.MaxPort) @@ -343,7 +343,7 @@ namespace ServiceLib.ViewModels { _noticeHandler?.Enqueue(ResUI.OperationSuccess); } - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 46117477..88abe2d7 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -95,13 +95,13 @@ namespace ServiceLib.ViewModels #region Init - public ProfilesViewModel(Func? updateView) + public ProfilesViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; - MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(x => _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); + MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); SelectedProfile = new(); SelectedSub = new(); @@ -120,7 +120,7 @@ namespace ServiceLib.ViewModels this.WhenAnyValue( x => x.SelectedSub, y => y != null && !y.remarks.IsNullOrEmpty() && _config.subIndexId != y.id) - .Subscribe(c => SubSelectedChanged(c)); + .Subscribe(c => SubSelectedChangedAsync(c)); this.WhenAnyValue( x => x.SelectedMoveToGroup, y => y != null && !y.remarks.IsNullOrEmpty()) @@ -139,11 +139,11 @@ namespace ServiceLib.ViewModels //servers delete EditServerCmd = ReactiveCommand.Create(() => { - EditServer(EConfigType.Custom); + EditServerAsync(EConfigType.Custom); }, canEditRemove); RemoveServerCmd = ReactiveCommand.Create(() => { - RemoveServer(); + RemoveServerAsync(); }, canEditRemove); RemoveDuplicateServerCmd = ReactiveCommand.Create(() => { @@ -159,7 +159,7 @@ namespace ServiceLib.ViewModels }, canEditRemove); ShareServerCmd = ReactiveCommand.Create(() => { - ShareServer(); + ShareServerAsync(); }, canEditRemove); SetDefaultMultipleServerCmd = ReactiveCommand.Create(() => { @@ -212,29 +212,29 @@ namespace ServiceLib.ViewModels //servers export Export2ClientConfigCmd = ReactiveCommand.Create(() => { - Export2ClientConfig(false); + Export2ClientConfigAsync(false); }, canEditRemove); Export2ClientConfigClipboardCmd = ReactiveCommand.Create(() => { - Export2ClientConfig(true); + Export2ClientConfigAsync(true); }, canEditRemove); Export2ShareUrlCmd = ReactiveCommand.Create(() => { - Export2ShareUrl(false); + Export2ShareUrlAsync(false); }, canEditRemove); Export2ShareUrlBase64Cmd = ReactiveCommand.Create(() => { - Export2ShareUrl(true); + Export2ShareUrlAsync(true); }, canEditRemove); //Subscription AddSubCmd = ReactiveCommand.Create(() => { - EditSub(true); + EditSubAsync(true); }); EditSubCmd = ReactiveCommand.Create(() => { - EditSub(false); + EditSubAsync(false); }); #endregion WhenAnyValue && ReactiveCommand @@ -308,16 +308,16 @@ namespace ServiceLib.ViewModels } } - public void AutofitColumnWidth() + public async Task AutofitColumnWidthAsync() { - _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null); + await _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null); } #endregion Actions #region Servers && Groups - private void SubSelectedChanged(bool c) + private async Task SubSelectedChangedAsync(bool c) { if (!c) { @@ -327,7 +327,7 @@ namespace ServiceLib.ViewModels RefreshServers(); - _updateView?.Invoke(EViewAction.ProfilesFocus, null); + await _updateView?.Invoke(EViewAction.ProfilesFocus, null); } private void ServerFilterChanged(bool c) @@ -420,7 +420,7 @@ namespace ServiceLib.ViewModels return 0; } - public void EditServer(EConfigType eConfigType) + public async Task EditServerAsync(EConfigType eConfigType) { if (Utils.IsNullOrEmpty(SelectedProfile?.indexId)) { @@ -437,11 +437,11 @@ namespace ServiceLib.ViewModels bool? ret = false; if (eConfigType == EConfigType.Custom) { - ret = _updateView?.Invoke(EViewAction.AddServer2Window, item); + ret = await _updateView?.Invoke(EViewAction.AddServer2Window, item); } else { - ret = _updateView?.Invoke(EViewAction.AddServerWindow, item); + ret = await _updateView?.Invoke(EViewAction.AddServerWindow, item); } if (ret == true) { @@ -453,13 +453,13 @@ namespace ServiceLib.ViewModels } } - public void RemoveServer() + public async Task RemoveServerAsync() { if (GetProfileItems(out List lstSelecteds, true) < 0) { return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) + if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } @@ -546,7 +546,7 @@ namespace ServiceLib.ViewModels SetDefaultServer(SelectedServer.ID); } - public void ShareServer() + public async Task ShareServerAsync() { var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); if (item is null) @@ -560,7 +560,7 @@ namespace ServiceLib.ViewModels return; } - _updateView?.Invoke(EViewAction.ShareServer, url); + await _updateView?.Invoke(EViewAction.ShareServer, url); } private void SetDefaultMultipleServer(ECoreType coreType) @@ -679,7 +679,7 @@ namespace ServiceLib.ViewModels _speedtestHandler?.ExitLoop(); } - private void Export2ClientConfig(bool blClipboard) + private async Task Export2ClientConfigAsync(bool blClipboard) { var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); if (item is null) @@ -695,13 +695,13 @@ namespace ServiceLib.ViewModels } else { - _updateView?.Invoke(EViewAction.SetClipboardData, content); + await _updateView?.Invoke(EViewAction.SetClipboardData, content); _noticeHandler?.SendMessage(ResUI.OperationSuccess); } } else { - _updateView?.Invoke(EViewAction.SaveFileDialog, item); + await _updateView?.Invoke(EViewAction.SaveFileDialog, item); } } @@ -722,7 +722,7 @@ namespace ServiceLib.ViewModels } } - public void Export2ShareUrl(bool blEncode) + public async Task Export2ShareUrlAsync(bool blEncode) { if (GetProfileItems(out List lstSelecteds, true) < 0) { @@ -744,11 +744,11 @@ namespace ServiceLib.ViewModels { if (blEncode) { - _updateView?.Invoke(EViewAction.SetClipboardData, Utils.Base64Encode(sb.ToString())); + await _updateView?.Invoke(EViewAction.SetClipboardData, Utils.Base64Encode(sb.ToString())); } else { - _updateView?.Invoke(EViewAction.SetClipboardData, sb.ToString()); + await _updateView?.Invoke(EViewAction.SetClipboardData, sb.ToString()); } _noticeHandler?.SendMessage(ResUI.BatchExportURLSuccessfully); } @@ -758,7 +758,7 @@ namespace ServiceLib.ViewModels #region Subscription - private void EditSub(bool blNew) + private async Task EditSubAsync(bool blNew) { SubItem item; if (blNew) @@ -773,10 +773,10 @@ namespace ServiceLib.ViewModels return; } } - if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true) + if (await _updateView?.Invoke(EViewAction.SubEditWindow, item) == true) { RefreshSubscriptions(); - SubSelectedChanged(true); + SubSelectedChangedAsync(true); } } diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs index 60294a42..8acfc234 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs @@ -27,7 +27,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveCmd { get; } - public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func? updateView) + public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -51,11 +51,11 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveRules(); + SaveRulesAsync(); }); } - private void SaveRules() + private async Task SaveRulesAsync() { Domain = Utils.Convert2Comma(Domain); IP = Utils.Convert2Comma(IP); @@ -88,7 +88,7 @@ namespace ServiceLib.ViewModels return; } //_noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index d76e26e0..fa0a57ef 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -34,7 +34,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveCmd { get; } - public RoutingRuleSettingViewModel(RoutingItem routingItem, Func? updateView) + public RoutingRuleSettingViewModel(RoutingItem routingItem, Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -60,15 +60,15 @@ namespace ServiceLib.ViewModels RuleAddCmd = ReactiveCommand.Create(() => { - RuleEdit(true); + RuleEditAsync(true); }); - ImportRulesFromFileCmd = ReactiveCommand.Create(() => + ImportRulesFromFileCmd = ReactiveCommand.CreateFromTask(async () => { - _updateView?.Invoke(EViewAction.ImportRulesFromFile, null); + await _updateView?.Invoke(EViewAction.ImportRulesFromFile, null); }); ImportRulesFromClipboardCmd = ReactiveCommand.Create(() => { - ImportRulesFromClipboard(null); + ImportRulesFromClipboardAsync(null); }); ImportRulesFromUrlCmd = ReactiveCommand.Create(() => { @@ -77,11 +77,11 @@ namespace ServiceLib.ViewModels RuleRemoveCmd = ReactiveCommand.Create(() => { - RuleRemove(); + RuleRemoveAsync(); }, canEditRemove); RuleExportSelectedCmd = ReactiveCommand.Create(() => { - RuleExportSelected(); + RuleExportSelectedAsync(); }, canEditRemove); MoveTopCmd = ReactiveCommand.Create(() => @@ -103,7 +103,7 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveRouting(); + SaveRoutingAsync(); }); } @@ -129,7 +129,7 @@ namespace ServiceLib.ViewModels } } - public void RuleEdit(bool blNew) + public async Task RuleEditAsync(bool blNew) { RulesItem? item; if (blNew) @@ -144,7 +144,7 @@ namespace ServiceLib.ViewModels return; } } - if (_updateView?.Invoke(EViewAction.RoutingRuleDetailsWindow, item) == true) + if (await _updateView?.Invoke(EViewAction.RoutingRuleDetailsWindow, item) == true) { if (blNew) { @@ -154,14 +154,14 @@ namespace ServiceLib.ViewModels } } - public void RuleRemove() + public async Task RuleRemoveAsync() { if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) { _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) + if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } @@ -177,7 +177,7 @@ namespace ServiceLib.ViewModels RefreshRulesItems(); } - public void RuleExportSelected() + public async Task RuleExportSelectedAsync() { if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) { @@ -197,7 +197,7 @@ namespace ServiceLib.ViewModels } if (lst.Count > 0) { - _updateView?.Invoke(EViewAction.SetClipboardData, JsonUtils.Serialize(lst)); + await _updateView?.Invoke(EViewAction.SetClipboardData, JsonUtils.Serialize(lst)); } } @@ -221,7 +221,7 @@ namespace ServiceLib.ViewModels } } - private void SaveRouting() + private async Task SaveRoutingAsync() { string remarks = SelectedRouting.remarks; if (Utils.IsNullOrEmpty(remarks)) @@ -240,7 +240,7 @@ namespace ServiceLib.ViewModels if (ConfigHandler.SaveRoutingItem(_config, item) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { @@ -250,7 +250,7 @@ namespace ServiceLib.ViewModels #region Import rules - public void ImportRulesFromFile(string fileName) + public async Task ImportRulesFromFileAsync(string fileName) { if (Utils.IsNullOrEmpty(fileName)) { @@ -262,29 +262,30 @@ namespace ServiceLib.ViewModels { return; } - - if (AddBatchRoutingRules(SelectedRouting, result) == 0) + var ret = await AddBatchRoutingRulesAsync(SelectedRouting, result); + if (ret == 0) { RefreshRulesItems(); _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } - public void ImportRulesFromClipboard(string? clipboardData) + public async Task ImportRulesFromClipboardAsync(string? clipboardData) { if (clipboardData == null) { - _updateView?.Invoke(EViewAction.ImportRulesFromClipboard, null); + await _updateView?.Invoke(EViewAction.ImportRulesFromClipboard, null); return; } - if (AddBatchRoutingRules(SelectedRouting, clipboardData) == 0) + var ret = await AddBatchRoutingRulesAsync(SelectedRouting, clipboardData); + if (ret == 0) { RefreshRulesItems(); _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } - private void ImportRulesFromUrl() + private async void ImportRulesFromUrl() { var url = SelectedRouting.url; if (Utils.IsNullOrEmpty(url)) @@ -294,18 +295,19 @@ namespace ServiceLib.ViewModels } DownloadHandler downloadHandle = new DownloadHandler(); - var result = downloadHandle.TryDownloadString(url, true, "").Result; - if (AddBatchRoutingRules(SelectedRouting, result) == 0) + var result = await downloadHandle.TryDownloadString(url, true, ""); + var ret = await AddBatchRoutingRulesAsync(SelectedRouting, result); + if (ret == 0) { RefreshRulesItems(); _noticeHandler?.Enqueue(ResUI.OperationSuccess); } } - private int AddBatchRoutingRules(RoutingItem routingItem, string? clipboardData) + private async Task AddBatchRoutingRulesAsync(RoutingItem routingItem, string? clipboardData) { bool blReplace = false; - if (_updateView?.Invoke(EViewAction.AddBatchRoutingRulesYesNo, null) == false) + if (await _updateView?.Invoke(EViewAction.AddBatchRoutingRulesYesNo, null) == false) { blReplace = true; } diff --git a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs index bf059948..ce0ba953 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs @@ -65,7 +65,7 @@ namespace ServiceLib.ViewModels #endregion Reactive - public RoutingSettingViewModel(Func? updateView) + public RoutingSettingViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -98,11 +98,11 @@ namespace ServiceLib.ViewModels RoutingAdvancedAddCmd = ReactiveCommand.Create(() => { - RoutingAdvancedEdit(true); + RoutingAdvancedEditAsync(true); }); RoutingAdvancedRemoveCmd = ReactiveCommand.Create(() => { - RoutingAdvancedRemove(); + RoutingAdvancedRemoveAsync(); }, canEditRemove); RoutingAdvancedSetDefaultCmd = ReactiveCommand.Create(() => { @@ -115,7 +115,7 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveRouting(); + SaveRoutingAsync(); }); } @@ -189,7 +189,7 @@ namespace ServiceLib.ViewModels } } - private void SaveRouting() + private async Task SaveRoutingAsync() { _config.routingBasicItem.domainStrategy = domainStrategy; _config.routingBasicItem.enableRoutingAdvanced = enableRoutingAdvanced; @@ -201,7 +201,7 @@ namespace ServiceLib.ViewModels if (ConfigHandler.SaveConfig(_config) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { @@ -223,7 +223,7 @@ namespace ServiceLib.ViewModels _noticeHandler?.Enqueue(ResUI.OperationSuccess); } - public void RoutingAdvancedEdit(bool blNew) + public async Task RoutingAdvancedEditAsync(bool blNew) { RoutingItem item; if (blNew) @@ -238,21 +238,21 @@ namespace ServiceLib.ViewModels return; } } - if (_updateView?.Invoke(EViewAction.RoutingRuleSettingWindow, item) == true) + if (await _updateView?.Invoke(EViewAction.RoutingRuleSettingWindow, item) == true) { RefreshRoutingItems(); IsModified = true; } } - public void RoutingAdvancedRemove() + public async Task RoutingAdvancedRemoveAsync() { if (SelectedSource is null || SelectedSource.remarks.IsNullOrEmpty()) { _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) + if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } diff --git a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs index 6c10ed51..487f34ce 100644 --- a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs @@ -12,7 +12,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SaveCmd { get; } - public SubEditViewModel(SubItem subItem, Func? updateView) + public SubEditViewModel(SubItem subItem, Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -29,11 +29,11 @@ namespace ServiceLib.ViewModels SaveCmd = ReactiveCommand.Create(() => { - SaveSub(); + SaveSubAsync(); }); } - private void SaveSub() + private async Task SaveSubAsync() { string remarks = SelectedSource.remarks; if (Utils.IsNullOrEmpty(remarks)) @@ -45,7 +45,7 @@ namespace ServiceLib.ViewModels if (ConfigHandler.AddSubItem(_config, SelectedSource) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow, null); + await _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs index 36f63874..632cddf4 100644 --- a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs @@ -23,7 +23,7 @@ namespace ServiceLib.ViewModels public ReactiveCommand SubShareCmd { get; } public bool IsModified { get; set; } - public SubSettingViewModel(Func? updateView) + public SubSettingViewModel(Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); @@ -39,19 +39,19 @@ namespace ServiceLib.ViewModels SubAddCmd = ReactiveCommand.Create(() => { - EditSub(true); + EditSubAsync(true); }); SubDeleteCmd = ReactiveCommand.Create(() => { - DeleteSub(); + DeleteSubAsync(); }, canEditRemove); - SubEditCmd = ReactiveCommand.Create(() => + SubEditCmd = ReactiveCommand.CreateFromTask(async () => { - EditSub(false); + await EditSubAsync(false); }, canEditRemove); - SubShareCmd = ReactiveCommand.Create(() => + SubShareCmd = ReactiveCommand.CreateFromTask(async () => { - _updateView?.Invoke(EViewAction.ShareSub, SelectedSource?.url); + await _updateView?.Invoke(EViewAction.ShareSub, SelectedSource?.url); }, canEditRemove); } @@ -61,7 +61,7 @@ namespace ServiceLib.ViewModels _subItems.AddRange(LazyConfig.Instance.SubItems().OrderBy(t => t.sort)); } - public void EditSub(bool blNew) + public async Task EditSubAsync(bool blNew) { SubItem item; if (blNew) @@ -76,16 +76,16 @@ namespace ServiceLib.ViewModels return; } } - if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true) + if (await _updateView?.Invoke(EViewAction.SubEditWindow, item) == true) { RefreshSubItems(); IsModified = true; } } - private void DeleteSub() + private async Task DeleteSubAsync() { - if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) + if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index b3038418..b9bdf56a 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -37,7 +37,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -54,7 +54,7 @@ namespace v2rayN.Views break; } - return true; + return await Task.FromResult(true); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index e2da0157..f9607334 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -220,7 +220,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -228,7 +228,7 @@ namespace v2rayN.Views this.DialogResult = true; break; } - return true; + return await Task.FromResult(true); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs index d3c61617..c90fcfad 100644 --- a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs +++ b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs @@ -29,7 +29,7 @@ namespace v2rayN.Views }); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -42,7 +42,7 @@ namespace v2rayN.Views break; } - return true; + return await Task.FromResult(true); } private void btnClose_Click(object sender, System.Windows.RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs b/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs index 0715a30c..5142f72b 100644 --- a/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs @@ -39,7 +39,7 @@ namespace v2rayN.Views }); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -60,7 +60,7 @@ namespace v2rayN.Views break; } - return true; + return await Task.FromResult(true); } private void ProxiesView_KeyDown(object sender, KeyEventArgs e) diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index 08c55513..0b029e35 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -53,7 +53,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -61,7 +61,7 @@ namespace v2rayN.Views this.DialogResult = true; break; } - return true; + return await Task.FromResult(true); } private void linkDnsObjectDoc_Click(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 82e60c51..baecf506 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -204,7 +204,7 @@ namespace v2rayN.Views }), DispatcherPriority.Normal); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -291,11 +291,11 @@ namespace v2rayN.Views case EViewAction.AddServerViaClipboard: var clipboardData = WindowsUtils.GetClipboardData(); - ViewModel?.AddServerViaClipboard(clipboardData); + ViewModel?.AddServerViaClipboardAsync(clipboardData); break; } - return true; + return await Task.FromResult(true); } private void OnHotkeyHandler(EGlobalHotkey e) @@ -336,14 +336,14 @@ namespace v2rayN.Views tbNotify.Dispose(); StorageUI(); - ViewModel?.MyAppExit(false); + ViewModel?.MyAppExitAsync(false); } private void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e) { Logging.SaveLog("Current_SessionEnding"); StorageUI(); - ViewModel?.MyAppExit(true); + ViewModel?.MyAppExitAsync(true); } private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e) @@ -354,7 +354,7 @@ namespace v2rayN.Views { case Key.V: var clipboardData = WindowsUtils.GetClipboardData(); - ViewModel?.AddServerViaClipboard(clipboardData); + ViewModel?.AddServerViaClipboardAsync(clipboardData); break; case Key.S: diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index c5549a30..0bdd2d35 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -168,7 +168,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -177,7 +177,7 @@ namespace v2rayN.Views this.DialogResult = true; break; } - return true; + return await Task.FromResult(true); } private List GetFonts(string path) diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 3f2530eb..f2fad81d 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -98,7 +98,7 @@ namespace v2rayN.Views StorageUI(); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -173,7 +173,7 @@ namespace v2rayN.Views break; } - return true; + return await Task.FromResult(true); } public async void ShareServer(string url) @@ -206,7 +206,7 @@ namespace v2rayN.Views } else { - ViewModel?.EditServer(EConfigType.Custom); + ViewModel?.EditServerAsync(EConfigType.Custom); } } @@ -238,15 +238,15 @@ namespace v2rayN.Views break; case Key.C: - ViewModel?.Export2ShareUrl(false); + ViewModel?.Export2ShareUrlAsync(false); break; case Key.D: - ViewModel?.EditServer(EConfigType.Custom); + ViewModel?.EditServerAsync(EConfigType.Custom); break; case Key.F: - ViewModel?.ShareServer(); + ViewModel?.ShareServerAsync(); break; case Key.O: @@ -274,7 +274,7 @@ namespace v2rayN.Views } else if (e.Key == Key.Delete) { - ViewModel?.RemoveServer(); + ViewModel?.RemoveServerAsync(); } else if (e.Key == Key.T) { diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 8235ccaa..fe3fef5d 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -60,7 +60,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -68,7 +68,7 @@ namespace v2rayN.Views this.DialogResult = true; break; } - return true; + return await Task.FromResult(true); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 62845cc5..4e9992b1 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -60,7 +60,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -95,7 +95,7 @@ namespace v2rayN.Views { return false; } - ViewModel?.ImportRulesFromFile(fileName); + ViewModel?.ImportRulesFromFileAsync(fileName); break; case EViewAction.SetClipboardData: @@ -105,11 +105,11 @@ namespace v2rayN.Views case EViewAction.ImportRulesFromClipboard: var clipboardData = WindowsUtils.GetClipboardData(); - ViewModel?.ImportRulesFromClipboard(clipboardData); + ViewModel?.ImportRulesFromClipboardAsync(clipboardData); break; } - return true; + return await Task.FromResult(true); } private void Window_Loaded(object sender, RoutedEventArgs e) @@ -127,7 +127,7 @@ namespace v2rayN.Views } else if (e.Key == Key.C) { - ViewModel?.RuleExportSelected(); + ViewModel?.RuleExportSelectedAsync(); } } else @@ -150,7 +150,7 @@ namespace v2rayN.Views } else if (e.Key == Key.Delete) { - ViewModel?.RuleRemove(); + ViewModel?.RuleRemoveAsync(); } } } @@ -162,7 +162,7 @@ namespace v2rayN.Views private void LstRules_MouseDoubleClick(object sender, MouseButtonEventArgs e) { - ViewModel?.RuleEdit(false); + ViewModel?.RuleEditAsync(false); } private void menuRuleSelectAll_Click(object sender, System.Windows.RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index 2696b930..90f2101f 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -67,7 +67,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -87,7 +87,7 @@ namespace v2rayN.Views if (obj is null) return false; return (new RoutingRuleSettingWindow((RoutingItem)obj)).ShowDialog() ?? false; } - return true; + return await Task.FromResult(true); } private void RoutingSettingWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e) @@ -118,7 +118,7 @@ namespace v2rayN.Views } else if (e.Key == Key.Delete) { - ViewModel?.RoutingAdvancedRemove(); + ViewModel?.RoutingAdvancedRemoveAsync(); } } @@ -134,7 +134,7 @@ namespace v2rayN.Views private void LstRoutings_MouseDoubleClick(object sender, MouseButtonEventArgs e) { - ViewModel?.RoutingAdvancedEdit(false); + ViewModel?.RoutingAdvancedEditAsync(false); } private void linkdomainStrategy_Click(object sender, System.Windows.RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index dff22a38..ae27980b 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -39,7 +39,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -47,7 +47,7 @@ namespace v2rayN.Views this.DialogResult = true; break; } - return true; + return await Task.FromResult(true); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index 278b56fb..f0c385b5 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -33,7 +33,7 @@ namespace v2rayN.Views WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); } - private bool UpdateViewHandler(EViewAction action, object? obj) + private async Task UpdateViewHandler(EViewAction action, object? obj) { switch (action) { @@ -57,7 +57,7 @@ namespace v2rayN.Views ShareSub((string)obj); break; } - return true; + return await Task.FromResult(true); } private async void ShareSub(string url) @@ -86,7 +86,7 @@ namespace v2rayN.Views private void LstSubscription_MouseDoubleClick(object sender, MouseButtonEventArgs e) { - ViewModel?.EditSub(false); + ViewModel?.EditSubAsync(false); } private void LstSubscription_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)