diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index d9a01eb4..6e4d7c1c 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -247,7 +247,10 @@ namespace v2rayN.Desktop.Views case EViewAction.AddServerViaClipboard: var clipboardData = await AvaUtils.GetClipboardData(this); - ViewModel?.AddServerViaClipboardAsync(clipboardData); + if (ViewModel != null) + { + await ViewModel.AddServerViaClipboardAsync(clipboardData); + } break; case EViewAction.AdjustMainLvColWidth: @@ -294,7 +297,10 @@ namespace v2rayN.Desktop.Views break; case WindowCloseReason.ApplicationShutdown or WindowCloseReason.OSShutdown: - await ViewModel?.MyAppExitAsync(true); + if (ViewModel != null) + { + await ViewModel.MyAppExitAsync(true); + } break; } @@ -309,7 +315,10 @@ namespace v2rayN.Desktop.Views { case Key.V: var clipboardData = await AvaUtils.GetClipboardData(this); - ViewModel?.AddServerViaClipboardAsync(clipboardData); + if (ViewModel != null) + { + await ViewModel.AddServerViaClipboardAsync(clipboardData); + } break; case Key.S: @@ -358,7 +367,11 @@ namespace v2rayN.Desktop.Views { return; } - await ViewModel?.ScanImageResult(fileName); + + if (ViewModel != null) + { + await ViewModel.ScanImageResult(fileName); + } } private void MenuCheckUpdate_Click(object? sender, RoutedEventArgs e) @@ -382,8 +395,10 @@ namespace v2rayN.Desktop.Views _blCloseByUser = true; StorageUI(); - - await ViewModel?.MyAppExitAsync(false); + if (ViewModel != null) + { + await ViewModel.MyAppExitAsync(false); + } } #endregion Event diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 62f73472..11574319 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -86,7 +86,7 @@ namespace v2rayN.Desktop.Views this.BindCommand(ViewModel, vm => vm.SpeedServerCmd, v => v.menuSpeedServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SortServerResultCmd, v => v.menuSortServerResult).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RemoveInvalidServerResultCmd, v => v.menuRemoveInvalidServerResult).DisposeWith(disposables); - + //servers export this.BindCommand(ViewModel, vm => vm.Export2ClientConfigCmd, v => v.menuExport2ClientConfig).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables); @@ -102,11 +102,16 @@ namespace v2rayN.Desktop.Views private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e) { e.Handled = true; - await ViewModel?.SortServer(e.Column.Tag.ToString()); + + if (ViewModel != null && e.Column?.Tag?.ToString() != null) + { + await ViewModel.SortServer(e.Column.Tag.ToString()); + } + e.Handled = false; } - //#region Event + #region Event private async Task UpdateViewHandler(EViewAction action, object? obj) { @@ -179,7 +184,9 @@ namespace v2rayN.Desktop.Views case EViewAction.DispatcherRefreshServersBiz: Dispatcher.UIThread.Post(() => - ViewModel?.RefreshServersBiz(), + { + _ = RefreshServersBiz(); + }, DispatcherPriority.Default); break; } @@ -198,6 +205,19 @@ namespace v2rayN.Desktop.Views await DialogHost.Show(dialog); } + public async Task RefreshServersBiz() + { + if (ViewModel != null) + { + await ViewModel.RefreshServersBiz(); + } + + if (lstProfiles.SelectedIndex > 0) + { + lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null); + } + } + private void lstProfiles_SelectionChanged(object? sender, SelectionChangedEventArgs e) { ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast().ToList(); @@ -333,9 +353,9 @@ namespace v2rayN.Desktop.Views } } - //#endregion Event + #endregion Event - //#region UI + #region UI private void RestoreUI() { @@ -388,9 +408,9 @@ namespace v2rayN.Desktop.Views _config.UiItem.MainColumnItem = lvColumnItem; } - //#endregion UI + #endregion UI - //#region Drag and Drop + #region Drag and Drop //private Point startPoint = new(); //private int startIndex = -1; @@ -480,6 +500,6 @@ namespace v2rayN.Desktop.Views // } //} - //#endregion Drag and Drop + #endregion Drag and Drop } } diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index d3a6c112..d217c8ea 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -166,7 +166,7 @@ namespace v2rayN.Views case EViewAction.DispatcherRefreshServersBiz: Application.Current?.Dispatcher.Invoke((() => { - ViewModel?.RefreshServersBiz(); + _ = RefreshServersBiz(); }), DispatcherPriority.Normal); break; } @@ -186,6 +186,19 @@ namespace v2rayN.Views await DialogHost.Show(dialog, "RootDialog"); } + public async Task RefreshServersBiz() + { + if (ViewModel != null) + { + await ViewModel.RefreshServersBiz(); + } + + if (lstProfiles.SelectedIndex > 0) + { + lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null); + } + } + private void lstProfiles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast().ToList();