Skip to content

Commit

Permalink
fix(Update): Only notify about the latest version, not all version hi…
Browse files Browse the repository at this point in the history
…gher than the current one

Fixes #806
  • Loading branch information
Belphemur committed Oct 30, 2021
1 parent f96f86b commit 337ea6f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions SoundSwitch/Framework/Updater/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public UpdateChecker(Uri releaseUrl, bool checkBeta)
Beta = checkBeta;
}

private bool ProcessRelease(Release serverRelease)
/// <summary>
/// Process the release, and notify about it if it's newer than the version of the app.
/// </summary>
/// <returns>true if the release is newer and has been notified</returns>
private bool ProcessAndNotifyRelease(Release serverRelease)
{
Log.Information("Checking version {version} ", serverRelease);
if (serverRelease.Prerelease && !Beta)
Expand Down Expand Up @@ -91,10 +95,13 @@ public async Task CheckForUpdate(CancellationToken token)
httpClient.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.CommentValue);
httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
var releases = await httpClient.GetFromJsonAsync(_releaseUrl, GithubReleasesJsonContext.Default.ReleaseArray, token);
foreach (var release in releases ?? Array.Empty<Release>())
foreach (var release in (releases ?? Array.Empty<Release>()).OrderByDescending(release => new Version(release.TagName.Substring(1))))
{
token.ThrowIfCancellationRequested();
ProcessRelease(release);
if (ProcessAndNotifyRelease(release))
{
break;
}
}
}

Expand Down

0 comments on commit 337ea6f

Please sign in to comment.