Browse Source

Merge branch 'main' into add-comfyui-package

pull/5/head
Ionite 1 year ago committed by GitHub
parent
commit
801f0245e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 66
      StabilityMatrix/InstallerWindow.xaml
  2. 3
      StabilityMatrix/InstallerWindow.xaml.cs
  3. 11
      StabilityMatrix/PackageManagerPage.xaml
  4. 25
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  5. 6
      StabilityMatrix/ViewModels/OneClickInstallViewModel.cs
  6. 5
      StabilityMatrix/ViewModels/PackageManagerViewModel.cs

66
StabilityMatrix/InstallerWindow.xaml

@ -1,4 +1,4 @@
<ui:FluentWindow <ui:FluentWindow
Background="{DynamicResource ApplicationBackgroundBrush}" Background="{DynamicResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True" ExtendsContentIntoTitleBar="True"
Foreground="{DynamicResource TextFillColorPrimaryBrush}" Foreground="{DynamicResource TextFillColorPrimaryBrush}"
@ -8,6 +8,7 @@
Title="Stability Matrix - Installer" Title="Stability Matrix - Installer"
Width="1100" Width="1100"
WindowBackdropType="Mica" WindowBackdropType="Mica"
WindowStartupLocation="CenterOwner"
d:DataContext="{d:DesignInstance Type=viewModels:InstallerViewModel, d:DataContext="{d:DesignInstance Type=viewModels:InstallerViewModel,
IsDesignTimeCreatable=True}" IsDesignTimeCreatable=True}"
d:DesignHeight="600" d:DesignHeight="600"
@ -34,19 +35,20 @@
</converters:ValueConverterGroup> </converters:ValueConverterGroup>
<converters:BoolNegationConverter x:Key="BoolNegationConverter"/> <converters:BoolNegationConverter x:Key="BoolNegationConverter"/>
<BooleanToVisibilityConverter x:Key="BoolToVisConverter"/>
<xaml:Markdown <xaml:Markdown x:Key="Markdown"
AssetPathRoot="{x:Static system:Environment.CurrentDirectory}"
DocumentStyle="{StaticResource DocumentStyle}" DocumentStyle="{StaticResource DocumentStyle}"
Heading1Style="{StaticResource H1Style}" Heading1Style="{StaticResource H1Style}"
Heading2Style="{StaticResource H2Style}" Heading2Style="{StaticResource H2Style}"
Heading3Style="{StaticResource H3Style}" Heading3Style="{StaticResource H3Style}"
Heading4Style="{StaticResource H4Style}" Heading4Style="{StaticResource H4Style}"
ImageStyle="{StaticResource ImageStyle}"
LinkStyle="{StaticResource LinkStyle}" LinkStyle="{StaticResource LinkStyle}"
ImageStyle="{StaticResource ImageStyle}"
SeparatorStyle="{StaticResource SeparatorStyle}" SeparatorStyle="{StaticResource SeparatorStyle}"
x:Key="Markdown" /> AssetPathRoot="{x:Static system:Environment.CurrentDirectory}"/>
<xaml:TextToFlowDocumentConverter Markdown="{StaticResource Markdown}" x:Key="TextToFlowDocumentConverter" /> <xaml:TextToFlowDocumentConverter x:Key="TextToFlowDocumentConverter"
Markdown="{StaticResource Markdown}"/>
</ui:FluentWindow.Resources> </ui:FluentWindow.Resources>
<Grid> <Grid>
@ -117,19 +119,13 @@
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<StackPanel <StackPanel Grid.Column="1" Orientation="Vertical" Margin="16,16,0,16">
Grid.Column="1" <TextBlock Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}"
Margin="16,16,0,16" FontSize="24" FontWeight="Bold" />
Orientation="Vertical"> <TextBlock Text="{Binding SelectedPackage.ByAuthor, FallbackValue=by Automatic111}"
<TextBlock FontSize="12"/>
FontSize="24" <ui:Hyperlink NavigateUri="{Binding SelectedPackage.GithubUrl}"
FontWeight="Bold" Margin="0,8,0,8">
Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}" />
<TextBlock
FontSize="12"
Margin="0,5,0,5"
Text="{Binding SelectedPackage.ByAuthor, FallbackValue=by Automatic111}" />
<ui:Hyperlink NavigateUri="{Binding SelectedPackage.GithubUrl}">
<TextBlock TextWrapping="Wrap"> <TextBlock TextWrapping="Wrap">
<Run Text="GitHub Page:" /> <Run Text="GitHub Page:" />
<Run Text="{Binding SelectedPackage.GithubUrl, Mode=OneWay}" TextDecorations="Underline" /> <Run Text="{Binding SelectedPackage.GithubUrl, Mode=OneWay}" TextDecorations="Underline" />
@ -191,19 +187,35 @@
</StackPanel> </StackPanel>
<Label Content="Install Location" Margin="0,16,0,0"/> <Label Content="Install Location" Margin="0,16,0,0"/>
<ui:TextBox Margin="0,0,0,8" Text="{Binding InstallPath}" /> <ui:TextBox Text="{Binding InstallPath, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,0,8"/>
<Label Content="Display Name" Margin="0,16,0,0"/> <Label Content="Display Name" Margin="0,16,0,0"/>
<ui:TextBox Margin="0,0,0,8" Text="{Binding InstallName}" /> <StackPanel Orientation="Horizontal"
Visibility="{Binding ShowDuplicateWarning,
Converter={StaticResource BoolToVisConverter}}">
<ui:SymbolIcon Symbol="ErrorCircle24"
Margin="8"
Foreground="{ui:ThemeResource SystemFillColorCriticalBrush}"/>
<TextBlock TextAlignment="Left"
Margin="0,8,8,8"
Foreground="{ui:ThemeResource SystemFillColorCriticalBrush}"
TextWrapping="Wrap">
<Run Text="An installation with this name already exists."/>
<LineBreak/><Run Text="Please choose a different name or select a different Install Location."/>
</TextBlock>
</StackPanel>
<ui:TextBox Text="{Binding InstallName, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,0,8"/>
<ui:Button <ui:Button Content="{Binding InstallButtonText, FallbackValue=Install}"
Appearance="Success"
Command="{Binding InstallCommand}" Command="{Binding InstallCommand}"
Content="{Binding InstallButtonText, FallbackValue=Install}" IsEnabled="{Binding ShowDuplicateWarning,
Height="50" Converter={StaticResource BoolNegationConverter}}"
Width="100" Height="50"
Background="Green"
Margin="0,16,0,0" Margin="0,16,0,0"
VerticalAlignment="Top" VerticalAlignment="Top" />
Width="100" />
</StackPanel> </StackPanel>
<FlowDocumentScrollViewer <FlowDocumentScrollViewer
Document="{Binding ReleaseNotes, Converter={StaticResource TextToFlowDocumentConverter}}" Document="{Binding ReleaseNotes, Converter={StaticResource TextToFlowDocumentConverter}}"

