mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 14:26:20 +00:00
easy add group and delete group
This commit is contained in:
parent
355bf84af4
commit
ca8307d1a9
4 changed files with 136 additions and 0 deletions
|
@ -13,6 +13,7 @@ using System.IO;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using v2rayN.Base;
|
using v2rayN.Base;
|
||||||
|
@ -129,6 +130,8 @@ namespace v2rayN.ViewModels
|
||||||
public ReactiveCommand<Unit, Unit> SubSettingCmd { get; }
|
public ReactiveCommand<Unit, Unit> SubSettingCmd { get; }
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> AddSubCmd { get; }
|
public ReactiveCommand<Unit, Unit> AddSubCmd { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> AddGroupCmd { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> DelGroupCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
|
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
|
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> SubGroupUpdateCmd { get; }
|
public ReactiveCommand<Unit, Unit> SubGroupUpdateCmd { get; }
|
||||||
|
@ -434,6 +437,18 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
SubSetting();
|
SubSetting();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddGroupCmd = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
AddGroup();
|
||||||
|
});
|
||||||
|
|
||||||
|
DelGroupCmd = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
DelGroup();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
AddSubCmd = ReactiveCommand.Create(() =>
|
AddSubCmd = ReactiveCommand.Create(() =>
|
||||||
{
|
{
|
||||||
AddSub();
|
AddSub();
|
||||||
|
@ -550,6 +565,8 @@ namespace v2rayN.ViewModels
|
||||||
Global.ShowInTaskbar = true;
|
Global.ShowInTaskbar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
ConfigHandler.InitBuiltinRouting(ref _config);
|
ConfigHandler.InitBuiltinRouting(ref _config);
|
||||||
|
@ -895,6 +912,25 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitSubscriptionViewLast()
|
||||||
|
{
|
||||||
|
_subItems.Clear();
|
||||||
|
|
||||||
|
_subItems.Add(new SubItem { remarks = ResUI.AllGroupServers });
|
||||||
|
foreach (var item in LazyConfig.Instance.SubItems().OrderBy(t => t.sort))
|
||||||
|
{
|
||||||
|
_subItems.Add(item);
|
||||||
|
}
|
||||||
|
if (_subId != null && _subItems.FirstOrDefault(t => t.id == _subId) != null)
|
||||||
|
{
|
||||||
|
SelectedSub = _subItems.FirstOrDefault(t => t.id == _subId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedSub = _subItems[_subItems.Count - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Servers && Groups
|
#endregion Servers && Groups
|
||||||
|
|
||||||
#region Add Servers
|
#region Add Servers
|
||||||
|
@ -1328,6 +1364,69 @@ namespace v2rayN.ViewModels
|
||||||
SubSelectedChanged(true);
|
SubSelectedChanged(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddGroup()
|
||||||
|
{
|
||||||
|
SubItem newItem = new();
|
||||||
|
var lastNum = 1;
|
||||||
|
var preffixStr = "g";
|
||||||
|
foreach (var config in LazyConfig.Instance.SubItems().OrderBy(t => t.sort))
|
||||||
|
{
|
||||||
|
var flag = config.remarks.StartsWith(preffixStr);
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var numStr = config.remarks.Substring( 1 );
|
||||||
|
if (Regex.IsMatch(numStr, @"^\d+$"))
|
||||||
|
{
|
||||||
|
var num = int.Parse(numStr);
|
||||||
|
if (lastNum == num)
|
||||||
|
{
|
||||||
|
lastNum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newItem.remarks = preffixStr + lastNum;
|
||||||
|
var ret = true;
|
||||||
|
|
||||||
|
var item = LazyConfig.Instance.GetSubItem(newItem.id);
|
||||||
|
if (item is null)
|
||||||
|
{
|
||||||
|
item = newItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item.remarks = newItem.remarks;
|
||||||
|
item.url = newItem.url;
|
||||||
|
item.moreUrl = newItem.moreUrl;
|
||||||
|
item.enabled = newItem.enabled;
|
||||||
|
item.autoUpdateInterval = newItem.autoUpdateInterval;
|
||||||
|
item.userAgent = newItem.userAgent;
|
||||||
|
item.sort = newItem.sort;
|
||||||
|
item.filter = newItem.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (ConfigHandler.AddSubItem(ref _config, item) == 0);
|
||||||
|
|
||||||
|
if (ret == true)
|
||||||
|
{
|
||||||
|
InitSubscriptionViewLast();
|
||||||
|
SubSelectedChanged(true);
|
||||||
|
// _noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DelGroup()
|
||||||
|
{
|
||||||
|
// MessageBox.Show("delete");
|
||||||
|
ConfigHandler.DeleteSubItem(ref _config, SelectedSub?.id);
|
||||||
|
InitSubscriptionViewLast();
|
||||||
|
SubSelectedChanged(true);
|
||||||
|
|
||||||
|
// RefreshSubItems();
|
||||||
|
// _noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||||
|
// v.lstGroup.SelectedItem
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateSubscriptionProcess(string subId, bool blProxy)
|
private void UpdateSubscriptionProcess(string subId, bool blProxy)
|
||||||
{
|
{
|
||||||
|
|
|
@ -377,6 +377,24 @@
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
<Button
|
||||||
|
x:Name="btnAddGroup"
|
||||||
|
Width="30"
|
||||||
|
Height="30"
|
||||||
|
Margin="4,0"
|
||||||
|
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||||
|
<materialDesign:PackIcon VerticalAlignment="Center" Kind="FolderPlusOutline" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
x:Name="btnDeleteGroup"
|
||||||
|
Width="30"
|
||||||
|
Height="30"
|
||||||
|
Margin="4,0"
|
||||||
|
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||||
|
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Delete" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
x:Name="btnAddSub"
|
x:Name="btnAddSub"
|
||||||
Width="30"
|
Width="30"
|
||||||
|
|
|
@ -63,9 +63,14 @@ namespace v2rayN.Views
|
||||||
|
|
||||||
this.OneWayBind(ViewModel, vm => vm.SubItems, v => v.lstGroup.ItemsSource).DisposeWith(disposables);
|
this.OneWayBind(ViewModel, vm => vm.SubItems, v => v.lstGroup.ItemsSource).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedSub, v => v.lstGroup.SelectedItem).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SelectedSub, v => v.lstGroup.SelectedItem).DisposeWith(disposables);
|
||||||
|
|
||||||
this.Bind(ViewModel, vm => vm.ServerFilter, v => v.txtServerFilter.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.ServerFilter, v => v.txtServerFilter.Text).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.AddSubCmd, v => v.btnAddSub).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.AddSubCmd, v => v.btnAddSub).DisposeWith(disposables);
|
||||||
|
|
||||||
|
this.BindCommand(ViewModel, vm => vm.AddGroupCmd, v => v.btnAddGroup).DisposeWith(disposables);
|
||||||
|
|
||||||
|
this.BindCommand(ViewModel, vm => vm.DelGroupCmd, v => v.btnDeleteGroup).DisposeWith(disposables);
|
||||||
|
|
||||||
//servers
|
//servers
|
||||||
this.BindCommand(ViewModel, vm => vm.AddVmessServerCmd, v => v.menuAddVmessServer).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.AddVmessServerCmd, v => v.menuAddVmessServer).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.AddVlessServerCmd, v => v.menuAddVlessServer).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.AddVlessServerCmd, v => v.menuAddVlessServer).DisposeWith(disposables);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Input;
|
||||||
using v2rayN.Mode;
|
using v2rayN.Mode;
|
||||||
using v2rayN.ViewModels;
|
using v2rayN.ViewModels;
|
||||||
|
|
||||||
|
@ -40,5 +41,18 @@ namespace v2rayN.Views
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void Send(Key key)
|
||||||
|
{
|
||||||
|
if (Keyboard.PrimaryDevice != null)
|
||||||
|
{
|
||||||
|
if (Keyboard.PrimaryDevice.ActiveSource != null)
|
||||||
|
{
|
||||||
|
var e1 = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Down) { RoutedEvent = Keyboard.KeyDownEvent };
|
||||||
|
InputManager.Current.ProcessInput(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue