Skip to content

Commit

Permalink
change updater interval from minutes to timespan
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Mar 21, 2022
1 parent ce9c586 commit 087f879
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions VpnHood.App.Launcher/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions VpnHood.App.Launcher/UpdaterOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 087f879

Please sign in to comment.