From fe54a73d74bd1f6f6e48c742c81b9fd735050e91 Mon Sep 17 00:00:00 2001 From: DHR60 <192860629+DHR60@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:43:06 +0000 Subject: [PATCH] Fix ipinfo copy functionality (#10515) * Fix ipinfo copy functionality * Code clean * Code clean --- .../ServiceLib/Handler/AutoStartupHandler.cs | 2 - v2rayN/ServiceLib/Handler/ConfigHandler.cs | 2 - .../CoreConfig/CoreConfigClashService.cs | 1 - .../v2rayN.Desktop/Views/JsonEditor.axaml.cs | 1 - .../v2rayN.Desktop/Views/ProfilesView.axaml | 13 +- .../Views/ProfilesView.axaml.cs | 164 ++---------------- 6 files changed, 27 insertions(+), 156 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index c1259456..df0c2098 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -1,5 +1,3 @@ -using System.Security.Principal; - namespace ServiceLib.Handler; public static class AutoStartupHandler diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index feecb35e..b0ac5879 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1,5 +1,3 @@ -using System.Data; - namespace ServiceLib.Handler; public static class ConfigHandler diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs index 96013109..c0adc6a4 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs @@ -1,4 +1,3 @@ -using YamlDotNet.Core; using YamlDotNet.RepresentationModel; namespace ServiceLib.Services.CoreConfig; diff --git a/v2rayN/v2rayN.Desktop/Views/JsonEditor.axaml.cs b/v2rayN/v2rayN.Desktop/Views/JsonEditor.axaml.cs index c0d8aef6..64e1802e 100644 --- a/v2rayN/v2rayN.Desktop/Views/JsonEditor.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/JsonEditor.axaml.cs @@ -1,4 +1,3 @@ -using System.Text.Json; using System.Xml; using AvaloniaEdit.Highlighting; using AvaloniaEdit.Highlighting.Xshd; diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml index 2d142e41..ef971f9a 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml @@ -353,10 +353,19 @@ Tag="IpInfo"> - + Text="{Binding Path=IpInfo, Mode=OneWay}"> + + + + + + diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 2f7e8318..089131b9 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -23,16 +23,6 @@ public partial class ProfilesView : ReactiveUserControl lstProfiles.SelectionChanged += lstProfiles_SelectionChanged; lstProfiles.DoubleTapped += LstProfiles_DoubleTapped; lstProfiles.Sorting += LstProfiles_Sorting; - //if (_config.UiItem.EnableDragDropSort) - //{ - // lstProfiles.SetValue(DragDrop.AllowDropProperty, true); - - // lstProfiles.AddHandler(PointerPressedEvent, LstProfiles_PointerPressed, RoutingStrategies.Bubble, true); - // lstProfiles.AddHandler(PointerMovedEvent, LstProfiles_PointerMoved, RoutingStrategies.Bubble, true); - // lstProfiles.AddHandler(PointerReleasedEvent, LstProfiles_PointerReleased, RoutingStrategies.Bubble, true); - // lstProfiles.AddHandler(DragDrop.DragOverEvent, LstProfiles_DragOver, RoutingStrategies.Bubble); - // lstProfiles.AddHandler(DragDrop.DropEvent, LstProfiles_Drop, RoutingStrategies.Bubble); - //} this.WhenActivated(disposables => { @@ -214,7 +204,7 @@ public partial class ProfilesView : ReactiveUserControl } } - private void LstProfiles_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e) + private void LstProfiles_DoubleTapped(object? sender, TappedEventArgs e) { var source = e.Source as Border; if (source?.Name == "HeaderBackground") @@ -418,6 +408,21 @@ public partial class ProfilesView : ReactiveUserControl } } + private async void CopyIpInfo_Click(object? sender, RoutedEventArgs e) + { + try + { + if (sender is MenuItem { CommandParameter: string text } && !text.IsNullOrEmpty()) + { + await AvaUtils.SetClipboardData(this, text); + } + } + catch + { + // Ignore + } + } + private void StorageUI() { try @@ -446,143 +451,6 @@ public partial class ProfilesView : ReactiveUserControl #endregion UI - //#region Drag and Drop - - //private static readonly DataFormat LstProfilesRowFormat = - // DataFormat.CreateInProcessFormat("LstProfilesRow"); - - //private (Point, PointerPressedEventArgs)? _dragStartPoint; - - //private void LstProfiles_PointerPressed(object? sender, PointerPressedEventArgs e) - //{ - // var properties = e.GetCurrentPoint(this).Properties; - // if (properties.IsLeftButtonPressed) - // { - // _dragStartPoint = (e.GetPosition(this), e); - // } - //} - - //private async void LstProfiles_PointerMoved(object? sender, PointerEventArgs e) - //{ - // try - // { - // if (_dragStartPoint == null) - // { - // return; - // } - - // var properties = e.GetCurrentPoint(this).Properties; - // if (!properties.IsLeftButtonPressed) - // { - // _dragStartPoint = null; - // return; - // } - - // var currentPoint = e.GetPosition(this); - // var startPoint = _dragStartPoint.Value.Item1; - // var delta = startPoint - currentPoint; - - // var threshold = new Vector(4, 4); - - // if (!(Math.Abs(delta.X) >= threshold.X) && !(Math.Abs(delta.Y) >= threshold.Y)) - // { - // return; - // } - // var dragStartEventArgs = _dragStartPoint.Value.Item2; - // _dragStartPoint = null; - - // if (e.Source is not Visual visualSource) - // { - // return; - // } - // var row = visualSource.FindAncestorOfType(true); - // if (row?.DataContext == null) - // { - // return; - // } - - // e.Handled = true; - - // var dragData = new DataTransfer(); - // var item = DataTransferItem.Create(LstProfilesRowFormat, row.DataContext as ProfileItemModel); - - // dragData.Add(item); - - // await DragDrop.DoDragDropAsync(dragStartEventArgs, dragData, DragDropEffects.Move); - // } - // catch - // { - // // Ignore - // } - //} - - //private void LstProfiles_PointerReleased(object? sender, PointerReleasedEventArgs e) - //{ - // _dragStartPoint = null; - //} - - //private void LstProfiles_DragOver(object? sender, DragEventArgs e) - //{ - // if (!e.DataTransfer.Contains(LstProfilesRowFormat)) - // { - // e.DragEffects = DragDropEffects.None; - // return; - // } - // e.DragEffects = DragDropEffects.Move; - //} - - //private void LstProfiles_Drop(object? sender, DragEventArgs e) - //{ - // if (!e.DataTransfer.Contains(LstProfilesRowFormat)) - // { - // return; - // } - // ProfileItemModel? sourceItem = null; - // foreach (var item in e.DataTransfer.Items) - // { - // if (!item.Formats.Contains(LstProfilesRowFormat)) - // { - // continue; - // } - // if (item.TryGetRaw(LstProfilesRowFormat) is not ProfileItemModel model) - // { - // continue; - // } - // sourceItem = model; - // break; - // } - // if (sourceItem == null) - // { - // return; - // } - // if (e.Source is not Visual visualTarget) - // { - // return; - // } - - // var targetRow = visualTarget.FindAncestorOfType(true); - // if (targetRow is not { DataContext: ProfileItemModel targetItem }) - // { - // return; - // } - // if (ReferenceEquals(sourceItem, targetItem)) - // { - // return; - // } - // if (lstProfiles.ItemsSource is not IList items) - // { - // return; - // } - // var oldIndex = items.IndexOf(sourceItem); - // var newIndex = items.IndexOf(targetItem); - // if (oldIndex >= 0 && newIndex >= 0) - // { - // ViewModel?.MoveServerTo(oldIndex, targetItem); - // } - //} - - //#endregion Drag and Drop - private sealed class ProfileRowDropHandler(ProfilesViewModel viewModel) : IDataGridRowDropHandler { private readonly DataGridRowReorderHandler _reorderHandler = new();