Skip to content

Commit

Permalink
[Auto-update][PT Settings] Updated UI (#11335)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova authored May 18, 2021
1 parent 415b10e commit cdb17f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository,
private string _latestAvailableVersion = string.Empty;
private string _updateCheckedDate = string.Empty;

private bool _isNewVersionDownloading;
private bool _isDownloadButtonClicked;

// Gets or sets a value indicating whether packaged.
public bool Packaged
{
Expand Down Expand Up @@ -452,6 +455,31 @@ private set
}
}

public bool IsNewVersionDownloading
{
get
{
return _isNewVersionDownloading;
}

set
{
if (value != _isNewVersionDownloading)
{
_isNewVersionDownloading = value;
NotifyPropertyChanged();
}
}
}

public bool IsDownloadAllowed
{
get
{
return AutoUpdatesEnabled && !IsNewVersionDownloading;
}
}

public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
Expand All @@ -474,6 +502,10 @@ private void CheckForUpdatesClick()

private void UpdateNowClick()
{
_isDownloadButtonClicked = UpdatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToDownload;
IsNewVersionDownloading = _isDownloadButtonClicked && string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
NotifyPropertyChanged(nameof(IsDownloadAllowed));

Process.Start(new ProcessStartInfo("powertoys://update_now") { UseShellExecute = true });
}

Expand Down Expand Up @@ -505,6 +537,15 @@ public void RefreshUpdatingState()
PowerToysNewAvailableVersion = UpdatingSettingsConfig.NewVersion;
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;

// reset _isDownloadButtonClicked state if the UpdatingState was changed
if (_isDownloadButtonClicked)
{
_isDownloadButtonClicked = UpdatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToDownload;
}

IsNewVersionDownloading = _isDownloadButtonClicked && string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
NotifyPropertyChanged(nameof(IsDownloadAllowed));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1219,4 +1219,10 @@ From there, simply click on a Markdown file or SVG icon in the File Explorer and
<data name="General_IsReadyToInstall.Text" xml:space="preserve">
<value>is ready to install.</value>
</data>
<data name="General_Downloading.Text" xml:space="preserve">
<value>Downloading...</value>
</data>
<data name="General_TryAgainToDownloadAndInstall.Content" xml:space="preserve">
<value>Try again to download and install</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,17 @@
<TextBlock x:Name="General_ReadMore_ReadyToDownload" x:Uid="General_ReadMore" />
</HyperlinkButton>

<TextBlock x:Name="General_Downloading"
x:Uid="General_Downloading"
Visibility="{Binding Mode=OneWay, Path=IsNewVersionDownloading, Converter={StaticResource VisibleIfTrueConverter}}"
Foreground="{Binding AutoUpdatesEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>

<Button x:Uid="General_DownloadAndInstall"
Margin="{StaticResource SmallTopMargin}"
Style="{StaticResource AccentButtonStyle}"
Foreground="White"
Command="{Binding UpdateNowButtonEventHandler}"
IsEnabled="{Binding AutoUpdatesEnabled}"/>
IsEnabled="{Binding IsDownloadAllowed}"/>
</StackPanel>

<StackPanel Visibility="{Binding PowerToysUpdatingState, Converter={StaticResource UpdatingStateReadyToInstallToVisibilityConverter}}">
Expand Down Expand Up @@ -230,11 +235,7 @@
</HyperlinkButton>
</StackPanel>

<HyperlinkButton NavigateUri="{Binding PowerToysNewAvailableVersionLink}" Margin="0,-6,0,0" IsEnabled="{Binding AutoUpdatesEnabled}">
<TextBlock x:Name="General_ReadMore_CannotDownload" x:Uid="General_ReadMore" />
</HyperlinkButton>

<Button x:Uid="General_DownloadAndInstall"
<Button x:Uid="General_TryAgainToDownloadAndInstall"
Margin="{StaticResource SmallTopMargin}"
Style="{StaticResource AccentButtonStyle}"
Foreground="White"
Expand Down

0 comments on commit cdb17f6

Please sign in to comment.