Skip to content

Commit

Permalink
feat: show startup download progress in status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Nov 18, 2024
1 parent c2e1169 commit a609abb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Hearthstone Deck Tracker/Utility/Updating/Updater.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static async void CheckForUpdates(bool force = false)
_release = await GetLatestRelease(false);
if(_release != null)
{
StatusBar.Visibility = Visibility.Visible;
Status.UpdaterState = UpdaterState.Available;
Status.StatusBarVisibility = Visibility.Visible;
ShowNewUpdateMessage(false);
}
else if(Config.Instance.CheckForBetaUpdates)
Expand Down
15 changes: 10 additions & 5 deletions Hearthstone Deck Tracker/Utility/Updating/Updater.Squirrel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public static async void CheckForUpdates(bool force = false)
if(updated)
{
_updateCheckDelay = new TimeSpan(1, 0, 0);
Status.Visibility = Visibility.Visible;
Status.StatusBarVisibility = Visibility.Visible;
}
}
catch(Exception ex)
{
Status.OnFailed(ex);
Log.Error(ex);
}
}
Expand Down Expand Up @@ -140,7 +141,7 @@ async Task<bool> Update(bool dev)
if(Status.SkipStartupCheck)
{
Log.Info("Update complete, showing update bar");
Status.Visibility = Visibility.Visible;
Status.StatusBarVisibility = Visibility.Visible;
}
else
{
Expand All @@ -151,6 +152,7 @@ async Task<bool> Update(bool dev)
}
catch(Exception ex)
{
Status.OnFailed(ex);
Log.Error(ex);
}
}
Expand Down Expand Up @@ -278,7 +280,7 @@ await mgr.ApplyReleases(updateInfo,
}