3
StabilityMatrix/InstallerWindow.xaml.cs

@ -1,4 +1,6 @@
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using StabilityMatrix.ViewModels; using StabilityMatrix.ViewModels;
using Wpf.Ui.Controls.Window; using Wpf.Ui.Controls.Window;
@ -19,6 +21,7 @@ namespace StabilityMatrix
this.viewModel = viewModel; this.viewModel = viewModel;
InitializeComponent(); InitializeComponent();
DataContext = viewModel; DataContext = viewModel;
viewModel.PackageInstalled += (_, _) => Close();
} }
private async void InstallPage_OnLoaded(object sender, RoutedEventArgs e) private async void InstallPage_OnLoaded(object sender, RoutedEventArgs e)

11
StabilityMatrix/PackageManagerPage.xaml

@ -16,6 +16,10 @@
xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels" xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisConverter"/>
</Page.Resources>
<Grid Margin="16"> <Grid Margin="16">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -128,6 +132,13 @@
Visibility="{Binding InstallButtonVisibility, FallbackValue=Visible}" Visibility="{Binding InstallButtonVisibility, FallbackValue=Visible}"
Width="100" /> Width="100" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsUninstalling,
Converter={StaticResource BoolToVisConverter}}">
<ui:ProgressRing Height="24" Width="24" Margin="8, 16, 8, 8"
VerticalAlignment="Center"
IsIndeterminate="True" HorizontalAlignment="Left"/>
<TextBlock Text="Uninstalling..." VerticalAlignment="Center" Margin="0,8,0,0"/>
</StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Grid> </Grid>

