diff --git a/src/ByteSync.Client/Helpers/EnvironmentServiceExtensions.cs b/src/ByteSync.Client/Helpers/EnvironmentServiceExtensions.cs new file mode 100644 index 00000000..a64fd40c --- /dev/null +++ b/src/ByteSync.Client/Helpers/EnvironmentServiceExtensions.cs @@ -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; + } +} diff --git a/src/ByteSync.Client/Services/Updates/SearchUpdateService.cs b/src/ByteSync.Client/Services/Updates/SearchUpdateService.cs index eef0343f..f3fdb549 100644 --- a/src/ByteSync.Client/Services/Updates/SearchUpdateService.cs +++ b/src/ByteSync.Client/Services/Updates/SearchUpdateService.cs @@ -3,6 +3,7 @@ using ByteSync.Interfaces.Controls.Applications; using ByteSync.Interfaces.Repositories; using ByteSync.Interfaces.Updates; +using ByteSync.Helpers; namespace ByteSync.Services.Updates; @@ -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()); - - _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(); @@ -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 DeduplicateVersions(List nextAvailableVersions) { var deduplicatedVersions = new List(); diff --git a/src/ByteSync.Client/ViewModels/Headers/UpdateDetailsViewModel.cs b/src/ByteSync.Client/ViewModels/Headers/UpdateDetailsViewModel.cs index 2fc00eb4..f0b48b65 100644 --- a/src/ByteSync.Client/ViewModels/Headers/UpdateDetailsViewModel.cs +++ b/src/ByteSync.Client/ViewModels/Headers/UpdateDetailsViewModel.cs @@ -20,6 +20,7 @@ using DynamicData.Binding; using ReactiveUI; using ReactiveUI.Fody.Helpers; +using ByteSync.Helpers; namespace ByteSync.ViewModels.Headers; @@ -115,6 +116,11 @@ public bool CanAutoUpdate { get { + if (_environmentService.IsInstalledFromWindowsStore()) + { + return false; + } + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (_environmentService.IsPortableApplication && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); } diff --git a/tests/ByteSync.Client.Tests/Services/Communications/SearchUpdateServiceTests.cs b/tests/ByteSync.Client.Tests/Services/Communications/SearchUpdateServiceTests.cs index 90c3180b..83768471 100644 --- a/tests/ByteSync.Client.Tests/Services/Communications/SearchUpdateServiceTests.cs +++ b/tests/ByteSync.Client.Tests/Services/Communications/SearchUpdateServiceTests.cs @@ -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 + { + 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 => list.Count == 0)), - Times.Once - ); - _mockAvailableUpdateRepository.Verify( - m => m.UpdateAvailableUpdates(It.IsAny>()), Times.Once); - _mockAvailableUpdateRepository.Verify( - m => m.Clear(), Times.Never); - _mockAvailableUpdatesLister.Verify(m => m.GetAvailableUpdates(), Times.Never); + _mockAvailableUpdateRepository.Verify(m => m.UpdateAvailableUpdates(It.Is>( + 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)