mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 06:46:19 +00:00
Regional presets support
This commit is contained in:
parent
55d2625447
commit
2af532f843
10 changed files with 117 additions and 25 deletions
8
v2rayN/ServiceLib/Enums/EPresetType.cs
Normal file
8
v2rayN/ServiceLib/Enums/EPresetType.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace ServiceLib.Enums
|
||||
{
|
||||
public enum EPresetType
|
||||
{
|
||||
Default = 0,
|
||||
Russia = 1,
|
||||
}
|
||||
}
|
|
@ -1788,5 +1788,31 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
|
||||
#endregion DNS
|
||||
|
||||
#region Presets
|
||||
|
||||
public static bool ApplyPreset(Config config, EPresetType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EPresetType.Default:
|
||||
config.constItem.geoSourceUrl = "";
|
||||
config.constItem.srsSourceUrl = "";
|
||||
config.constItem.routeRulesTemplateSourceUrl = "";
|
||||
|
||||
return true;
|
||||
|
||||
case EPresetType.Russia:
|
||||
config.constItem.geoSourceUrl = Global.GeoFilesSources[1];
|
||||
config.constItem.srsSourceUrl = Global.SingboxRulesetSources[1];
|
||||
config.constItem.routeRulesTemplateSourceUrl = Global.RoutingRulesSources[1];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
27
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
27
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
@ -1113,6 +1113,33 @@ namespace ServiceLib.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Regional presets 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string menuPresets {
|
||||
get {
|
||||
return ResourceManager.GetString("menuPresets", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Default 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string menuPresetsDefault {
|
||||
get {
|
||||
return ResourceManager.GetString("menuPresetsDefault", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Russia 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string menuPresetsRussia {
|
||||
get {
|
||||
return ResourceManager.GetString("menuPresetsRussia", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Auto column width adjustment 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1339,4 +1339,13 @@
|
|||
<data name="TbSettingsRoutingRulesSource" xml:space="preserve">
|
||||
<value>Routing rules source (optional)</value>
|
||||
</data>
|
||||
<data name="menuPresets" xml:space="preserve">
|
||||
<value>Regional presets</value>
|
||||
</data>
|
||||
<data name="menuPresetsDefault" xml:space="preserve">
|
||||
<value>Default</value>
|
||||
</data>
|
||||
<data name="menuPresetsRussia" xml:space="preserve">
|
||||
<value>Russia</value>
|
||||
</data>
|
||||
</root>
|
|
@ -253,23 +253,6 @@ namespace ServiceLib.Services
|
|||
});
|
||||
}
|
||||
|
||||
public async Task<bool> VerifyGeoFilesRepo(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
var repoPath = Utils.GetBinPath("geo.repo");
|
||||
var repo = File.Exists(repoPath) ? File.ReadAllText(repoPath) : "";
|
||||
|
||||
if (repo != (config.constItem.geoSourceUrl ?? ""))
|
||||
{
|
||||
await UpdateGeoFileAll(config, updateFunc);
|
||||
|
||||
File.WriteAllText(repoPath, repo);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task UpdateGeoFileAll(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
await UpdateGeoFile("geosite", config, updateFunc);
|
||||
|
|
|
@ -44,6 +44,10 @@ namespace ServiceLib.ViewModels
|
|||
public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> OpenTheFileLocationCmd { get; }
|
||||
|
||||
//Presets
|
||||
public ReactiveCommand<Unit, Unit> PresetDefaultCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> PresetRussiaCmd { get; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
|
||||
|
||||
[Reactive]
|
||||
|
@ -181,6 +185,16 @@ namespace ServiceLib.ViewModels
|
|||
await Reload();
|
||||
});
|
||||
|
||||
PresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await ApplyPreset(EPresetType.Default);
|
||||
});
|
||||
|
||||
PresetRussiaCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await ApplyPreset(EPresetType.Russia);
|
||||
});
|
||||
|
||||
#endregion WhenAnyValue && ReactiveCommand
|
||||
|
||||
AutoHideStartup();
|
||||
|
@ -191,7 +205,6 @@ namespace ServiceLib.ViewModels
|
|||
ConfigHandler.InitRouting(_config);
|
||||
ConfigHandler.InitBuiltinDNS(_config);
|
||||
CoreHandler.Instance.Init(_config, UpdateHandler);
|
||||
Task.Run(() => VerifyGeoFiles(true));
|
||||
TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler);
|
||||
|
||||
if (_config.guiItem.enableStatistics)
|
||||
|
@ -422,7 +435,6 @@ namespace ServiceLib.ViewModels
|
|||
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
|
||||
if (ret == true)
|
||||
{
|
||||
await VerifyGeoFiles();
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
|
||||
Reload();
|
||||
}
|
||||
|
@ -543,14 +555,23 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public async Task VerifyGeoFiles(bool needReload = false)
|
||||
{
|
||||
var result = await new UpdateService().VerifyGeoFilesRepo(_config, UpdateHandler);
|
||||
#endregion core job
|
||||
|
||||
if (needReload && !result)
|
||||
Reload();
|
||||
#region Presets
|
||||
|
||||
public async Task ApplyPreset(EPresetType type)
|
||||
{
|
||||
ConfigHandler.ApplyPreset(_config, type);
|
||||
|
||||
await new UpdateService().UpdateGeoFileAll(_config, UpdateHandler);
|
||||
|
||||
ConfigHandler.InitRouting(_config);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
|
||||
ConfigHandler.SaveConfig(_config, false);
|
||||
Reload();
|
||||
}
|
||||
|
||||
#endregion core job
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -74,6 +74,10 @@
|
|||
<MenuItem x:Name="menuRoutingSetting" Header="{x:Static resx:ResUI.menuRoutingSetting}" />
|
||||
<MenuItem x:Name="menuDNSSetting" Header="{x:Static resx:ResUI.menuDNSSetting}" />
|
||||
<MenuItem x:Name="menuGlobalHotkeySetting" Header="{x:Static resx:ResUI.menuGlobalHotkeySetting}" />
|
||||
<MenuItem Header="{x:Static resx:ResUI.menuPresets}">
|
||||
<MenuItem x:Name="menuPresetsDefault" Header="{x:Static resx:ResUI.menuPresetsDefault}" />
|
||||
<MenuItem x:Name="menuPresetsRussia" Header="{x:Static resx:ResUI.menuPresetsRussia}" />
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem x:Name="menuRebootAsAdmin" Header="{x:Static resx:ResUI.menuRebootAsAdmin}" />
|
||||
<MenuItem x:Name="menuSettingsSetUWP" Header="{x:Static resx:ResUI.TbSettingsSetUWP}" />
|
||||
|
|
|
@ -76,6 +76,8 @@ namespace v2rayN.Desktop.Views
|
|||
this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.PresetDefaultCmd, v => v.menuPresetsDefault).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.PresetRussiaCmd, v => v.menuPresetsRussia).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);
|
||||
|
|
|
@ -171,6 +171,16 @@
|
|||
x:Name="menuGlobalHotkeySetting"
|
||||
Height="{StaticResource MenuItemHeight}"
|
||||
Header="{x:Static resx:ResUI.menuGlobalHotkeySetting}" />
|
||||
<MenuItem Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuPresets}">
|
||||
<MenuItem
|
||||
x:Name="menuPresetsDefault"
|
||||
Height="{StaticResource MenuItemHeight}"
|
||||
Header="{x:Static resx:ResUI.menuPresetsDefault}" />
|
||||
<MenuItem
|
||||
x:Name="menuPresetsRussia"
|
||||
Height="{StaticResource MenuItemHeight}"
|
||||
Header="{x:Static resx:ResUI.menuPresetsRussia}" />
|
||||
</MenuItem>
|
||||
<Separator Margin="-40,5" />
|
||||
<MenuItem
|
||||
x:Name="menuRebootAsAdmin"
|
||||
|
|
|
@ -98,6 +98,8 @@ namespace v2rayN.Views
|
|||
this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.PresetDefaultCmd, v => v.menuPresetsDefault).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.PresetRussiaCmd, v => v.menuPresetsRussia).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);
|
||||
|
|
Loading…
Reference in a new issue