App: Add auto update check on network change to active
All checks were successful
Test / Run tests (push) Successful in 1m55s

This commit is contained in:
2025-09-18 23:37:10 +02:00
parent a0dcaf7b4f
commit 8bc053053c

View File

@@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -131,6 +132,7 @@ namespace Elwig {
await CheckForUpdates(); await CheckForUpdates();
}); });
} }
NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
_autoUpdateTimer.Tick += new EventHandler(OnAutoUpdateTimer); _autoUpdateTimer.Tick += new EventHandler(OnAutoUpdateTimer);
_autoUpdateTimer.Start(); _autoUpdateTimer.Start();
} }
@@ -228,6 +230,16 @@ namespace Elwig {
} }
} }
private void OnNetworkAvailabilityChanged(object? sender, NetworkAvailabilityEventArgs evt) {
if (!evt.IsAvailable) return;
if (Utils.HasInternetConnectivity()) {
Utils.RunBackground("Auto Updater", async () => {
await Task.Delay(500);
await CheckForUpdates();
});
}
}
public static async Task CheckForUpdates(bool showAlert = false) { public static async Task CheckForUpdates(bool showAlert = false) {
if (Config.UpdateUrl == null) return; if (Config.UpdateUrl == null) return;
var latest = await Utils.GetLatestInstallerUrl(Config.UpdateUrl); var latest = await Utils.GetLatestInstallerUrl(Config.UpdateUrl);