Skip to content

Commit f5e9ff3

Browse files
feat: loading icon when clicking start update
#6
1 parent 93da345 commit f5e9ff3

File tree

5 files changed

+97
-10
lines changed

5 files changed

+97
-10
lines changed

src/TwitchStreamingTools/TwitchStreamingTools.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
3636
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.1"/>
3737
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.1"/>
38-
<PackageReference Include="Material.Avalonia" Version="3.12.0"/>
3938
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6"/>
4039
<PackageReference Include="NAudio.Wasapi" Version="2.2.1"/>
4140
<PackageReference Include="NAudio.WinMM" Version="2.2.1"/>

src/TwitchStreamingTools/ViewModels/NewVersionWindowViewModel.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ namespace TwitchStreamingTools.ViewModels;
1717
/// The view model for the <seealso cref="NewVersionWindow" /> class.
1818
/// </summary>
1919
public class NewVersionWindowViewModel : ViewModelBase {
20+
/// <summary>
21+
/// True if updating the application currently, false otherwise.
22+
/// </summary>
23+
private bool _isUpdating;
24+
2025
/// <summary>
2126
/// The local version of the software.
2227
/// </summary>
@@ -36,7 +41,7 @@ public class NewVersionWindowViewModel : ViewModelBase {
3641
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
3742
/// </summary>
3843
public NewVersionWindowViewModel() {
39-
OpenBrowser = ReactiveCommand.Create(LaunchBrowser);
44+
UpdateSoftware = ReactiveCommand.Create(StartUpdateSoftware);
4045
CloseWindow = ReactiveCommand.Create<Window>(CloseWindowCommand);
4146

4247
Task.Factory.StartNew(async () => {
@@ -69,9 +74,17 @@ public string? ServerVersion {
6974
}
7075

7176
/// <summary>
72-
/// A command to open the browser window at the current update's location.
77+
/// True if updating the application currently, false otherwise.
78+
/// </summary>
79+
public bool IsUpdating {
80+
get => _isUpdating;
81+
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
82+
}
83+
84+
/// <summary>
85+
/// A command to update the software.
7386
/// </summary>
74-
public ICommand OpenBrowser { get; }
87+
public ICommand UpdateSoftware { get; }
7588

7689
/// <summary>
7790
/// A command to close the current window.
@@ -89,7 +102,8 @@ private void CloseWindowCommand(Window self) {
89102
/// <summary>
90103
/// Launches the web browser at the new release page.
91104
/// </summary>
92-
private void LaunchBrowser() {
105+
private void StartUpdateSoftware() {
106+
IsUpdating = true;
93107
GitHubUpdateManager.PrepareUpdate()
94108
.ContinueWith(_ => {
95109
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" Width="200" Height="200"
6+
x:Class="TwitchStreamingTools.Views.Loading">
7+
<UserControl.Styles>
8+
<Style Selector="Rectangle.textColor">
9+
<Setter Property="Fill" Value="rgb(204, 200, 175)" />
10+
<Style.Animations>
11+
<Animation Duration="0:0:1" IterationCount="INFINITE">
12+
<KeyFrame Cue="0%">
13+
<Setter Property="Opacity" Value="0.0" />
14+
<Setter Property="RotateTransform.Angle" Value="0.0" />
15+
</KeyFrame>
16+
<KeyFrame Cue="50%">
17+
<Setter Property="Opacity" Value="1.0" />
18+
<Setter Property="RotateTransform.Angle" Value="90.0" />
19+
</KeyFrame>
20+
<KeyFrame Cue="100%">
21+
<Setter Property="Opacity" Value="0.0" />
22+
<Setter Property="RotateTransform.Angle" Value="180.0" />
23+
</KeyFrame>
24+
</Animation>
25+
</Style.Animations>
26+
</Style>
27+
</UserControl.Styles>
28+
29+
<Rectangle Classes="textColor" Width="50" Height="50" />
30+
</UserControl>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
4+
namespace TwitchStreamingTools.Views;
5+
6+
/// <summary>
7+
/// A loading icon.
8+
/// </summary>
9+
public partial class Loading : UserControl {
10+
/// <summary>
11+
/// The width of the icon.
12+
/// </summary>
13+
public static readonly StyledProperty<int> WidthProperty =
14+
AvaloniaProperty.Register<Loading, int>(nameof(Width), 1);
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="Loading" /> class.
18+
/// </summary>
19+
public Loading() {
20+
InitializeComponent();
21+
}
22+
23+
/// <summary>
24+
/// The width of the icon.
25+
/// </summary>
26+
public int Width {
27+
get => GetValue(WidthProperty);
28+
set => SetValue(WidthProperty, value);
29+
}
30+
}

src/TwitchStreamingTools/Views/NewVersionWindow.axaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
ExtendClientAreaTitleBarHeightHint="-1"
1515
SizeToContent="WidthAndHeight"
1616
Icon="/Assets/update.png"
17-
Title="New Version Available">
17+
Title="New Version Available"
18+
Background="rgb(26, 24, 23)">
1819
<Design.DataContext>
1920
<viewModels:NewVersionWindowViewModel />
2021
</Design.DataContext>
@@ -23,8 +24,9 @@
2324
VerticalAlignment="Stretch"
2425
Name="ContentWrapper">
2526
<views:WindowsTitleBar IsSeamless="True" />
26-
<DockPanel Background="Transparent">
27-
<StackPanel Margin="10">
27+
<StackPanel>
28+
<!-- The normal panel -->
29+
<StackPanel Margin="10" IsVisible="{Binding !IsUpdating}">
2830
<TextBlock TextWrapping="Wrap" Margin="0 0 0 10">There is a new version of the software available, would you like to download it?</TextBlock>
2931
<StackPanel Orientation="Horizontal">
3032
<Label>App Version: </Label>
@@ -35,13 +37,25 @@
3537
<TextBlock Text="{Binding ServerVersion}" HorizontalAlignment="Center" VerticalAlignment="Center" />
3638
</StackPanel>
3739
<StackPanel Orientation="Horizontal">
38-
<Button Command="{Binding OpenBrowser}" Margin="0 10 0 0">Open Browser...</Button>
40+
<Button Command="{Binding UpdateSoftware}" Margin="0 10 0 0">Install New Version</Button>
3941
<Button Command="{Binding CloseWindow}" CommandParameter="{Binding ElementName=Window}"
4042
Margin="10 10 0 0">
4143
Close
4244
</Button>
4345
</StackPanel>
4446
</StackPanel>
45-
</DockPanel>
47+
48+
<!-- The waiting to update display -->
49+
<StackPanel IsVisible="{Binding IsUpdating}">
50+
<Label HorizontalAlignment="Center"
51+
VerticalAlignment="Center"
52+
FontSize="32"
53+
FontWeight="Bold"
54+
Foreground="rgb(204, 200, 175)">
55+
Updating
56+
</Label>
57+
<views:Loading Width="100" Height="100" />
58+
</StackPanel>
59+
</StackPanel>
4660
</DockPanel>
4761
</Window>

0 commit comments

Comments
 (0)