diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index 8f84c346..d65fee4e 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -62,14 +62,30 @@ namespace SourceGit.Commands public class AutoFetch { - private const double INTERVAL = 10 * 60; - public static bool IsEnabled { get; set; } = false; + public static int Interval + { + get => _interval; + set + { + if (value < 1) + return; + _interval = value; + lock (_lock) + { + foreach (var job in _jobs) + { + job.Value.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(_interval)); + } + } + } + } + class Job { public Fetch Cmd = null; @@ -104,7 +120,7 @@ namespace SourceGit.Commands foreach (var job in uptodate) { job.Cmd.Exec(); - job.NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL); + job.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)); } Thread.Sleep(2000); @@ -117,7 +133,7 @@ namespace SourceGit.Commands var job = new Job { Cmd = new Fetch(repo, "--all", true, null) { RaiseError = false }, - NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL), + NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)), }; lock (_lock) @@ -147,12 +163,13 @@ namespace SourceGit.Commands { if (_jobs.TryGetValue(repo, out var value)) { - value.NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL); + value.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)); } } } private static readonly Dictionary _jobs = new Dictionary(); private static readonly object _lock = new object(); + private static int _interval = 10; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 381c6dbe..daa2fa7d 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -274,6 +274,7 @@ Use fixed tab width in titlebar GIT Fetch remotes automatically + Auto Fetch Interval Enable Auto CRLF Default Clone Dir User Email diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 6a50539d..b0e4bce2 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -274,6 +274,7 @@ 使用固定宽度的标题栏标签 GIT配置 启用定时自动拉取远程更新 + 自动拉取间隔 自动换行转换 默认克隆路径 邮箱 diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index a9cb6277..85f26611 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -232,6 +232,23 @@ namespace SourceGit.ViewModels } } + public int? GitAutoFetchInterval + { + get => Commands.AutoFetch.Interval; + set + { + if (value is null or < 1) + { + return; + } + if (Commands.AutoFetch.Interval != value) + { + Commands.AutoFetch.Interval = (int)value; + OnPropertyChanged(nameof(GitAutoFetchInterval)); + } + } + } + public int ExternalMergeToolType { get => _externalMergeToolType; @@ -406,7 +423,8 @@ namespace SourceGit.ViewModels }); container.Clear(); - foreach (var one in list) container.Add(one); + foreach (var one in list) + container.Add(one); } public static Repository FindRepository(string path) diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 4579fe42..dddeb6f0 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -231,7 +231,7 @@ - + + + + + + + +