Skip to content

Commit cd3881c

Browse files
[feature] Update behavior for Windows Store installations (#139)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c5755fc commit cd3881c

4 files changed

Lines changed: 50 additions & 37 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using ByteSync.Common.Business.Misc;
2+
using ByteSync.Interfaces.Controls.Applications;
3+
4+
namespace ByteSync.Helpers;
5+
6+
public static class EnvironmentServiceExtensions
7+
{
8+
public static bool IsInstalledFromWindowsStore(this IEnvironmentService environmentService)
9+
{
10+
if (environmentService.OSPlatform == OSPlatforms.Windows)
11+
{
12+
if (environmentService.AssemblyFullName.Contains("\\Program Files\\WindowsApps\\") ||
13+
environmentService.AssemblyFullName.Contains("\\Program Files (x86)\\WindowsApps\\"))
14+
{
15+
return true;
16+
}
17+
}
18+
19+
return false;
20+
}
21+
}

src/ByteSync.Client/Services/Updates/SearchUpdateService.cs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ByteSync.Interfaces.Controls.Applications;
44
using ByteSync.Interfaces.Repositories;
55
using ByteSync.Interfaces.Updates;
6+
using ByteSync.Helpers;
67

78
namespace ByteSync.Services.Updates;
89

@@ -26,13 +27,12 @@ public async Task SearchNextAvailableVersionsAsync()
2627
{
2728
try
2829
{
29-
if (IsApplicationInstalledFromStore)
30+
// Check if the application is installed from the Windows Store. This condition is used for logging purposes
31+
// and does not affect the subsequent code execution. Auto-update is disabled for store installations, but
32+
// other parts of the method will still execute to log available updates and update the repository.
33+
if (_environmentService.IsInstalledFromWindowsStore())
3034
{
31-
_availableUpdateRepository.UpdateAvailableUpdates(new List<SoftwareVersion>());
32-
33-
_logger.LogInformation("UpdateSystem: Application is installed from store, update check is disabled");
34-
35-
return;
35+
_logger.LogInformation("UpdateSystem: Application is installed from store, auto-update is disabled");
3636
}
3737

3838
var updates = await _availableUpdatesLister.GetAvailableUpdates();
@@ -80,23 +80,6 @@ public async Task SearchNextAvailableVersionsAsync()
8080
}
8181
}
8282

83-
public bool IsApplicationInstalledFromStore
84-
{
85-
get
86-
{
87-
if (_environmentService.OSPlatform == OSPlatforms.Windows)
88-
{
89-
if (_environmentService.AssemblyFullName.Contains("\\Program Files\\WindowsApps\\")
90-
|| _environmentService.AssemblyFullName.Contains("\\Program Files (x86)\\WindowsApps\\"))
91-
{
92-
return true;
93-
}
94-
}
95-
96-
return false;
97-
}
98-
}
99-
10083
private List<SoftwareVersion> DeduplicateVersions(List<SoftwareVersion> nextAvailableVersions)
10184
{
10285
var deduplicatedVersions = new List<SoftwareVersion>();

src/ByteSync.Client/ViewModels/Headers/UpdateDetailsViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using DynamicData.Binding;
2121
using ReactiveUI;
2222
using ReactiveUI.Fody.Helpers;
23+
using ByteSync.Helpers;
2324

2425
namespace ByteSync.ViewModels.Headers;
2526

@@ -115,6 +116,11 @@ public bool CanAutoUpdate
115116
{
116117
get
117118
{
119+
if (_environmentService.IsInstalledFromWindowsStore())
120+
{
121+
return false;
122+
}
123+
118124
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
119125
(_environmentService.IsPortableApplication && RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
120126
}

tests/ByteSync.Client.Tests/Services/Communications/SearchUpdateServiceTests.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,30 @@ public async Task SearchNextAvailableVersionsAsync_ShouldDeduplicateVersions()
154154
[Theory]
155155
[TestCase(@"C:\Program Files\WindowsApps\MyApp.exe")]
156156
[TestCase(@"C:\Program Files (x86)\WindowsApps\MyApp.exe")]
157-
public async Task SearchNextAvailableVersionsAsync_WhenInstalledFromStore_ShouldUpdateWithEmptyList(string assemblyFullName)
157+
public async Task SearchNextAvailableVersionsAsync_WhenInstalledFromStore_ShouldSearchForUpdates(string assemblyFullName)
158158
{
159159
// Arrange
160-
_mockEnvironmentService.SetupGet(m => m.AssemblyFullName)
161-
.Returns(@"C:\Program Files\WindowsApps\MyApp.exe");
162-
_mockEnvironmentService.SetupGet(m => m.OSPlatform)
163-
.Returns(OSPlatforms.Windows);
160+
var currentVersion = new Version("1.0.0");
161+
_mockEnvironmentService.SetupGet(m => m.ApplicationVersion).Returns(currentVersion);
162+
_mockEnvironmentService.SetupGet(m => m.AssemblyFullName).Returns(assemblyFullName);
163+
_mockEnvironmentService.SetupGet(m => m.OSPlatform).Returns(OSPlatforms.Windows);
164+
165+
var availableUpdates = new List<SoftwareVersion>
166+
{
167+
CreateSoftwareVersion("1.1.0", PriorityLevel.Minimal)
168+
};
169+
170+
_mockAvailableUpdatesLister.Setup(m => m.GetAvailableUpdates())
171+
.ReturnsAsync(availableUpdates);
164172

165173
// Act
166174
await _searchUpdateService.SearchNextAvailableVersionsAsync();
167175

168176
// Assert
169-
_mockAvailableUpdateRepository.Verify(
170-
m => m.UpdateAvailableUpdates(It.Is<List<SoftwareVersion>>(list => list.Count == 0)),
171-
Times.Once
172-
);
173-
_mockAvailableUpdateRepository.Verify(
174-
m => m.UpdateAvailableUpdates(It.IsAny<List<SoftwareVersion>>()), Times.Once);
175-
_mockAvailableUpdateRepository.Verify(
176-
m => m.Clear(), Times.Never);
177-
_mockAvailableUpdatesLister.Verify(m => m.GetAvailableUpdates(), Times.Never);
177+
_mockAvailableUpdateRepository.Verify(m => m.UpdateAvailableUpdates(It.Is<List<SoftwareVersion>>(
178+
list => list.Count == 1 && list[0].Version == "1.1.0")), Times.Once);
179+
_mockAvailableUpdateRepository.Verify(m => m.Clear(), Times.Never);
180+
_mockAvailableUpdatesLister.Verify(m => m.GetAvailableUpdates(), Times.Once);
178181
}
179182

180183
private SoftwareVersion CreateSoftwareVersion(string version, PriorityLevel level)

0 commit comments

Comments
 (0)