diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 93981b3b..16d3a569 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -941,7 +941,11 @@ namespace v2rayN.Handler //Check for duplicate indexId List? lstDbIndexId = null; List 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) { //maybe sub diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index c20b3514..01afb56f 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -10,15 +10,7 @@ namespace v2rayN.Handler { public sealed class MainFormHandler { - private static readonly Lazy instance = new(() => new()); - //Action _updateUI; - - //private DownloadHandle downloadHandle2; - //private Config _config; - //private V2rayHandler _v2rayHandler; - //private List _selecteds; - //private Thread _workThread; - //Action _updateFunc; + private static readonly Lazy instance = new(() => new()); public static MainFormHandler Instance => instance.Value; public Icon GetNotifyIcon(Config config) @@ -285,37 +277,52 @@ namespace v2rayN.Handler public void UpdateTask(Config config, Action update) { - Task.Run(() => UpdateTaskRun(config, update)); + Task.Run(() => UpdateTaskRunSubscription(config, update)); + Task.Run(() => UpdateTaskRunGeo(config, update)); } - private void UpdateTaskRun(Config config, Action update) + private void UpdateTaskRunSubscription(Config config, Action 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 update) { - var autoUpdateSubTime = DateTime.Now; var autoUpdateGeoTime = DateTime.Now; - Thread.Sleep(60000); - Utils.SaveLog("UpdateTaskRun"); + Thread.Sleep(1000 * 120); + Utils.SaveLog("UpdateTaskRunGeo"); var updateHandle = new UpdateHandle(); while (true) { 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 ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0) diff --git a/v2rayN/v2rayN/Mode/SubItem.cs b/v2rayN/v2rayN/Mode/SubItem.cs index 5995b273..3ef59a07 100644 --- a/v2rayN/v2rayN/Mode/SubItem.cs +++ b/v2rayN/v2rayN/Mode/SubItem.cs @@ -22,5 +22,8 @@ namespace v2rayN.Mode public string filter { get; set; } + public int autoUpdateInterval { get; set; } + + public long updateTime { get; set; } } } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 4b1075d9..0b1551fe 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -366,6 +366,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Automatic update interval(minutes) 的本地化字符串。 + /// + public static string LvAutoUpdateInterval { + get { + return ResourceManager.GetString("LvAutoUpdateInterval", resourceCulture); + } + } + /// /// 查找类似 Count 的本地化字符串。 /// @@ -2257,15 +2266,6 @@ namespace v2rayN.Resx { } } - /// - /// 查找类似 Automatic update interval of subscriptions (hours) 的本地化字符串。 - /// - public static string TbSettingsAutoUpdate { - get { - return ResourceManager.GetString("TbSettingsAutoUpdate", resourceCulture); - } - } - /// /// 查找类似 Automatic update interval of and Geo (hours) 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx b/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx index 03b1630d..eff32dc3 100644 --- a/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx @@ -724,9 +724,6 @@ Auto hide startup - - فاصله به روز رسانی خودکار اشتراک ها (ساعت) - فاصله به روز رسانی خودکار و Geo (ساعت) diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index f7650bfd..2fa0683d 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -724,9 +724,6 @@ Auto hide startup - - Automatic update interval of subscriptions (hours) - Automatic update interval of and Geo (hours) @@ -1111,4 +1108,7 @@ {0}:{1}/s↑ | {2}/s↓ + + Automatic update interval(minutes) + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.ru.resx b/v2rayN/v2rayN/Resx/ResUI.ru.resx index 0bc6025b..654071af 100644 --- a/v2rayN/v2rayN/Resx/ResUI.ru.resx +++ b/v2rayN/v2rayN/Resx/ResUI.ru.resx @@ -724,9 +724,6 @@ Auto hide startup - - Интервал автоматического обновления подписок в часах - Интервал автоматического обновления Geo в часах diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index cd797a19..667399a8 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -724,9 +724,6 @@ 启动后隐藏窗口 - - 自动更新订阅的间隔(单位小时) - 自动更新Geo文件的间隔(单位小时) @@ -1108,4 +1105,7 @@ 更多地址(url),用逗号(,)分隔 + + 自动更新间隔(分钟) + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index b36c8bfb..efb1d36d 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -60,7 +60,6 @@ namespace v2rayN.ViewModels [Reactive] public bool EnableDragDropSort { get; set; } [Reactive] public bool DoubleClick2Activate { get; set; } [Reactive] public int autoUpdateInterval { get; set; } - [Reactive] public int autoUpdateSubInterval { get; set; } [Reactive] public int trayMenuServersLimit { get; set; } [Reactive] public string currentFontFamily { get; set; } [Reactive] public int SpeedTestTimeout { get; set; } @@ -156,7 +155,6 @@ namespace v2rayN.ViewModels EnableDragDropSort = _config.uiItem.enableDragDropSort; DoubleClick2Activate = _config.uiItem.doubleClick2Activate; autoUpdateInterval = _config.guiItem.autoUpdateInterval; - autoUpdateSubInterval = _config.guiItem.autoUpdateSubInterval; trayMenuServersLimit = _config.guiItem.trayMenuServersLimit; currentFontFamily = _config.uiItem.currentFontFamily; SpeedTestTimeout = _config.speedTestItem.speedTestTimeout; @@ -333,7 +331,6 @@ namespace v2rayN.ViewModels _config.guiItem.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13; _config.uiItem.autoHideStartup = AutoHideStartup; _config.guiItem.autoUpdateInterval = autoUpdateInterval; - _config.guiItem.autoUpdateSubInterval = autoUpdateSubInterval; _config.guiItem.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate; _config.uiItem.enableDragDropSort = EnableDragDropSort; _config.uiItem.doubleClick2Activate = DoubleClick2Activate; diff --git a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs index aef1a3ba..d018e799 100644 --- a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs @@ -64,6 +64,7 @@ namespace v2rayN.ViewModels item.url = SelectedSource.url; item.moreUrl = SelectedSource.moreUrl; item.enabled = SelectedSource.enabled; + item.autoUpdateInterval = SelectedSource.autoUpdateInterval; item.userAgent = SelectedSource.userAgent; item.sort = SelectedSource.sort; item.filter = SelectedSource.filter; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 7565ca7c..8b90272f 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -668,22 +668,6 @@ HorizontalAlignment="Left" Style="{StaticResource DefTextBox}" /> - - - 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.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.currentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml b/v2rayN/v2rayN/Views/SubEditWindow.xaml index 9c716014..b8d02388 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml @@ -11,7 +11,7 @@ xmlns:vms="clr-namespace:v2rayN.ViewModels" Title="{x:Static resx:ResUI.menuSubSetting}" Width="700" - Height="550" + Height="600" x:TypeArguments="vms:SubEditViewModel" Background="{DynamicResource MaterialDesignPaper}" FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" @@ -49,6 +49,7 @@ + @@ -145,10 +146,28 @@ Grid.Column="0" Margin="4" VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.LvAutoUpdateInterval}" /> + + + 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.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.sort, v => v.txtSort.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.filter, v => v.txtFilter.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml b/v2rayN/v2rayN/Views/SubSettingWindow.xaml index 39af5091..bfe2252a 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml @@ -10,7 +10,7 @@ xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:vms="clr-namespace:v2rayN.ViewModels" Title="{x:Static resx:ResUI.menuSubSetting}" - Width="700" + Width="800" Height="600" x:TypeArguments="vms:SubSettingViewModel" Background="{DynamicResource MaterialDesignPaper}" @@ -104,7 +104,7 @@ Binding="{Binding remarks}" Header="{x:Static resx:ResUI.LvRemarks}" /> +