Browse Source

Use new console progress dialog for package updates

pull/137/head
JT 1 year ago
parent
commit
455ad05ba2
  1. 6
      CHANGELOG.md
  2. 21
      StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs
  3. 67
      StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs
  4. 2
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  5. 5
      StabilityMatrix.Avalonia/ViewModels/Progress/ProgressManagerViewModel.cs
  6. 1
      StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs
  7. 9
      StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs
  8. 47
      StabilityMatrix.Core/Models/PackageModification/UpdatePackageStep.cs
  9. 7
      StabilityMatrix.Core/Models/Packages/A3WebUI.cs

6
CHANGELOG.md

@ -5,6 +5,12 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
## v2.4.3
### Added
- Added "--no-download-sd-model" launch argument option for Stable Diffusion Web UI
### Changed
- Package updates now use the new progress dialog with console output
## v2.4.2
### Added
- Added Japanese UI language option, thanks to kgmkm_mkgm for the translation

21
StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs

@ -62,9 +62,6 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
[ObservableProperty]
private string? releaseNotes;
[ObservableProperty]
private string latestVersionText = string.Empty;
[ObservableProperty]
private bool isAdvancedMode;
@ -97,6 +94,10 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
private PackageVersionType availableVersionTypes =
PackageVersionType.GithubRelease | PackageVersionType.Commit;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanInstall))]
private bool isLoading;
public string ReleaseLabelText =>
IsReleaseMode ? Resources.Label_Version : Resources.Label_Branch;
public bool IsReleaseMode
@ -111,7 +112,8 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
AvailableVersionTypes.HasFlag(PackageVersionType.GithubRelease);
public bool ShowTorchVersionOptions => SelectedTorchVersion != TorchVersion.None;
public bool CanInstall => !string.IsNullOrWhiteSpace(InstallName) && !ShowDuplicateWarning;
public bool CanInstall =>
!string.IsNullOrWhiteSpace(InstallName) && !ShowDuplicateWarning && !IsLoading;
public ProgressViewModel InstallProgress { get; } = new();
public IEnumerable<IPackageStep> Steps { get; set; }
@ -153,6 +155,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
// Check for updates
try
{
IsLoading = true;
var versionOptions = await SelectedPackage.GetAllVersionOptions();
if (IsReleaseMode)
{
@ -178,6 +181,10 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
{
Logger.Warn("Error getting versions: {Exception}", e.ToString());
}
finally
{
IsLoading = false;
}
}
[RelayCommand]
@ -357,6 +364,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
partial void OnSelectedPackageChanged(BasePackage value)
{
IsLoading = true;
ReleaseNotes = string.Empty;
AvailableVersions?.Clear();
AvailableCommits?.Clear();
@ -398,9 +406,8 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
}
InstallName = SelectedPackage.DisplayName;
LatestVersionText = IsReleaseMode
? $"Latest version: {SelectedVersion?.TagName}"
: $"Branch: {SelectedVersion?.TagName}";
IsLoading = false;
})
.SafeFireAndForget();
}

67
StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

