Can set the update interval for each subscription

This commit is contained in:
2dust 2023-04-10 16:00:32 +08:00
parent 6114e4ff55
commit fce6c46250
15 changed files with 94 additions and 81 deletions

View file

@ -941,7 +941,11 @@ namespace v2rayN.Handler
//Check for duplicate indexId //Check for duplicate indexId
List<string>? lstDbIndexId = null; List<string>? lstDbIndexId = null;
List<ProfileItem> lstAdd = new(); List<ProfileItem> lstAdd = new();
string[] arrData = clipboardData.Split(Environment.NewLine.ToCharArray()); var arrData = clipboardData.Split(Environment.NewLine.ToCharArray()).Where(t => !t.IsNullOrEmpty());
if (isSub)
{
arrData = arrData.Distinct();
}
foreach (string str in arrData) foreach (string str in arrData)
{ {
//maybe sub //maybe sub

View file

@ -11,14 +11,6 @@ namespace v2rayN.Handler
public sealed class MainFormHandler public sealed class MainFormHandler
{ {
private static readonly Lazy<MainFormHandler> instance = new(() => new()); private static readonly Lazy<MainFormHandler> instance = new(() => new());
//Action<bool, string> _updateUI;
//private DownloadHandle downloadHandle2;
//private Config _config;
//private V2rayHandler _v2rayHandler;
//private List<int> _selecteds;
//private Thread _workThread;
//Action<int, string> _updateFunc;
public static MainFormHandler Instance => instance.Value; public static MainFormHandler Instance => instance.Value;
public Icon GetNotifyIcon(Config config) public Icon GetNotifyIcon(Config config)
@ -285,37 +277,52 @@ namespace v2rayN.Handler
public void UpdateTask(Config config, Action<bool, string> update) public void UpdateTask(Config config, Action<bool, string> update)
{ {
Task.Run(() => UpdateTaskRun(config, update)); Task.Run(() => UpdateTaskRunSubscription(config, update));
Task.Run(() => UpdateTaskRunGeo(config, update));
} }
private void UpdateTaskRun(Config config, Action<bool, string> update) private void UpdateTaskRunSubscription(Config config, Action<bool, string> update)
{
Thread.Sleep(60000);
Utils.SaveLog("UpdateTaskRunSubscription");
var updateHandle = new UpdateHandle();
while (true)
{
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
var lstSubs = LazyConfig.Instance.SubItems()
.Where(t => t.autoUpdateInterval > 0)
.Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60)
.ToList();
foreach (var item in lstSubs)
{
updateHandle.UpdateSubscriptionProcess(config, item.id, true, (bool success, string msg) =>
{
update(success, msg);
if (success)
Utils.SaveLog("subscription" + msg);
});
item.updateTime = updateTime;
ConfigHandler.AddSubItem(ref config, item);
Thread.Sleep(5000);
}
Thread.Sleep(60000);
}
}
private void UpdateTaskRunGeo(Config config, Action<bool, string> update)
{ {
var autoUpdateSubTime = DateTime.Now;
var autoUpdateGeoTime = DateTime.Now; var autoUpdateGeoTime = DateTime.Now;
Thread.Sleep(60000); Thread.Sleep(1000 * 120);
Utils.SaveLog("UpdateTaskRun"); Utils.SaveLog("UpdateTaskRunGeo");
var updateHandle = new UpdateHandle(); var updateHandle = new UpdateHandle();
while (true) while (true)
{ {
var dtNow = DateTime.Now; var dtNow = DateTime.Now;
if (config.guiItem.autoUpdateSubInterval > 0)
{
if ((dtNow - autoUpdateSubTime).Hours % config.guiItem.autoUpdateSubInterval == 0)
{
updateHandle.UpdateSubscriptionProcess(config, "", true, (bool success, string msg) =>
{
update(success, msg);
if (success)
Utils.SaveLog("subscription" + msg);
});
autoUpdateSubTime = dtNow;
}
Thread.Sleep(60000);
}
if (config.guiItem.autoUpdateInterval > 0) if (config.guiItem.autoUpdateInterval > 0)
{ {
if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0) if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0)

View file

@ -22,5 +22,8 @@ namespace v2rayN.Mode
public string filter { get; set; } public string filter { get; set; }
public int autoUpdateInterval { get; set; }
public long updateTime { get; set; }
} }
} }

View file

@ -366,6 +366,15 @@ namespace v2rayN.Resx {
} }
} }
/// <summary>
/// 查找类似 Automatic update interval(minutes) 的本地化字符串。
/// </summary>
public static string LvAutoUpdateInterval {
get {
return ResourceManager.GetString("LvAutoUpdateInterval", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Count 的本地化字符串。 /// 查找类似 Count 的本地化字符串。
/// </summary> /// </summary>
@ -2257,15 +2266,6 @@ namespace v2rayN.Resx {
} }
} }
/// <summary>
/// 查找类似 Automatic update interval of subscriptions (hours) 的本地化字符串。
/// </summary>
public static string TbSettingsAutoUpdate {
get {
return ResourceManager.GetString("TbSettingsAutoUpdate", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Automatic update interval of and Geo (hours) 的本地化字符串。 /// 查找类似 Automatic update interval of and Geo (hours) 的本地化字符串。
/// </summary> /// </summary>

View file

@ -724,9 +724,6 @@
<data name="TbSettingsAutoHideStartup" xml:space="preserve"> <data name="TbSettingsAutoHideStartup" xml:space="preserve">
<value>Auto hide startup</value> <value>Auto hide startup</value>
</data> </data>
<data name="TbSettingsAutoUpdate" xml:space="preserve">
<value>فاصله به روز رسانی خودکار اشتراک ها (ساعت)</value>
</data>
<data name="TbSettingsAutoUpdateInterval" xml:space="preserve"> <data name="TbSettingsAutoUpdateInterval" xml:space="preserve">
<value>فاصله به روز رسانی خودکار و Geo (ساعت)</value> <value>فاصله به روز رسانی خودکار و Geo (ساعت)</value>
</data> </data>

View file

@ -724,9 +724,6 @@
<data name="TbSettingsAutoHideStartup" xml:space="preserve"> <data name="TbSettingsAutoHideStartup" xml:space="preserve">
<value>Auto hide startup</value> <value>Auto hide startup</value>
</data> </data>
<data name="TbSettingsAutoUpdate" xml:space="preserve">
<value>Automatic update interval of subscriptions (hours)</value>
</data>
<data name="TbSettingsAutoUpdateInterval" xml:space="preserve"> <data name="TbSettingsAutoUpdateInterval" xml:space="preserve">
<value>Automatic update interval of and Geo (hours)</value> <value>Automatic update interval of and Geo (hours)</value>
</data> </data>
@ -1111,4 +1108,7 @@
<data name="SpeedDisplayText" xml:space="preserve"> <data name="SpeedDisplayText" xml:space="preserve">
<value>{0}:{1}/s↑ | {2}/s↓</value> <value>{0}:{1}/s↑ | {2}/s↓</value>
</data> </data>
<data name="LvAutoUpdateInterval" xml:space="preserve">
<value>Automatic update interval(minutes)</value>
</data>
</root> </root>

View file

@ -724,9 +724,6 @@
<data name="TbSettingsAutoHideStartup" xml:space="preserve"> <data name="TbSettingsAutoHideStartup" xml:space="preserve">
<value>Auto hide startup</value> <value>Auto hide startup</value>
</data> </data>
<data name="TbSettingsAutoUpdate" xml:space="preserve">
<value>Интервал автоматического обновления подписок в часах</value>
</data>
<data name="TbSettingsAutoUpdateInterval" xml:space="preserve"> <data name="TbSettingsAutoUpdateInterval" xml:space="preserve">
<value>Интервал автоматического обновления Geo в часах</value> <value>Интервал автоматического обновления Geo в часах</value>
</data> </data>

View file

@ -724,9 +724,6 @@
<data name="TbSettingsAutoHideStartup" xml:space="preserve"> <data name="TbSettingsAutoHideStartup" xml:space="preserve">
<value>启动后隐藏窗口</value> <value>启动后隐藏窗口</value>
</data> </data>
<data name="TbSettingsAutoUpdate" xml:space="preserve">
<value>自动更新订阅的间隔(单位小时)</value>
</data>
<data name="TbSettingsAutoUpdateInterval" xml:space="preserve"> <data name="TbSettingsAutoUpdateInterval" xml:space="preserve">
<value>自动更新Geo文件的间隔(单位小时)</value> <value>自动更新Geo文件的间隔(单位小时)</value>
</data> </data>
@ -1108,4 +1105,7 @@
<data name="LvMoreUrl" xml:space="preserve"> <data name="LvMoreUrl" xml:space="preserve">
<value>更多地址(url),用逗号(,)分隔</value> <value>更多地址(url),用逗号(,)分隔</value>
</data> </data>
<data name="LvAutoUpdateInterval" xml:space="preserve">
<value>自动更新间隔(分钟)</value>
</data>
</root> </root>

View file

@ -60,7 +60,6 @@ namespace v2rayN.ViewModels
[Reactive] public bool EnableDragDropSort { get; set; } [Reactive] public bool EnableDragDropSort { get; set; }
[Reactive] public bool DoubleClick2Activate { get; set; } [Reactive] public bool DoubleClick2Activate { get; set; }
[Reactive] public int autoUpdateInterval { get; set; } [Reactive] public int autoUpdateInterval { get; set; }
[Reactive] public int autoUpdateSubInterval { get; set; }
[Reactive] public int trayMenuServersLimit { get; set; } [Reactive] public int trayMenuServersLimit { get; set; }
[Reactive] public string currentFontFamily { get; set; } [Reactive] public string currentFontFamily { get; set; }
[Reactive] public int SpeedTestTimeout { get; set; } [Reactive] public int SpeedTestTimeout { get; set; }
@ -156,7 +155,6 @@ namespace v2rayN.ViewModels
EnableDragDropSort = _config.uiItem.enableDragDropSort; EnableDragDropSort = _config.uiItem.enableDragDropSort;
DoubleClick2Activate = _config.uiItem.doubleClick2Activate; DoubleClick2Activate = _config.uiItem.doubleClick2Activate;
autoUpdateInterval = _config.guiItem.autoUpdateInterval; autoUpdateInterval = _config.guiItem.autoUpdateInterval;
autoUpdateSubInterval = _config.guiItem.autoUpdateSubInterval;
trayMenuServersLimit = _config.guiItem.trayMenuServersLimit; trayMenuServersLimit = _config.guiItem.trayMenuServersLimit;
currentFontFamily = _config.uiItem.currentFontFamily; currentFontFamily = _config.uiItem.currentFontFamily;
SpeedTestTimeout = _config.speedTestItem.speedTestTimeout; SpeedTestTimeout = _config.speedTestItem.speedTestTimeout;
@ -333,7 +331,6 @@ namespace v2rayN.ViewModels
_config.guiItem.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13; _config.guiItem.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13;
_config.uiItem.autoHideStartup = AutoHideStartup; _config.uiItem.autoHideStartup = AutoHideStartup;
_config.guiItem.autoUpdateInterval = autoUpdateInterval; _config.guiItem.autoUpdateInterval = autoUpdateInterval;
_config.guiItem.autoUpdateSubInterval = autoUpdateSubInterval;
_config.guiItem.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate; _config.guiItem.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate;
_config.uiItem.enableDragDropSort = EnableDragDropSort; _config.uiItem.enableDragDropSort = EnableDragDropSort;
_config.uiItem.doubleClick2Activate = DoubleClick2Activate; _config.uiItem.doubleClick2Activate = DoubleClick2Activate;

View file

@ -64,6 +64,7 @@ namespace v2rayN.ViewModels
item.url = SelectedSource.url; item.url = SelectedSource.url;
item.moreUrl = SelectedSource.moreUrl; item.moreUrl = SelectedSource.moreUrl;
item.enabled = SelectedSource.enabled; item.enabled = SelectedSource.enabled;
item.autoUpdateInterval = SelectedSource.autoUpdateInterval;
item.userAgent = SelectedSource.userAgent; item.userAgent = SelectedSource.userAgent;
item.sort = SelectedSource.sort; item.sort = SelectedSource.sort;
item.filter = SelectedSource.filter; item.filter = SelectedSource.filter;

View file

@ -668,22 +668,6 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="13"
Grid.Column="0"
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsAutoUpdate}" />
<TextBox
x:Name="txtautoUpdateSubInterval"
Grid.Row="13"
Grid.Column="1"
Width="200"
Margin="{StaticResource SettingItemMargin}"
HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" />
<TextBlock <TextBlock
Grid.Row="14" Grid.Row="14"
Grid.Column="0" Grid.Column="0"

View file

@ -160,7 +160,6 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.EnableDragDropSort, v => v.togEnableDragDropSort.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.EnableDragDropSort, v => v.togEnableDragDropSort.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.DoubleClick2Activate, v => v.togDoubleClick2Activate.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.DoubleClick2Activate, v => v.togDoubleClick2Activate.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.autoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.autoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.autoUpdateSubInterval, v => v.txtautoUpdateSubInterval.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.trayMenuServersLimit, v => v.txttrayMenuServersLimit.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.trayMenuServersLimit, v => v.txttrayMenuServersLimit.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.currentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.currentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.Text).DisposeWith(disposables);

View file

@ -11,7 +11,7 @@
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuSubSetting}" Title="{x:Static resx:ResUI.menuSubSetting}"
Width="700" Width="700"
Height="550" Height="600"
x:TypeArguments="vms:SubEditViewModel" x:TypeArguments="vms:SubEditViewModel"
Background="{DynamicResource MaterialDesignPaper}" Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}"
@ -49,6 +49,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
@ -145,10 +146,28 @@
Grid.Column="0" Grid.Column="0"
Margin="4" Margin="4"
VerticalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.LvAutoUpdateInterval}" />
<TextBox
x:Name="txtAutoUpdateInterval"
Grid.Row="4"
Grid.Column="1"
Width="400"
Margin="4"
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="{x:Static resx:ResUI.SubUrlTips}"
AcceptsReturn="True"
Style="{StaticResource MyOutlinedTextBox}" />
<TextBlock
Grid.Row="5"
Grid.Column="0"
Margin="4"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.LvUserAgent}" /> Text="{x:Static resx:ResUI.LvUserAgent}" />
<TextBox <TextBox
x:Name="txtUserAgent" x:Name="txtUserAgent"
Grid.Row="4" Grid.Row="5"
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="4" Margin="4"
@ -159,7 +178,7 @@
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<TextBlock <TextBlock
Grid.Row="5" Grid.Row="6"
Grid.Column="0" Grid.Column="0"
Margin="4" Margin="4"
VerticalAlignment="Center" VerticalAlignment="Center"
@ -167,7 +186,7 @@
Text="{x:Static resx:ResUI.LvFilter}" /> Text="{x:Static resx:ResUI.LvFilter}" />
<TextBox <TextBox
x:Name="txtFilter" x:Name="txtFilter"
Grid.Row="5" Grid.Row="6"
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="4" Margin="4"
@ -177,7 +196,7 @@
Style="{StaticResource MyOutlinedTextBox}" /> Style="{StaticResource MyOutlinedTextBox}" />
<TextBlock <TextBlock
Grid.Row="6" Grid.Row="7"
Grid.Column="0" Grid.Column="0"
Margin="4" Margin="4"
VerticalAlignment="Center" VerticalAlignment="Center"
@ -185,7 +204,7 @@
Text="{x:Static resx:ResUI.LvSort}" /> Text="{x:Static resx:ResUI.LvSort}" />
<TextBox <TextBox
x:Name="txtSort" x:Name="txtSort"
Grid.Row="6" Grid.Row="7"
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="4" Margin="4"