25
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@ -72,10 +73,15 @@ public partial class InstallerViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
private bool isReleaseModeEnabled; private bool isReleaseModeEnabled;
[ObservableProperty]
private bool showDuplicateWarning;
public Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed; public Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed;
public string ReleaseLabelText => IsReleaseMode ? "Version" : "Branch"; public string ReleaseLabelText => IsReleaseMode ? "Version" : "Branch";
internal event EventHandler? PackageInstalled;
public InstallerViewModel(ISettingsManager settingsManager, ILogger<InstallerViewModel> logger, IPyRunner pyRunner, public InstallerViewModel(ISettingsManager settingsManager, ILogger<InstallerViewModel> logger, IPyRunner pyRunner,
IPackageFactory packageFactory) IPackageFactory packageFactory)
@ -104,6 +110,7 @@ public partial class InstallerViewModel : ObservableObject
private async Task Install() private async Task Install()
{ {
await ActuallyInstall(); await ActuallyInstall();
OnPackageInstalled();
} }
public async Task OnLoaded() public async Task OnLoaded()
@ -134,7 +141,7 @@ public partial class InstallerViewModel : ObservableObject
ReleaseNotes = string.Empty; ReleaseNotes = string.Empty;
AvailableVersions?.Clear(); AvailableVersions?.Clear();
// This can swallow exceptions if you don't explicity try/catch // This can swallow exceptions if you don't explicitly try/catch
// Idk how to make it better tho // Idk how to make it better tho
Task.Run(async () => Task.Run(async () =>
{ {
@ -182,6 +189,18 @@ public partial class InstallerViewModel : ObservableObject
OnSelectedPackageChanged(SelectedPackage); OnSelectedPackageChanged(SelectedPackage);
} }
partial void OnInstallNameChanged(string oldValue, string newValue)
{
var path = Path.GetFullPath($"{InstallPath}\\{newValue}");
ShowDuplicateWarning = settingsManager.Settings.InstalledPackages.Any(p => p.Path.Equals(path));
}
partial void OnInstallPathChanged(string oldValue, string newValue)
{
var path = Path.GetFullPath($"{newValue}\\{InstallName}");
ShowDuplicateWarning = settingsManager.Settings.InstalledPackages.Any(p => p.Path.Equals(path));
}
partial void OnSelectedVersionChanged(PackageVersion? value) partial void OnSelectedVersionChanged(PackageVersion? value)
{ {
ReleaseNotes = value?.ReleaseNotesMarkdown ?? string.Empty; ReleaseNotes = value?.ReleaseNotesMarkdown ?? string.Empty;
@ -255,6 +274,8 @@ public partial class InstallerViewModel : ObservableObject
}; };
settingsManager.AddInstalledPackage(package); settingsManager.AddInstalledPackage(package);
settingsManager.SetActiveInstalledPackage(package); settingsManager.SetActiveInstalledPackage(package);
ProgressValue = 0;
} }
private Task<string?> DownloadPackage(string version) private Task<string?> DownloadPackage(string version)
@ -314,4 +335,6 @@ public partial class InstallerViewModel : ObservableObject
EventManager.Instance.OnGlobalProgressChanged(progress); EventManager.Instance.OnGlobalProgressChanged(progress);
} }
private void OnPackageInstalled() => PackageInstalled?.Invoke(this, EventArgs.Empty);
} }

6
StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

@ -41,9 +41,11 @@ public partial class OneClickInstallViewModel : ObservableObject
this.logger = logger; this.logger = logger;
this.pyRunner = pyRunner; this.pyRunner = pyRunner;
HeaderText = "Click the Install button below to get started!"; HeaderText = "Welcome to Stability Matrix!";
SubHeaderText = SubHeaderText =
"This will install the latest version of Stable Diffusion WebUI by Automatic1111.\nIf you don't know what this means, don't worry, you'll be generating images soon!"; "Click the Install button below to get started!\n" +
"This will install the latest version of Stable Diffusion WebUI by Automatic1111.\n" +
"If you don't know what this means, don't worry, you'll be generating images soon!";
ShowInstallButton = true; ShowInstallButton = true;
} }

5
StabilityMatrix/ViewModels/PackageManagerViewModel.cs

@ -50,6 +50,9 @@ public partial class PackageManagerViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
private Visibility installButtonVisibility; private Visibility installButtonVisibility;
[ObservableProperty]
private bool isUninstalling;
[ObservableProperty] [ObservableProperty]
[NotifyPropertyChangedFor(nameof(SelectedPackage))] [NotifyPropertyChangedFor(nameof(SelectedPackage))]
private bool updateAvailable; private bool updateAvailable;
@ -170,6 +173,7 @@ public partial class PackageManagerViewModel : ObservableObject
if (result == ContentDialogResult.Primary) if (result == ContentDialogResult.Primary)
{ {
IsUninstalling = true;
var deleteTask = DeleteDirectoryAsync(SelectedPackage.Path); var deleteTask = DeleteDirectoryAsync(SelectedPackage.Path);
var taskResult = await dialogErrorHandler.TryAsync(deleteTask, var taskResult = await dialogErrorHandler.TryAsync(deleteTask,
"Some files could not be deleted. Please close any open files in the package directory and try again."); "Some files could not be deleted. Please close any open files in the package directory and try again.");
@ -178,6 +182,7 @@ public partial class PackageManagerViewModel : ObservableObject
settingsManager.RemoveInstalledPackage(SelectedPackage); settingsManager.RemoveInstalledPackage(SelectedPackage);
} }
await OnLoaded(); await OnLoaded();
IsUninstalling = false;
} }
} }

Loading…
Cancel
Save