Add sing-box srs custom url support for fix TUN (#5835)

Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
pull/5840/head
runetfreedom 2024-10-15 08:28:51 +03:00 committed by GitHub
parent e96c9abd69
commit eebb6735aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 70 additions and 3 deletions

View File

@ -119,6 +119,11 @@
@"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat",
};
public static readonly List<string> SingboxRulesetSources = new() {
SingboxRulesetUrl,
@"https://raw.githubusercontent.com/runetfreedom/russia-v2ray-rules-dat/refs/heads/release/sing-box/rule-set-{0}/{1}.srs",
};
public static readonly Dictionary<string, string> UserAgentTexts = new()
{
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },

View File

@ -141,6 +141,7 @@
public string defIEProxyExceptions { get; set; }
public string subConvertUrl { get; set; } = string.Empty;
public string? geoSourceUrl { get; set; }
public string? srsSourceUrl { get; set; }
}
[Serializable]

View File

@ -3012,7 +3012,18 @@ namespace ServiceLib.Resx {
return ResourceManager.GetString("TbSettingsGeoFilesSource", resourceCulture);
}
}
/// <summary>
/// 查找类似 Sing-box srs files source (optional) 的本地化字符串。
/// </summary>
public static string TbSettingsSrsFilesSource
{
get
{
return ResourceManager.GetString("TbSettingsSrsFilesSource", resourceCulture);
}
}
/// <summary>
/// 查找类似 HTTP Port 的本地化字符串。
/// </summary>

View File

@ -1330,6 +1330,8 @@
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
<value>Geo files source (optional)</value>
</data>
<data name="TbSettingsSrsFilesSource" xml:space="preserve">
<value>Sing-box srs files source (optional)</value>
<data name="UpgradeAppNotExistTip" xml:space="preserve">
<value>UpgradeApp does not exist</value>
</data>

View File

@ -1367,12 +1367,16 @@ namespace ServiceLib.Services.CoreConfig
}
else
{
var srsUrl = string.IsNullOrEmpty(_config.constItem.srsSourceUrl)
? Global.SingboxRulesetUrl
: _config.constItem.srsSourceUrl;
customRuleset = new()
{
type = "remote",
format = "binary",
tag = item,
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
url = string.Format(srsUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag
};
}

View File

@ -454,7 +454,7 @@ namespace ServiceLib.Services
var geoUrl = string.IsNullOrEmpty(config?.constItem.geoSourceUrl)
? Global.GeoUrl
: config.constItem.geoSourceUrl;
var url = string.Format(Global.GeoUrl, geoName);
var url = string.Format(geoUrl, geoName);
var fileName = Utils.GetTempPath(Utils.GetGuid());
DownloadService downloadHandle = new();

View File

@ -66,6 +66,7 @@ namespace ServiceLib.ViewModels
[Reactive] public string SubConvertUrl { get; set; }
[Reactive] public int MainGirdOrientation { get; set; }
[Reactive] public string GeoFileSourceUrl { get; set; }
[Reactive] public string SrsFileSourceUrl { get; set; }
#endregion UI
@ -166,6 +167,7 @@ namespace ServiceLib.ViewModels
SubConvertUrl = _config.constItem.subConvertUrl;
MainGirdOrientation = (int)_config.uiItem.mainGirdOrientation;
GeoFileSourceUrl = _config.constItem.geoSourceUrl;
SrsFileSourceUrl = _config.constItem.srsSourceUrl;
#endregion UI
@ -319,6 +321,7 @@ namespace ServiceLib.ViewModels
_config.constItem.subConvertUrl = SubConvertUrl;
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
_config.constItem.geoSourceUrl = GeoFileSourceUrl;
_config.constItem.srsSourceUrl = SrsFileSourceUrl;
//systemProxy
_config.systemProxyItem.systemProxyExceptions = systemProxyExceptions;

View File

@ -365,6 +365,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@ -624,6 +625,19 @@
Grid.Column="1"
Width="300"
Classes="Margin8" />
<TextBlock
Grid.Row="23"
Grid.Column="0"
VerticalAlignment="Center"
Classes="Margin8"
Text="{x:Static resx:ResUI.TbSettingsSrsFilesSource}" />
<ComboBox
x:Name="cmbSrsFilesSourceUrl"
Grid.Row="23"
Grid.Column="1"
Width="300"
Classes="Margin8" />
</Grid>
</ScrollViewer>
</TabItem>

View File

@ -87,6 +87,10 @@ namespace v2rayN.Desktop.Views
{
cmbGetFilesSourceUrl.Items.Add(it);
});
Global.SingboxRulesetSources.ForEach(it =>
{
cmbSrsFilesSourceUrl.Items.Add(it);
});
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{
cmbMainGirdOrientation.Items.Add(it.ToString());
@ -137,6 +141,7 @@ namespace v2rayN.Desktop.Views
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.SelectedValue).DisposeWith(disposables);

View File

@ -529,6 +529,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@ -862,6 +863,22 @@
Margin="{StaticResource Margin8}"
IsEditable="True"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="23"
Grid.Column="0"
Margin="{StaticResource Margin8}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsSrsFilesSource}" />
<ComboBox
x:Name="cmbSrsFilesSourceUrl"
Grid.Row="23"
Grid.Column="1"
Width="300"
Margin="{StaticResource Margin8}"
IsEditable="True"
Style="{StaticResource DefComboBox}" />
</Grid>
</ScrollViewer>
</TabItem>

View File

@ -89,6 +89,10 @@ namespace v2rayN.Views
{
cmbGetFilesSourceUrl.Items.Add(it);
});
Global.SingboxRulesetSources.ForEach(it =>
{
cmbSrsFilesSourceUrl.Items.Add(it);
});
foreach (EGirdOrientation it in Enum.GetValues(typeof(EGirdOrientation)))
{
cmbMainGirdOrientation.Items.Add(it.ToString());
@ -150,6 +154,7 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.notProxyLocalAddress, v => v.tognotProxyLocalAddress.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);