feat: add Start browser menu (launch Edge with proxy on Windows)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
fqfqgo 2026-02-22 21:02:30 +08:00
parent b5800f7dfc
commit 1d6da1f391
8 changed files with 83 additions and 1 deletions

View file

@ -1,4 +1,4 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// 此代码由工具生成。 // 此代码由工具生成。
// 运行时版本:4.0.30319.42000 // 运行时版本:4.0.30319.42000
@ -1473,6 +1473,15 @@ namespace ServiceLib.Resx {
} }
} }
/// <summary>
/// 查找类似 Start browser 的本地化字符串。
/// </summary>
public static string menuStartBrowser {
get {
return ResourceManager.GetString("menuStartBrowser", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Backup to remote (WebDAV) 的本地化字符串。 /// 查找类似 Backup to remote (WebDAV) 的本地化字符串。
/// </summary> /// </summary>

View file

@ -423,6 +423,9 @@
<data name="menuReload" xml:space="preserve"> <data name="menuReload" xml:space="preserve">
<value>Reload</value> <value>Reload</value>
</data> </data>
<data name="menuStartBrowser" xml:space="preserve">
<value>Start browser</value>
</data>
<data name="menuRoutingSetting" xml:space="preserve"> <data name="menuRoutingSetting" xml:space="preserve">
<value>Routing Setting</value> <value>Routing Setting</value>
</data> </data>

View file

@ -423,6 +423,9 @@
<data name="menuReload" xml:space="preserve"> <data name="menuReload" xml:space="preserve">
<value>重启服务</value> <value>重启服务</value>
</data> </data>
<data name="menuStartBrowser" xml:space="preserve">
<value>启动浏览器</value>
</data>
<data name="menuRoutingSetting" xml:space="preserve"> <data name="menuRoutingSetting" xml:space="preserve">
<value>路由设置</value> <value>路由设置</value>
</data> </data>

View file

@ -53,6 +53,8 @@ public class MainWindowViewModel : MyReactiveObject
public ReactiveCommand<Unit, Unit> ReloadCmd { get; } public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
public ReactiveCommand<Unit, Unit> StartBrowserCmd { get; }
[Reactive] [Reactive]
public bool BlReloadEnabled { get; set; } public bool BlReloadEnabled { get; set; }
@ -207,6 +209,11 @@ public class MainWindowViewModel : MyReactiveObject
await Reload(); await Reload();
}); });
StartBrowserCmd = ReactiveCommand.CreateFromTask(async () =>
{
await StartBrowser();
});
RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () => RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
{ {
await ApplyRegionalPreset(EPresetType.Default); await ApplyRegionalPreset(EPresetType.Default);
@ -520,6 +527,42 @@ public class MainWindowViewModel : MyReactiveObject
await Task.CompletedTask; 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 #endregion Setting
#region core job #region core job

View file

@ -97,6 +97,11 @@
<MenuItem x:Name="menuReload" Header="{x:Static resx:ResUI.menuReload}" /> <MenuItem x:Name="menuReload" Header="{x:Static resx:ResUI.menuReload}" />
<MenuItem
x:Name="menuStartBrowser"
Header="{x:Static resx:ResUI.menuStartBrowser}"
IsVisible="{Binding BlIsWindows}" />
<MenuItem x:Name="menuPromotion" Header="{x:Static resx:ResUI.menuPromotion}" /> <MenuItem x:Name="menuPromotion" Header="{x:Static resx:ResUI.menuPromotion}" />
<MenuItem x:Name="menuClose" Header="{x:Static resx:ResUI.menuExit}" /> <MenuItem x:Name="menuClose" Header="{x:Static resx:ResUI.menuExit}" />

View file

@ -101,6 +101,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).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) switch (_config.UiItem.MainGirdOrientation)
{ {

View file

@ -268,6 +268,23 @@
</MenuItem> </MenuItem>
</Menu> </Menu>
<Separator /> <Separator />
<Menu Margin="0,1" Style="{StaticResource ToolbarMenu}">
<MenuItem
x:Name="menuStartBrowser"
Padding="{StaticResource MarginLeftRight8}"
AutomationProperties.Name="{x:Static resx:ResUI.menuStartBrowser}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon
Margin="{StaticResource MarginRight8}"
VerticalAlignment="Center"
Kind="OpenInBrowser" />
<TextBlock Text="{x:Static resx:ResUI.menuStartBrowser}" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</Menu>
<Separator />
<Menu Margin="0,1" Style="{StaticResource ToolbarMenu}"> <Menu Margin="0,1" Style="{StaticResource ToolbarMenu}">
<MenuItem <MenuItem
x:Name="menuPromotion" x:Name="menuPromotion"

View file

@ -100,6 +100,7 @@ public partial class MainWindow
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).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) switch (_config.UiItem.MainGirdOrientation)
{ {