Skip to content

Commit

Permalink
Fixed an issue where the app wrongly detect an update (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
veler authored Jun 17, 2024
1 parent 8df10d8 commit 81baa84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app/dev/DevToys.Core/AppHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,29 @@ var assemblyInformationalVersion
.GetExecutingAssembly()
.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute))!;

string currentVersion
string currentVersionString
= assemblyInformationalVersion.InformationalVersion
.TrimStart('v')
.Replace("-alpha", string.Empty)
.Replace("-beta", string.Empty)
.Replace("-preview", string.Empty)
.Replace("-pre", string.Empty);
string? releaseVersion
string? gitHubVersionString
= potentialRelease.Name?
.TrimStart('v')
.Replace("-alpha", string.Empty)
.Replace("-beta", string.Empty)
.Replace("-preview", string.Empty)
.Replace("-pre", string.Empty);

if (!string.IsNullOrEmpty(releaseVersion) && !string.IsNullOrEmpty(currentVersion))
if (!string.IsNullOrEmpty(gitHubVersionString) && !string.IsNullOrEmpty(currentVersionString))
{
if (new System.Version(releaseVersion) > new System.Version(currentVersion))
var gitHubReleaseVersion = new System.Version(gitHubVersionString);
var currentVersion = new System.Version(currentVersionString);

if (gitHubReleaseVersion.Major > currentVersion.Major
|| (gitHubReleaseVersion.Major == currentVersion.Major && gitHubReleaseVersion.Minor > currentVersion.Minor)
|| (gitHubReleaseVersion.Major == currentVersion.Major && gitHubReleaseVersion.Minor == currentVersion.Minor && gitHubReleaseVersion.Build > currentVersion.Build))
{
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions src/app/tests/DevToys.UnitTests/Core/AppHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ GitHubRelease[] releases
result.Should().BeFalse();
}

[Fact]
public async Task CheckForUpdate_Preview_NoUpdate2_Async()
{
GitHubRelease[] releases
= [
new GitHubRelease
{
Draft = false,
PreRelease = true,
Name = "v0.0.0"
},
];
string releasesJson = JsonSerializer.Serialize(releases);

var mockWebClientService = new Mock<IWebClientService>();
mockWebClientService
.Setup(service => service.SafeGetStringAsync(It.IsAny<Uri>(), CancellationToken.None))
.ReturnsAsync(releasesJson);

var mockVersionService = new Mock<IVersionService>();
mockVersionService
.Setup(service => service.IsPreviewVersion())
.Returns(true);

bool result = await AppHelper.CheckForUpdateAsync(mockWebClientService.Object, mockVersionService.Object, CancellationToken.None);
result.Should().BeFalse();
}

[Fact]
public async Task CheckForUpdate_StableAsync()
{
Expand Down

0 comments on commit 81baa84

Please sign in to comment.