From e5be649a2d1f533d30e37718ec41660b103d54df Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 7 Apr 2024 09:51:55 +0800 Subject: [PATCH] fix: Github REST API access rate limit (#60) --- src/App.axaml.cs | 5 ++++- src/ViewModels/Preference.cs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index c9aa6a4d..8ef9e336 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -227,8 +227,11 @@ namespace SourceGit _notificationReceiver = launcher; desktop.MainWindow = launcher; - if (ViewModels.Preference.Instance.Check4UpdatesOnStartup) + if (ViewModels.Preference.Instance.ShouldCheck4UpdateOnStartup) + { + ViewModels.Preference.Save(); Check4Update(); + } } base.OnFrameworkInitializationCompleted(); diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 8be7f9e2..ee8f96a9 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -278,6 +278,31 @@ namespace SourceGit.ViewModels set; } = 0; + public double LastCheckUpdateTime + { + get; + set; + } = 0; + + [JsonIgnore] + public bool ShouldCheck4UpdateOnStartup + { + get + { + if (!_check4UpdatesOnStartup) + return false; + + var lastCheck = DateTime.UnixEpoch.AddSeconds(LastCheckUpdateTime).ToLocalTime(); + var now = DateTime.Now; + + if (lastCheck.Year == now.Year && lastCheck.Month == now.Month && lastCheck.Day == now.Day) + return false; + + LastCheckUpdateTime = now.Subtract(DateTime.UnixEpoch.ToLocalTime()).TotalSeconds; + return true; + } + } + public static void AddNode(RepositoryNode node, RepositoryNode to = null) { var collection = to == null ? _instance._repositoryNodes : to.SubNodes;