mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-03 03:52:07 +03:00
Add custom outbound support (#9817)
* Add custom outbound support * Add test * Add inner fmt support * Full config to outbounds * Rename to `Outbound` * AI optimized * Fix * Add bind interface placeholder --------- Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,9 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable
|
||||
[Reactive]
|
||||
public partial string? CoreType { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public partial bool IsSingboxEndpoint { get; set; }
|
||||
|
||||
public ReactiveCommand<RxVoid, RxVoid> BrowseServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> EditServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> SaveServerCmd { get; }
|
||||
@@ -40,7 +43,10 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable
|
||||
});
|
||||
|
||||
SelectedSource = profileItem.IndexId.IsNullOrEmpty() ? profileItem : JsonUtils.DeepCopy(profileItem);
|
||||
CoreType = SelectedSource?.CoreType?.ToString();
|
||||
var coreStr = SelectedSource?.CoreType?.ToString();
|
||||
coreStr = coreStr.IsNullOrEmpty() ? Global.CoreTypes.FirstOrDefault() : coreStr;
|
||||
CoreType = coreStr;
|
||||
IsSingboxEndpoint = SelectedSource?.GetProtocolExtra()?.IsSingboxEndpoint ?? false;
|
||||
}
|
||||
|
||||
private async Task SaveServerAsync()
|
||||
@@ -58,6 +64,10 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable
|
||||
return;
|
||||
}
|
||||
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : Enum.Parse<ECoreType>(CoreType);
|
||||
SelectedSource.SetProtocolExtra(SelectedSource?.GetProtocolExtra() with
|
||||
{
|
||||
IsSingboxEndpoint = IsSingboxEndpoint ? true : null,
|
||||
});
|
||||
|
||||
if (await ConfigHandler.EditCustomServer(_config, SelectedSource) == 0)
|
||||
{
|
||||
@@ -80,7 +90,8 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable
|
||||
var item = await AppManager.Instance.GetProfileItem(SelectedSource.IndexId);
|
||||
item ??= SelectedSource;
|
||||
item.Address = fileName;
|
||||
if (await ConfigHandler.AddCustomServer(_config, item, false) == 0)
|
||||
var result = item.ConfigType == EConfigType.Outbound ? await ConfigHandler.AddCustomOutboundServer(_config, item, false) : await ConfigHandler.AddCustomServer(_config, item, false);
|
||||
if (result == 0)
|
||||
{
|
||||
NoticeManager.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
|
||||
if (item.IndexId.IsNotEmpty())
|
||||
|
||||
@@ -33,6 +33,7 @@ public partial class MainWindowViewModel : MyReactiveObject
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddAnytlsServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddNaiveServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddCustomServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddCustomOutboundServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddPolicyGroupServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddProxyChainServerCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> AddServerViaClipboardCmd { get; }
|
||||
@@ -145,6 +146,10 @@ public partial class MainWindowViewModel : MyReactiveObject
|
||||
{
|
||||
await AddServerAsync(EConfigType.Custom);
|
||||
});
|
||||
AddCustomOutboundServerCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await AddServerAsync(EConfigType.Outbound);
|
||||
});
|
||||
AddPolicyGroupServerCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await AddServerAsync(EConfigType.PolicyGroup);
|
||||
@@ -432,7 +437,7 @@ public partial class MainWindowViewModel : MyReactiveObject
|
||||
};
|
||||
|
||||
bool? ret = false;
|
||||
if (eConfigType == EConfigType.Custom)
|
||||
if (eConfigType is EConfigType.Custom or EConfigType.Outbound)
|
||||
{
|
||||
var addServer2ViewModel = new AddServer2ViewModel(item);
|
||||
ret = await AppManager.Instance.WindowDialog.ShowDialogAsync(addServer2ViewModel);
|
||||
|
||||
@@ -503,7 +503,7 @@ public partial class ProfilesViewModel : MyReactiveObject
|
||||
var eConfigType = item.ConfigType;
|
||||
|
||||
bool? ret = false;
|
||||
if (eConfigType == EConfigType.Custom)
|
||||
if (eConfigType is EConfigType.Custom or EConfigType.Outbound)
|
||||
{
|
||||
var addServer2ViewModel = new AddServer2ViewModel(item);
|
||||
ret = await AppManager.Instance.WindowDialog.ShowDialogAsync(addServer2ViewModel);
|
||||
|
||||
@@ -7,6 +7,9 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable
|
||||
[Reactive]
|
||||
public partial SubItem SelectedSource { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public partial string CustomCoreType { get; set; }
|
||||
|
||||
public ReactiveCommand<RxVoid, RxVoid> SelectPrevProfileCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> SelectNextProfileCmd { get; }
|
||||
public ReactiveCommand<RxVoid, RxVoid> SaveCmd { get; }
|
||||
@@ -39,6 +42,7 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable
|
||||
});
|
||||
|
||||
SelectedSource = subItem.Id.IsNullOrEmpty() ? subItem : JsonUtils.DeepCopy(subItem);
|
||||
CustomCoreType = SelectedSource.CustomCoreType?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
private async Task SaveSubAsync()
|
||||
@@ -67,6 +71,8 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable
|
||||
}
|
||||
}
|
||||
|
||||
SelectedSource.CustomCoreType = Enum.TryParse<ECoreType>(CustomCoreType, out var coreType) ? coreType : null;
|
||||
|
||||
if (await ConfigHandler.AddSubItem(_config, SelectedSource) == 0)
|
||||
{
|
||||
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
|
||||
Reference in New Issue
Block a user