Skip to content

Commit

Permalink
added uninstall port button
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfds committed Sep 24, 2024
1 parent 15aa240 commit 3b3b9f2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
7 changes: 4 additions & 3 deletions src/Avalonia.Desktop/Controls/PortControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@

<Button Height="{Binding #InstallButton.Bounds.Height}"
Grid.Column="1"
Command="{Binding CheckUpdateCommand}"
Command="{Binding UninstallCommand}"
Margin="5"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
ToolTip.Tip="Check for updates">
<i:Icon Value="fa-sync" />
IsEnabled="{Binding IsInstalled}"
ToolTip.Tip="Uninstall">
<i:Icon Value="fa-trash" />
</Button>

</Grid>
Expand Down
66 changes: 43 additions & 23 deletions src/Avalonia.Desktop/ViewModels/PortViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ out var newVersion
/// </summary>
public string Version => _port.InstalledVersion ?? "None";

/// <summary>
/// Is port installed
/// </summary>
public bool IsInstalled => _port.IsInstalled;

/// <summary>
/// Latest available version
/// </summary>
Expand All @@ -122,7 +127,7 @@ out var newVersion

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(InstallCommand))]
[NotifyCanExecuteChangedFor(nameof(CheckUpdateCommand))]
[NotifyCanExecuteChangedFor(nameof(UninstallCommand))]
private bool _isInProgress;

#endregion
Expand All @@ -140,6 +145,7 @@ public async Task InitializeAsync()
OnPropertyChanged(nameof(LatestVersion));
OnPropertyChanged(nameof(InstallButtonText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(IsInstalled));
}


Expand All @@ -149,25 +155,33 @@ public async Task InitializeAsync()
[RelayCommand(CanExecute = nameof(InstallCommandCanExecute))]
private async Task InstallAsync()
{
IsInProgress = true;
try
{
IsInProgress = true;

var installer = _installerFactory.Create();
var installer = _installerFactory.Create();

installer.Progress.ProgressChanged += OnProgressChanged;
ProgressBarValue = 0;
OnPropertyChanged(nameof(ProgressBarValue));
installer.Progress.ProgressChanged += OnProgressChanged;
ProgressBarValue = 0;
OnPropertyChanged(nameof(ProgressBarValue));

await installer.InstallAsync(_port);
await installer.InstallAsync(_port);

installer.Progress.ProgressChanged -= OnProgressChanged;
ProgressBarValue = 0;
installer.Progress.ProgressChanged -= OnProgressChanged;
ProgressBarValue = 0;

OnPropertyChanged(nameof(ProgressBarValue));
OnPropertyChanged(nameof(Version));
OnPropertyChanged(nameof(InstallButtonText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(ProgressBarValue));
OnPropertyChanged(nameof(Version));
OnPropertyChanged(nameof(InstallButtonText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(IsInstalled));

IsInProgress = false;
UninstallCommand.NotifyCanExecuteChanged();
}
finally
{
IsInProgress = false;
}
}
public bool InstallCommandCanExecute() => !IsInProgress;

Expand All @@ -176,19 +190,25 @@ private async Task InstallAsync()
/// Force check for updates
/// </summary>
[RelayCommand(CanExecute = nameof(CheckUpdateCommandCanExecute))]
private async Task CheckUpdateAsync()
private void Uninstall()
{
IsInProgress = true;

_release = await _portsReleasesProvider.GetLatestReleaseAsync(_port.PortEnum);
try
{
IsInProgress = true;

OnPropertyChanged(nameof(LatestVersion));
OnPropertyChanged(nameof(InstallButtonText));
OnPropertyChanged(nameof(IsUpdateAvailable));
Directory.Delete(_port.PathToExecutableFolder, true);

IsInProgress = false;
OnPropertyChanged(nameof(Version));
OnPropertyChanged(nameof(InstallButtonText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(IsInstalled));
}
finally
{
IsInProgress = false;
}
}
public bool CheckUpdateCommandCanExecute() => !IsInProgress;
public bool CheckUpdateCommandCanExecute() => IsInstalled;


#endregion
Expand Down

0 comments on commit 3b3b9f2

Please sign in to comment.