Skip to content

Commit 6aa5c1c

Browse files
Fix settings update progress binding (#322)
Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent d9a9346 commit 6aa5c1c

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

src/SwitchifyPc.App/SettingsWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,10 @@
543543
Style="{StaticResource MutedText}" />
544544
<StackPanel Margin="0,10,0,0"
545545
Visibility="{Binding IsUpdateDownloading, Converter={StaticResource BooleanToVisibilityConverter}}">
546-
<ProgressBar Value="{Binding UpdateDownloadPercent}"
547-
IsIndeterminate="{Binding IsUpdateDownloadIndeterminate}" />
546+
<ProgressBar Value="{Binding UpdateDownloadPercent, Mode=OneWay}"
547+
IsIndeterminate="{Binding IsUpdateDownloadIndeterminate, Mode=OneWay}" />
548548
<TextBlock Margin="0,6,0,0"
549-
Text="{Binding UpdateDownloadProgressText}"
549+
Text="{Binding UpdateDownloadProgressText, Mode=OneWay}"
550550
Style="{StaticResource MutedText}" />
551551
</StackPanel>
552552
<WrapPanel Margin="0,14,0,0">
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Threading;
2+
using SwitchifyPc.App;
3+
using SwitchifyPc.Core.Ui;
4+
using SwitchifyPc.Core.Updates;
5+
6+
namespace SwitchifyPc.Tests;
7+
8+
public sealed class SettingsWindowTests
9+
{
10+
[Fact]
11+
public void SettingsWindowLoadsWithUpdateDownloadProgress()
12+
{
13+
RunOnSta(() =>
14+
{
15+
SettingsViewModel viewModel = new();
16+
viewModel.SetUpdateState(UpdateState.CreateInitial("0.2.4") with
17+
{
18+
Download = new UpdateDownloadProgress(
19+
UpdateDownloadStatus.Downloading,
20+
20_971_520,
21+
52_428_800,
22+
40)
23+
});
24+
25+
SettingsWindow window = new(viewModel);
26+
try
27+
{
28+
window.Show();
29+
window.UpdateLayout();
30+
}
31+
finally
32+
{
33+
window.Close();
34+
}
35+
});
36+
}
37+
38+
private static void RunOnSta(Action action)
39+
{
40+
Exception? exception = null;
41+
Thread thread = new(() =>
42+
{
43+
try
44+
{
45+
action();
46+
}
47+
catch (Exception error)
48+
{
49+
exception = error;
50+
}
51+
});
52+
53+
thread.SetApartmentState(ApartmentState.STA);
54+
thread.Start();
55+
thread.Join();
56+
57+
if (exception is not null) throw exception;
58+
}
59+
}

src/SwitchifyPc.Tests/SwitchifyPc.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<ItemGroup>
2121
<ProjectReference Include="..\SwitchifyPc.Core\SwitchifyPc.Core.csproj" />
22+
<ProjectReference Include="..\SwitchifyPc.App\SwitchifyPc.App.csproj" />
2223
<ProjectReference Include="..\SwitchifyPc.Protocol\SwitchifyPc.Protocol.csproj" />
2324
<ProjectReference Include="..\SwitchifyPc.Windows\SwitchifyPc.Windows.csproj" />
2425
</ItemGroup>

0 commit comments

Comments
 (0)