diff --git a/VpnHood.App.Launcher/Updater.cs b/VpnHood.App.Launcher/Updater.cs index 329107155..caaea6c16 100644 --- a/VpnHood.App.Launcher/Updater.cs +++ b/VpnHood.App.Launcher/Updater.cs @@ -28,7 +28,7 @@ public Updater(string? appFolder = null, UpdaterOptions? options = null) AppFolder = appFolder ?? Path.GetDirectoryName(Path.GetDirectoryName(typeof(Updater).Assembly.Location)) ?? throw new ArgumentException("Could not set AppFolder", nameof(appFolder)); - CheckIntervalMinutes = options.CheckIntervalMinutes; + CheckInterval = options.CheckInterval; var publishInfoFilePath = Path.Combine(AppFolder, "publish.json"); Console.WriteLine(publishInfoFilePath); @@ -52,7 +52,7 @@ public Updater(string? appFolder = null, UpdaterOptions? options = null) public string AppFolder { get; } public Uri? UpdateUri { get; } - public int CheckIntervalMinutes { get; } + public TimeSpan CheckInterval { get; } public string UpdatesFolder => Path.Combine(AppFolder, "updates"); public string NewPublishInfoFilePath => Path.Combine(UpdatesFolder, "publish.json"); private string LastCheckFilePath => Path.Combine(UpdatesFolder, "lastcheck.json"); @@ -108,8 +108,8 @@ public int Start() CheckUpdateOffline(); // Create Update Interval - if (UpdateUri != null && CheckIntervalMinutes != 0) - _timer = new Timer(_ => CheckUpdateOnlineInterval(), null, 0, CheckIntervalMinutes * 60 * 1000); + if (UpdateUri != null && CheckInterval != TimeSpan.Zero) + _timer = new Timer(_ => CheckUpdateOnlineInterval(), null, TimeSpan.Zero, CheckInterval); // launch main app if (!CancellationToken.IsCancellationRequested) @@ -124,7 +124,7 @@ private void CheckUpdateOnlineInterval() { // read last check var lastOnlineCheckTime = LastOnlineCheckTime ?? DateTime.MinValue; - if ((DateTime.Now - lastOnlineCheckTime).TotalMinutes >= CheckIntervalMinutes) + if ((DateTime.Now - lastOnlineCheckTime) >= CheckInterval) CheckUpdateOnline().GetAwaiter(); } catch (Exception ex) diff --git a/VpnHood.App.Launcher/UpdaterOptions.cs b/VpnHood.App.Launcher/UpdaterOptions.cs index 3aa589557..60fc361a8 100644 --- a/VpnHood.App.Launcher/UpdaterOptions.cs +++ b/VpnHood.App.Launcher/UpdaterOptions.cs @@ -1,11 +1,12 @@ -using Microsoft.Extensions.Logging; +using System; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; namespace VpnHood.App.Launcher { public class UpdaterOptions { - public int CheckIntervalMinutes { get; set; } = 1 * 24 * 60; + public TimeSpan CheckInterval { get; set; } = TimeSpan.FromHours(12); public ILogger Logger { get; set; } = NullLogger.Instance; } } \ No newline at end of file