Added Copy Terminal proxy command to clipboard in tray menu

https://github.com/2dust/v2rayN/issues/6482
This commit is contained in:
2dust
2025-01-12 11:07:34 +08:00
parent cb94d64395
commit 649e89e7af
12 changed files with 69 additions and 1 deletions
@@ -32,6 +32,7 @@ namespace ServiceLib.ViewModels
public ReactiveCommand<Unit, Unit> AddServerViaScanCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
public ReactiveCommand<Unit, Unit> CopyProxyCmdToClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> NotifyLeftClickCmd { get; }
#region System Proxy
@@ -128,6 +129,11 @@ namespace ServiceLib.ViewModels
y => y == true)
.Subscribe(async c => await DoEnableTun(c));
CopyProxyCmdToClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
await CopyProxyCmdToClipboard();
});
NotifyLeftClickCmd = ReactiveCommand.CreateFromTask(async () =>
{
Locator.Current.GetService<MainWindowViewModel>()?.ShowHideWindow(null);
@@ -198,6 +204,23 @@ namespace ServiceLib.ViewModels
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
}
private async Task CopyProxyCmdToClipboard()
{
var cmd = Utils.IsWindows() ? "set" : "export";
var address = $"{Global.Loopback}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}";
var sb = new StringBuilder();
sb.AppendLine($"{cmd} http_proxy=http://{address}");
sb.AppendLine($"{cmd} https_proxy=http://{address}");
sb.AppendLine($"{cmd} all_proxy=socks5://{address}");
sb.AppendLine("");
sb.AppendLine($"{cmd} HTTP_PROXY=http://{address}");
sb.AppendLine($"{cmd} HTTPS_PROXY=http://{address}");
sb.AppendLine($"{cmd} ALL_PROXY=socks5://{address}");
await _updateView?.Invoke(EViewAction.SetClipboardData, sb.ToString());
}
private async Task AddServerViaClipboard()
{
var service = Locator.Current.GetService<MainWindowViewModel>();