Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ByteSync.Client/Helpers/EnvironmentServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ByteSync.Common.Business.Misc;
using ByteSync.Interfaces.Controls.Applications;

namespace ByteSync.Helpers;

public static class EnvironmentServiceExtensions
{
public static bool IsInstalledFromWindowsStore(this IEnvironmentService environmentService)
{
if (environmentService.OSPlatform == OSPlatforms.Windows)
{
if (environmentService.AssemblyFullName.Contains("\\Program Files\\WindowsApps\\") ||
environmentService.AssemblyFullName.Contains("\\Program Files (x86)\\WindowsApps\\"))
{
return true;
}
}

return false;
}
}
29 changes: 6 additions & 23 deletions src/ByteSync.Client/Services/Updates/SearchUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ByteSync.Interfaces.Controls.Applications;
using ByteSync.Interfaces.Repositories;
using ByteSync.Interfaces.Updates;
using ByteSync.Helpers;

namespace ByteSync.Services.Updates;

Expand All @@ -26,13 +27,12 @@ public async Task SearchNextAvailableVersionsAsync()
{
try
{
if (IsApplicationInstalledFromStore)
// Check if the application is installed from the Windows Store. This condition is used for logging purposes
// and does not affect the subsequent code execution. Auto-update is disabled for store installations, but
// other parts of the method will still execute to log available updates and update the repository.
if (_environmentService.IsInstalledFromWindowsStore())
{
_availableUpdateRepository.UpdateAvailableUpdates(new List<SoftwareVersion>());

_logger.LogInformation("UpdateSystem: Application is installed from store, update check is disabled");

return;
_logger.LogInformation("UpdateSystem: Application is installed from store, auto-update is disabled");
}

var updates = await _availableUpdatesLister.GetAvailableUpdates();
Expand Down Expand Up @@ -80,23 +80,6 @@ public async Task SearchNextAvailableVersionsAsync()
}
}

public bool IsApplicationInstalledFromStore
{
get
{
if (_environmentService.OSPlatform == OSPlatforms.Windows)
{
if (_environmentService.AssemblyFullName.Contains("\\Program Files\\WindowsApps\\")
|| _environmentService.AssemblyFullName.Contains("\\Program Files (x86)\\WindowsApps\\"))
{
return true;
}
}

return false;
}
}

private List<SoftwareVersion> DeduplicateVersions(List<SoftwareVersion> nextAvailableVersions)
{
var deduplicatedVersions = new List<SoftwareVersion>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using ByteSync.Helpers;

namespace ByteSync.ViewModels.Headers;

Expand Down Expand Up @@ -115,6 +116,11 @@ public bool CanAutoUpdate
{
get
{
if (_environmentService.IsInstalledFromWindowsStore())
{
return false;
}

return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
(_environmentService.IsPortableApplication && RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,30 @@ public async Task SearchNextAvailableVersionsAsync_ShouldDeduplicateVersions()
[Theory]
[TestCase(@"C:\Program Files\WindowsApps\MyApp.exe")]
[TestCase(@"C:\Program Files (x86)\WindowsApps\MyApp.exe")]
public async Task SearchNextAvailableVersionsAsync_WhenInstalledFromStore_ShouldUpdateWithEmptyList(string assemblyFullName)
public async Task SearchNextAvailableVersionsAsync_WhenInstalledFromStore_ShouldSearchForUpdates(string assemblyFullName)
{
// Arrange
_mockEnvironmentService.SetupGet(m => m.AssemblyFullName)
.Returns(@"C:\Program Files\WindowsApps\MyApp.exe");
_mockEnvironmentService.SetupGet(m => m.OSPlatform)
.Returns(OSPlatforms.Windows);
var currentVersion = new Version("1.0.0");
_mockEnvironmentService.SetupGet(m => m.ApplicationVersion).Returns(currentVersion);
_mockEnvironmentService.SetupGet(m => m.AssemblyFullName).Returns(assemblyFullName);
_mockEnvironmentService.SetupGet(m => m.OSPlatform).Returns(OSPlatforms.Windows);

var availableUpdates = new List<SoftwareVersion>
{
CreateSoftwareVersion("1.1.0", PriorityLevel.Minimal)
};

_mockAvailableUpdatesLister.Setup(m => m.GetAvailableUpdates())
.ReturnsAsync(availableUpdates);

// Act
await _searchUpdateService.SearchNextAvailableVersionsAsync();

// Assert
_mockAvailableUpdateRepository.Verify(
m => m.UpdateAvailableUpdates(It.Is<List<SoftwareVersion>>(list => list.Count == 0)),
Times.Once
);
_mockAvailableUpdateRepository.Verify(
m => m.UpdateAvailableUpdates(It.IsAny<List<SoftwareVersion>>()), Times.Once);
_mockAvailableUpdateRepository.Verify(
m => m.Clear(), Times.Never);
_mockAvailableUpdatesLister.Verify(m => m.GetAvailableUpdates(), Times.Never);
_mockAvailableUpdateRepository.Verify(m => m.UpdateAvailableUpdates(It.Is<List<SoftwareVersion>>(
list => list.Count == 1 && list[0].Version == "1.1.0")), Times.Once);
_mockAvailableUpdateRepository.Verify(m => m.Clear(), Times.Never);
_mockAvailableUpdatesLister.Verify(m => m.GetAvailableUpdates(), Times.Once);
}

private SoftwareVersion CreateSoftwareVersion(string version, PriorityLevel level)
Expand Down