This commit is contained in:
2dust
2022-11-02 15:09:27 +08:00
parent 2d251d9844
commit f3e61be2f7
6 changed files with 30 additions and 22 deletions

View File

@@ -34,13 +34,19 @@ public class HttpHandler
{
try
{
if (!_tcpListener.Pending())
{
Thread.Sleep(10);
continue;
}
var client = _tcpListener.AcceptTcpClient();
Task.Factory.StartNew(() =>
{
var stream = client.GetStream();
var sb = new StringBuilder();
sb.AppendLine("HTTP/1.0 200 OK");
sb.AppendLine("Content-type:text/plain;charset=UTF-8");
sb.AppendLine("Content-type:application/x-ns-proxy-autoconfig");
sb.AppendLine("Connection:close");
sb.AppendLine("Content-Length:" + Encoding.UTF8.GetByteCount(_pacText));
sb.AppendLine();

View File

@@ -39,6 +39,8 @@ namespace clashN.Handler
return Properties.Resources.NotifyIcon2;
case 2:
return Properties.Resources.NotifyIcon3;
case 3:
return Properties.Resources.NotifyIcon2;
}
return Properties.Resources.NotifyIcon1;

View File

@@ -37,7 +37,7 @@ namespace clashN.Handler
{
var type = config.sysProxyType;
if (forceDisable && type == ESysProxyType.ForcedChange)
if (forceDisable && (type == ESysProxyType.ForcedChange || type == ESysProxyType.Pac))
{
type = ESysProxyType.ForcedClear;
}
@@ -78,7 +78,7 @@ namespace clashN.Handler
else if (type == ESysProxyType.Pac)
{
HttpHandler.Start(config);
var strProxy = $"http://127.0.0.1:{config.PacPort}/";
var strProxy = $"{Global.httpProtocol}{Global.Loopback}:{config.PacPort}/pac?t={DateTime.Now.Ticks}";
SetIEProxy(false, strProxy, "");
}

View File

@@ -54,10 +54,10 @@ namespace clashN.ViewModels
public int autoDelayTestInterval { get; set; }
[Reactive]
public string SubConvertUrl { get; set; }
[Reactive]
public int PacPort { get; set; }
public ReactiveCommand<Unit, Unit> SetLoopbackCmd { get; }
public ReactiveCommand<Unit, Unit> SetGlobalHotkeyCmd { get; }
[Reactive]
public int PacListenPort { get; set; }
#endregion
#region System proxy
@@ -109,7 +109,7 @@ namespace clashN.ViewModels
autoUpdateSubInterval = _config.autoUpdateSubInterval;
autoDelayTestInterval = _config.autoDelayTestInterval;
SubConvertUrl = _config.constItem.subConvertUrl;
PacListenPort = _config.PacPort;
PacPort = _config.PacPort;
SetLoopbackCmd = ReactiveCommand.Create(() =>
{
Utils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe"));
@@ -205,7 +205,7 @@ namespace clashN.ViewModels
_config.autoUpdateSubInterval = autoUpdateSubInterval;
_config.autoDelayTestInterval = autoDelayTestInterval;
_config.constItem.subConvertUrl = SubConvertUrl;
_config.PacPort = PacListenPort;
_config.PacPort = PacPort;
//System proxy
_config.systemProxyExceptions = systemProxyExceptions;

View File

@@ -303,20 +303,7 @@
Grid.Row="7"
Grid.Column="1"
Width="300"
Margin="8" />
<TextBlock
Grid.Row="8"
Grid.Column="0"
Margin="8"
VerticalAlignment="Center"
Style="{StaticResource ListItemTitle}"
Text="{x:Static resx:ResUI.TbSettingsPacListenPort}" />
<TextBox
x:Name="txtPacPort"
Grid.Row="8"
Grid.Column="1"
Width="300"
Margin="8" />
Margin="8" />
<TextBlock
Grid.Row="9"
Grid.Column="0"
@@ -360,6 +347,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@@ -402,6 +390,17 @@
Grid.Row="4"
Margin="8"
materialDesign:HintAssist.Hint="Protocol" />
<TextBlock
Grid.Row="5"
Margin="8"
VerticalAlignment="Center"
Style="{StaticResource ListItemTitle}"
Text="{x:Static resx:ResUI.TbSettingsPacListenPort}" />
<TextBox
x:Name="txtPacPort"
Grid.Row="5"
Width="200"
Margin="8" />
</Grid>
</TabItem>

View File

@@ -52,13 +52,14 @@ namespace clashN.Views
this.Bind(ViewModel, vm => vm.EnableSecurityProtocolTls13, v => v.togEnableSecurityProtocolTls13.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.autoUpdateSubInterval, v => v.txtautoUpdateSubInterval.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.autoDelayTestInterval, v => v.txtautoDelayTestInterval.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SetLoopbackCmd, v => v.btnSetLoopback).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SetGlobalHotkeyCmd, v => v.btnSetGlobalHotkey).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyExceptions, v => v.txtsystemProxyExceptions.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.PacPort, v => v.txtPacPort.Text).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveCommand, v => v.btnSave).DisposeWith(disposables);