View file

@ -22,6 +22,7 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.SelectedSource.url, v => v.txtUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.url, v => v.txtUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.moreUrl, v => v.txtMoreUrl.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.moreUrl, v => v.txtMoreUrl.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.enabled, v => v.togEnable.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.enabled, v => v.togEnable.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.autoUpdateInterval, v => v.txtAutoUpdateInterval.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.userAgent, v => v.txtUserAgent.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.userAgent, v => v.txtUserAgent.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.sort, v => v.txtSort.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.sort, v => v.txtSort.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.filter, v => v.txtFilter.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.filter, v => v.txtFilter.Text).DisposeWith(disposables);

View file

@ -10,7 +10,7 @@
xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuSubSetting}" Title="{x:Static resx:ResUI.menuSubSetting}"
Width="700" Width="800"
Height="600" Height="600"
x:TypeArguments="vms:SubSettingViewModel" x:TypeArguments="vms:SubSettingViewModel"
Background="{DynamicResource MaterialDesignPaper}" Background="{DynamicResource MaterialDesignPaper}"
@ -104,7 +104,7 @@
Binding="{Binding remarks}" Binding="{Binding remarks}"
Header="{x:Static resx:ResUI.LvRemarks}" /> Header="{x:Static resx:ResUI.LvRemarks}" />
<DataGridTextColumn <DataGridTextColumn
Width="200" Width="150"
Binding="{Binding url}" Binding="{Binding url}"
Header="{x:Static resx:ResUI.LvUrl}" /> Header="{x:Static resx:ResUI.LvUrl}" />
<DataGridTextColumn <DataGridTextColumn
@ -112,7 +112,11 @@
Binding="{Binding enabled}" Binding="{Binding enabled}"
Header="{x:Static resx:ResUI.LvEnabled}" /> Header="{x:Static resx:ResUI.LvEnabled}" />
<DataGridTextColumn <DataGridTextColumn
Width="200" Width="150"
Binding="{Binding autoUpdateInterval}"
Header="{x:Static resx:ResUI.LvAutoUpdateInterval}" />
<DataGridTextColumn
Width="150"
Binding="{Binding userAgent}" Binding="{Binding userAgent}"
Header="{x:Static resx:ResUI.LvUserAgent}" /> Header="{x:Static resx:ResUI.LvUserAgent}" />
<DataGridTextColumn <DataGridTextColumn