@ -18,6 +18,7 @@ using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.PackageModification;
using StabilityMatrix.Core.Models.Packages;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
@ -181,61 +182,25 @@ public partial class PackageCardViewModel : ProgressViewModel
Text = $"Updating {packageName}";
IsIndeterminate = true;
var progressId = Guid.NewGuid();
EventManager.Instance.OnProgressChanged(
new ProgressItem(
progressId,
Package.DisplayName ?? Package.PackageName!,
new ProgressReport(0f, isIndeterminate: true, type: ProgressType.Update)
)
);
try
{
var progress = new Progress<ProgressReport>(progress =>
var runner = new PackageModificationRunner
{
var percent = Convert.ToInt32(progress.Percentage);
Value = percent;
IsIndeterminate = progress.IsIndeterminate;
Text = string.Format(Resources.TextTemplate_UpdatingPackage, packageName);
EventManager.Instance.OnGlobalProgressChanged(percent);
EventManager.Instance.OnProgressChanged(
new ProgressItem(progressId, packageName, progress)
);
});
ModificationCompleteMessage = $"{packageName} Update Complete"
};
var updatePackageStep = new UpdatePackageStep(settingsManager, Package, basePackage);
var steps = new List<IPackageStep> { updatePackageStep };
var torchVersion =
Package.PreferredTorchVersion ?? basePackage.GetRecommendedTorchVersion();
EventManager.Instance.OnPackageInstallProgressAdded(runner);
await runner.ExecuteSteps(steps);
var updateResult = await basePackage.Update(Package, torchVersion, progress);
settingsManager.UpdatePackageVersionNumber(Package.Id, updateResult);
IsUpdateAvailable = false;
InstalledVersion = Package.Version?.DisplayVersion ?? "Unknown";
notificationService.Show(
Resources.Progress_UpdateComplete,
string.Format(Resources.TextTemplate_PackageUpdatedToLatest, packageName),
NotificationType.Success
);
await using (settingsManager.BeginTransaction())
{
Package.UpdateAvailable = false;
}
IsUpdateAvailable = false;
InstalledVersion = updateResult.DisplayVersion ?? "Unknown";
EventManager.Instance.OnProgressChanged(
new ProgressItem(
progressId,
packageName,
new ProgressReport(
1f,
Resources.Progress_UpdateComplete,
type: ProgressType.Update
)
)
);
}
catch (Exception e)
{
@ -245,18 +210,6 @@ public partial class PackageCardViewModel : ProgressViewModel
e.Message,
NotificationType.Error
);
EventManager.Instance.OnProgressChanged(
new ProgressItem(
progressId,
packageName,
new ProgressReport(
0f,
Resources.Progress_UpdateFailed,
type: ProgressType.Update
),
Failed: true
)
);
}
finally
{

2
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -138,7 +138,7 @@ public partial class PackageManagerViewModel : PageViewModelBase
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
var runner = new PackageModificationRunner();
var runner = new PackageModificationRunner { ShowDialogOnStart = true };
var steps = viewModel.Steps;
EventManager.Instance.OnPackageInstallProgressAdded(runner);

5
StabilityMatrix.Avalonia/ViewModels/Progress/ProgressManagerViewModel.cs

@ -129,7 +129,10 @@ public partial class ProgressManagerViewModel : PageViewModelBase
var vm = new PackageInstallProgressItemViewModel(packageModificationRunner);
ProgressItems.Add(vm);
await vm.ShowProgressDialog();
if (packageModificationRunner.ShowDialogOnStart)
{
await vm.ShowProgressDialog();
}
}
private void ShowFailedNotification(string title, string message)

1
StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs

@ -11,4 +11,5 @@ public interface IPackageModificationRunner
event EventHandler<ProgressReport>? ProgressChanged;
List<string> ConsoleOutput { get; }
Guid Id { get; }
bool ShowDialogOnStart { get; init; }
}

9
StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs

@ -25,12 +25,19 @@ public class PackageModificationRunner : IPackageModificationRunner
}
progress.Report(
new ProgressReport(1f, message: "Package Install Complete", isIndeterminate: false)
new ProgressReport(
1f,
message: ModificationCompleteMessage ?? "Package Install Complete",
isIndeterminate: false
)
);
IsRunning = false;
}
public string? ModificationCompleteMessage { get; init; }
public bool ShowDialogOnStart { get; init; }
public bool IsRunning { get; set; }
public ProgressReport CurrentProgress { get; set; }
public IPackageStep? CurrentStep { get; set; }

47
StabilityMatrix.Core/Models/PackageModification/UpdatePackageStep.cs

@ -0,0 +1,47 @@
using StabilityMatrix.Core.Models.Packages;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Core.Models.PackageModification;
public class UpdatePackageStep : IPackageStep
{
private readonly ISettingsManager settingsManager;
private readonly InstalledPackage installedPackage;
private readonly BasePackage basePackage;
public UpdatePackageStep(
ISettingsManager settingsManager,
InstalledPackage installedPackage,
BasePackage basePackage
)
{
this.settingsManager = settingsManager;
this.installedPackage = installedPackage;
this.basePackage = basePackage;
}
public async Task ExecuteAsync(IProgress<ProgressReport>? progress = null)
{
var torchVersion =
installedPackage.PreferredTorchVersion ?? basePackage.GetRecommendedTorchVersion();
void OnConsoleOutput(ProcessOutput output)
{
progress?.Report(new ProgressReport { IsIndeterminate = true, Message = output.Text });
}
var updateResult = await basePackage
.Update(installedPackage, torchVersion, progress, onConsoleOutput: OnConsoleOutput)
.ConfigureAwait(false);
settingsManager.UpdatePackageVersionNumber(installedPackage.Id, updateResult);
await using (settingsManager.BeginTransaction())
{
installedPackage.UpdateAvailable = false;
}
}
public string ProgressTitle => $"Updating {installedPackage.DisplayName}";
}

7
StabilityMatrix.Core/Models/Packages/A3WebUI.cs

@ -134,6 +134,13 @@ public class A3WebUI : BaseGitPackage
InitialValue = HardwareHelper.HasAmdGpu(),
Options = new() { "--no-half" }
},
new()
{
Name = "Skip SD Model Download",
Type = LaunchOptionType.Bool,
InitialValue = false,
Options = new() { "--no-download-sd-model" }
},
LaunchOptionDefinition.Extras
};

Loading…
Cancel
Save