await mgr.CreateUninstallerRegistryEntry();
Status.UpdaterState = UpdaterState.Installed;
Status.OnInstalled();
Log.Info("Done");
return true;
}
Expand All @@ -289,16 +291,19 @@ await mgr.ApplyReleases(updateInfo,
{
_useChinaMirror = true;
Log.Warn("Now using china mirror");
return await SquirrelUpdate(mgr, isStartupCheck,
ignoreDelta);
return await SquirrelUpdate(mgr, isStartupCheck, ignoreDelta);
}

Status.OnFailed(ex);
return false;
}
catch(Exception ex)
{
if(ignoreDelta)
{
Status.OnFailed(ex);
return false;
}
if(ex is Win32Exception)
Log.Info(
"Not able to apply deltas, downloading full release");
Expand Down
43 changes: 39 additions & 4 deletions Hearthstone Deck Tracker/Utility/Updating/UpdaterStatus.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
using System;
using System.Windows;
using Hearthstone_Deck_Tracker.Utility.MVVM;
using static System.Windows.Visibility;

namespace Hearthstone_Deck_Tracker.Utility.Updating;

public class UpdaterStatus : ViewModel
{
public Visibility Visibility
public Visibility StatusBarVisibility
{
get => GetProp(Visibility.Collapsed);
get => GetProp(Collapsed);
set => SetProp(value);
}

public Visibility DownloadingUpdateVisibility => UpdaterState == UpdaterState.Downloading ? Visible : Collapsed;
public Visibility InstallingUpdateVisibility => UpdaterState == UpdaterState.Installing ? Visible : Collapsed;
public Visibility UpdateInstalledVisibility => UpdaterState == UpdaterState.Available ? Visible : Collapsed;
public Visibility UpdateFailedVisibility => UpdaterState == UpdaterState.Failed ? Visible : Collapsed;

public UpdaterState UpdaterState
{
get => GetProp(UpdaterState.None);
set => SetProp(value);
set
{
SetProp(value);
OnPropertyChanged(nameof(DownloadingUpdateVisibility));
OnPropertyChanged(nameof(InstallingUpdateVisibility));
OnPropertyChanged(nameof(UpdateInstalledVisibility));
OnPropertyChanged(nameof(UpdateFailedVisibility));
}
}

public int UpdateProgress
Expand All @@ -33,12 +47,32 @@ public void OnDownloadProgressChanged(int progress)
{
UpdaterState = UpdaterState.Downloading;
UpdateProgress = progress;

if(SkipStartupCheck)
StatusBarVisibility = Visible;
}

public void OnInstallProgressChanged(int progress)
{
UpdaterState = UpdaterState.Installing;
UpdateProgress = progress;

if(SkipStartupCheck)
StatusBarVisibility = Visible;
}

public void OnInstalled()
{
UpdaterState = UpdaterState.Available;
StatusBarVisibility = Visible;
}

public void OnFailed(Exception ex)
{
// We might want special handling for specific exceptions in the future?

UpdaterState = UpdaterState.Failed;
StatusBarVisibility = Visible;
}
}

Expand All @@ -48,5 +82,6 @@ public enum UpdaterState
Checking,
Downloading,
Installing,
Installed
Available,
Failed
}
50 changes: 39 additions & 11 deletions Hearthstone Deck Tracker/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,45 @@
IsChecked="{Binding CheckForDevUpdates, Source={StaticResource ConfigWrapper}}" />
</StatusBarItem>
</StatusBar>
<StatusBar Name="StatusBarUpdate" DockPanel.Dock="Top" Margin="0,1,0,0" Visibility="{Binding Visibility, Source={x:Static utility:Updater.Status}}">
<StatusBarItem Margin="10,0,0,0" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run FontWeight="SemiBold" Text="{lex:LocTextUpper MainWindow_StatusBarUpdate_NewUpdateAvailable}"/>
<Run FontWeight="SemiBold">-</Run>
<Hyperlink Foreground="White" FontWeight="Bold" Click="HyperlinkUpdateNow_OnClick">
<Run Text="{lex:LocTextUpper MainWindow_StatusBarUpdate_ClickToUpdate}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
<StatusBar DataContext="{x:Static utility:Updater.Status}" DockPanel.Dock="Top" Margin="1,1,1,0" Visibility="{Binding StatusBarVisibility}" Background="{DynamicResource AccentBaseColorBrush}">
<StatusBarItem Margin="0,5,0,5" HorizontalAlignment="Center">
<Grid>
<StackPanel Orientation="Horizontal" Visibility="{Binding DownloadingUpdateVisibility}">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run FontWeight="SemiBold" Text="{lex:Loc MainWindow_StatusBarUpdate_Downloading}"/>
<Run FontWeight="SemiBold" Text="{Binding UpdateProgress, StringFormat='{}{0}%'}"/>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding InstallingUpdateVisibility}">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run FontWeight="SemiBold" Text="{lex:Loc MainWindow_StatusBarUpdate_Installing}"/>
<Run FontWeight="SemiBold" Text="{Binding UpdateProgress, StringFormat='{}{0}%'}"/>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding UpdateInstalledVisibility}">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run FontWeight="SemiBold" Text="{lex:LocTextUpper MainWindow_StatusBarUpdate_NewUpdateAvailable}"/>
<Run FontWeight="SemiBold">-</Run>
<Hyperlink Foreground="White" FontWeight="Bold" Click="HyperlinkUpdateNow_OnClick">
<Run Text="{lex:LocTextUpper MainWindow_StatusBarUpdate_ClickToUpdate}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding UpdateFailedVisibility}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_warning}" />
</Rectangle.Fill>
</Rectangle>
<TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,0,0">
<Run FontWeight="SemiBold" Text="{lex:Loc MainWindow_StatusBarUpdate_UpdateFailed}"/>
<Run FontWeight="SemiBold">-</Run>
<Hyperlink Foreground="White" FontWeight="Bold" Command="{Binding OpenUrl, Source={StaticResource GlobalCommands}}" CommandParameter="https://hsreplay.net/downloads">
<Run Text="{lex:Loc MainWindow_StatusBarUpdate_UpdateFailed_Download}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
</StatusBarItem>
</StatusBar>
<mainWindowControls:NewsBarView x:Name="NewsBar" DockPanel.Dock="Top"/>
Expand Down

0 comments on commit a609abb

Please sign in to comment.