From 1d6da1f391824d5b2c40fab852c6e3ad65f6bf91 Mon Sep 17 00:00:00 2001 From: fqfqgo Date: Sun, 22 Feb 2026 21:02:30 +0800 Subject: [PATCH] feat: add Start browser menu (launch Edge with proxy on Windows) Co-authored-by: Cursor --- v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 11 ++++- v2rayN/ServiceLib/Resx/ResUI.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 3 ++ .../ViewModels/MainWindowViewModel.cs | 43 +++++++++++++++++++ v2rayN/v2rayN.Desktop/Views/MainWindow.axaml | 5 +++ .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 1 + v2rayN/v2rayN/Views/MainWindow.xaml | 17 ++++++++ v2rayN/v2rayN/Views/MainWindow.xaml.cs | 1 + 8 files changed, 83 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 6f223693..c9b4b798 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // 此代码由工具生成。 // 运行时版本:4.0.30319.42000 @@ -1473,6 +1473,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Start browser 的本地化字符串。 + /// + public static string menuStartBrowser { + get { + return ResourceManager.GetString("menuStartBrowser", resourceCulture); + } + } + /// /// 查找类似 Backup to remote (WebDAV) 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 041a103b..1a949baf 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -423,6 +423,9 @@ Reload + + Start browser + Routing Setting diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index c8936668..d4a1c3a0 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -423,6 +423,9 @@ 重启服务 + + 启动浏览器 + 路由设置 diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 8f5e9029..bfbbbafd 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -53,6 +53,8 @@ public class MainWindowViewModel : MyReactiveObject public ReactiveCommand ReloadCmd { get; } + public ReactiveCommand StartBrowserCmd { get; } + [Reactive] public bool BlReloadEnabled { get; set; } @@ -207,6 +209,11 @@ public class MainWindowViewModel : MyReactiveObject await Reload(); }); + StartBrowserCmd = ReactiveCommand.CreateFromTask(async () => + { + await StartBrowser(); + }); + RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () => { await ApplyRegionalPreset(EPresetType.Default); @@ -520,6 +527,42 @@ public class MainWindowViewModel : MyReactiveObject await Task.CompletedTask; } + private async Task StartBrowser() + { + if (!Utils.IsWindows()) + { + NoticeManager.Instance.Enqueue(ResUI.OperationFailed); + await Task.CompletedTask; + return; + } + + try + { + var v2rayNPath = Utils.StartupPath(); + var port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks); + var edgeDataDir = Path.Combine(v2rayNPath, "edge-data"); + + var process = new System.Diagnostics.Process + { + StartInfo = new System.Diagnostics.ProcessStartInfo + { + FileName = "msedge.exe", + Arguments = $"--user-data-dir=\"{edgeDataDir}\" --proxy-server=127.0.0.1:{port} https://www.google.com/", + WorkingDirectory = v2rayNPath, + UseShellExecute = true + } + }; + process.Start(); + } + catch (Exception ex) + { + Logging.SaveLog("StartBrowser", ex); + NoticeManager.Instance.Enqueue(ResUI.OperationFailed); + } + + await Task.CompletedTask; + } + #endregion Setting #region core job diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml index ca59c472..dc353271 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml @@ -97,6 +97,11 @@ + + diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 5c5ba9cb..31c8e960 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -101,6 +101,7 @@ public partial class MainWindow : WindowBase this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.StartBrowserCmd, v => v.menuStartBrowser).DisposeWith(disposables); switch (_config.UiItem.MainGirdOrientation) { diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 1c49ca24..a80ead2d 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -268,6 +268,23 @@ + + + + + + + + + + + vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.StartBrowserCmd, v => v.menuStartBrowser).DisposeWith(disposables); switch (_config.UiItem.MainGirdOrientation) {