Browse Source

Merge branch 'main' into add-py-version-settings

pull/5/head
JT 2 years ago committed by GitHub
parent
commit
a09aca91ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      StabilityMatrix/Api/IGithubApi.cs
  2. 4
      StabilityMatrix/App.xaml.cs
  3. 2
      StabilityMatrix/Helper/SettingsManager.cs
  4. 2
      StabilityMatrix/LaunchPage.xaml
  5. 96
      StabilityMatrix/MainWindow.xaml
  6. 27
      StabilityMatrix/MainWindow.xaml.cs
  7. 9
      StabilityMatrix/Models/Api/GithubRelease.cs
  8. 14
      StabilityMatrix/Models/BasePackage.cs
  9. 45
      StabilityMatrix/Models/Packages/A3WebUI.cs
  10. 10
      StabilityMatrix/Models/Packages/DankDiffusion.cs
  11. 2
      StabilityMatrix/StabilityMatrix.csproj
  12. 2
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  13. 50
      StabilityMatrix/ViewModels/MainWindowViewModel.cs
  14. 8
      StabilityMatrix/ViewModels/SettingsViewModel.cs

12
StabilityMatrix/Api/IGithubApi.cs

@ -0,0 +1,12 @@
using System.Threading.Tasks;
using Refit;
using StabilityMatrix.Models.Api;
namespace StabilityMatrix.Api;
[Headers("User-Agent: StabilityMatrix")]
public interface IGithubApi
{
[Get("/repos/{username}/{repository}/releases/latest")]
Task<GithubRelease> GetLatestRelease(string username, string repository);
}

4
StabilityMatrix/App.xaml.cs

@ -1,5 +1,7 @@
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Refit;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
using StabilityMatrix.Services;
using StabilityMatrix.ViewModels;
@ -21,9 +23,11 @@ namespace StabilityMatrix
serviceCollection.AddTransient<SettingsPage>();
serviceCollection.AddTransient<LaunchPage>();
serviceCollection.AddTransient<InstallPage>();
serviceCollection.AddTransient<MainWindowViewModel>();
serviceCollection.AddSingleton<SettingsViewModel>();
serviceCollection.AddSingleton<IContentDialogService, ContentDialogService>();
serviceCollection.AddSingleton<ISettingsManager, SettingsManager>();
serviceCollection.AddRefitClient<IGithubApi>();
var provider = serviceCollection.BuildServiceProvider();
var window = provider.GetRequiredService<MainWindow>();

2
StabilityMatrix/Helper/SettingsManager.cs

@ -28,6 +28,8 @@ public class SettingsManager : ISettingsManager
}
LoadSettings();
}
public void SetTheme(string theme)

2
StabilityMatrix/LaunchPage.xaml

@ -5,6 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:StabilityMatrix"
Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d"
Title="LaunchPage" d:DesignHeight="700" d:DesignWidth="1100">
<Grid>

96
StabilityMatrix/MainWindow.xaml

@ -1,59 +1,65 @@
<ui:FluentWindow x:Class="StabilityMatrix.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StabilityMatrix"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
Loaded="MainWindow_OnLoaded"
Title="Stability Matrix" Height="700" Width="1100">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StabilityMatrix"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
Loaded="MainWindow_OnLoaded"
Title="Stability Matrix" Height="700" Width="1100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ui:TitleBar Foreground="White" Background="#191919">
<ui:TitleBar.Header>
<TextBlock Text="Stability Matrix" Margin="16,8" />
</ui:TitleBar.Header>
</ui:TitleBar>
<ui:NavigationView
Grid.Row="1" x:Name="RootNavigation"
IsBackButtonVisible="Collapsed">
<ui:NavigationView.Header>
<ui:BreadcrumbBar
Margin="42,32,0,0"
FontSize="28"
FontWeight="DemiBold" />
</ui:NavigationView.Header>
<ui:NavigationView.MenuItems>
<ui:NavigationViewItem Content="Launch" IsActive="true" TargetPageType="{x:Type local:LaunchPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Rocket24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="Install" TargetPageType="{x:Type local:InstallPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Wrench24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.MenuItems>
<ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem Content="Settings" TargetPageType="{x:Type local:SettingsPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Settings24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.FooterMenuItems>
</ui:NavigationView>
<Grid Grid.Row="1" Visibility="{Binding AdvancedModeVisibility, FallbackValue=Visible}">
<ui:NavigationView x:Name="RootNavigation"
IsBackButtonVisible="Collapsed">
<ui:NavigationView.Header>
<ui:BreadcrumbBar
Margin="42,32,0,16"
FontSize="28"
FontWeight="DemiBold" />
</ui:NavigationView.Header>
<ui:NavigationView.MenuItems>
<ui:NavigationViewItem Content="Launch" IsActive="true" TargetPageType="{x:Type local:LaunchPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Rocket24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="Install" TargetPageType="{x:Type local:InstallPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Wrench24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.MenuItems>
<ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem Content="Settings" TargetPageType="{x:Type local:SettingsPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Settings24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.FooterMenuItems>
</ui:NavigationView>
</Grid>
<Grid Grid.Row="1" Visibility="{Binding SimpleModeVisibility, FallbackValue=Hidden}">
<ui:Button Content="Install" HorizontalAlignment="Center" FontSize="36" Padding="16"/>
<Button Content="Advanced Options" HorizontalAlignment="Center"
Background="Transparent"
Command="{Binding GoAdvancedModeCommand}"
VerticalAlignment="Bottom" Margin="16" FontSize="14"/>
</Grid>
<ContentPresenter x:Name="RootContentDialog" Grid.Row="1" />
</Grid>
</ui:FluentWindow>

27
StabilityMatrix/MainWindow.xaml.cs

@ -1,7 +1,6 @@
using System.Diagnostics;
using System.Windows;
using StabilityMatrix.Helper;
using Wpf.Ui.Appearance;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.Navigation;
using Wpf.Ui.Controls.Window;
@ -16,15 +15,20 @@ namespace StabilityMatrix
private readonly IPageService pageService;
private readonly ISettingsManager settingsManager;
private readonly IContentDialogService contentDialogService;
private readonly MainWindowViewModel mainWindowViewModel;
public MainWindow(IPageService pageService, ISettingsManager settingsManager, IContentDialogService contentDialogService)
public MainWindow(IPageService pageService, ISettingsManager settingsManager,
IContentDialogService contentDialogService, MainWindowViewModel mainWindowViewModel)
{
InitializeComponent();
this.pageService = pageService;
this.settingsManager = settingsManager;
this.contentDialogService = contentDialogService;
this.mainWindowViewModel = mainWindowViewModel;
DataContext = mainWindowViewModel;
RootNavigation.Navigating += (_, _) => Debug.WriteLine("Navigating");
RootNavigation.SetPageService(pageService);
@ -33,22 +37,9 @@ namespace StabilityMatrix
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
SetTheme();
RootNavigation.Navigate(typeof(LaunchPage));
mainWindowViewModel.OnLoaded();
}
private void SetTheme()
{
var theme = settingsManager.Settings.Theme;
switch (theme)
{
case "Dark":
Theme.Apply(ThemeType.Dark);
break;
case "Light":
Theme.Apply(ThemeType.Light);
break;
}
}
}
}

9
StabilityMatrix/Models/Api/GithubRelease.cs

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class GithubRelease
{
[JsonPropertyName("tag_name")]
public string TagName { get; set; }
}

14
StabilityMatrix/Models/BasePackage.cs

@ -1,4 +1,7 @@
namespace StabilityMatrix.Models;
using System;
using System.Threading.Tasks;
namespace StabilityMatrix.Models;
public abstract class BasePackage
{
@ -6,6 +9,15 @@ public abstract class BasePackage
public abstract string DisplayName { get; }
public abstract string Author { get; }
public abstract string GithubUrl { get; }
public abstract Task DownloadPackage();
internal virtual string DownloadLocation => $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages\\{Name}.zip";
public event EventHandler<int> DownloadProgressChanged;
public event EventHandler<string> DownloadComplete;
public void OnDownloadProgressChanged(int progress) => DownloadProgressChanged?.Invoke(this, progress);
public void OnDownloadComplete(string path) => DownloadComplete?.Invoke(this, path);
public string ByAuthor => $"By {Author}";
}

45
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -1,4 +1,12 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Refit;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
namespace StabilityMatrix.Models.Packages;
@ -9,6 +17,43 @@ public class A3WebUI: BasePackage
public override string DisplayName => "Stable Diffusion WebUI";
public override string Author => "AUTOMATIC1111";
public override string GithubUrl => "https://github.com/AUTOMATIC1111/stable-diffusion-webui";
public override async Task DownloadPackage()
{
var githubApi = RestService.For<IGithubApi>("https://api.github.com");
var latestRelease = await githubApi.GetLatestRelease("AUTOMATIC1111", "stable-diffusion-webui");
var downloadUrl = $"https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/zipball/{latestRelease.TagName}";
if (!Directory.Exists(DownloadLocation.Replace($"{Name}.zip", "")))
{
Directory.CreateDirectory(DownloadLocation.Replace($"{Name}.zip", ""));
}
using var client = new HttpClient {Timeout = TimeSpan.FromMinutes(5)};
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("StabilityMatrix", "1.0"));
await using var file = new FileStream(DownloadLocation, FileMode.Create, FileAccess.Write, FileShare.None);
using var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
var length = response.Content.Headers.ContentLength;
await using var stream = await response.Content.ReadAsStreamAsync();
var totalBytesRead = 0;
while (true)
{
var buffer = new byte[1024];
var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
if (bytesRead == 0) break;
await file.WriteAsync(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
var progress = (int) (totalBytesRead * 100d / length);
Debug.WriteLine($"Progress; {progress}");
OnDownloadProgressChanged(progress);
}
await file.FlushAsync();
OnDownloadComplete(DownloadLocation);
}
public string CommandLineArgs => $"{GetVramOption()} {GetXformersOption()}";
private static string GetVramOption()

10
StabilityMatrix/Models/Packages/DankDiffusion.cs

@ -1,4 +1,7 @@
namespace StabilityMatrix.Models.Packages;
using System;
using System.Threading.Tasks;
namespace StabilityMatrix.Models.Packages;
public class DankDiffusion : BasePackage
{
@ -6,4 +9,9 @@ public class DankDiffusion : BasePackage
public override string DisplayName => "Dank Diffusion";
public override string Author => "mohnjiles";
public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion";
public override Task DownloadPackage()
{
throw new System.NotImplementedException();
}
}

2
StabilityMatrix/StabilityMatrix.csproj

@ -10,6 +10,8 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Refit" Version="6.3.2" />
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageReference Include="WPF-UI" Version="3.0.0-preview.2" />
<PackageReference Include="pythonnet" Version="3.0.1" />
</ItemGroup>

2
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -83,7 +83,7 @@ internal class InstallerViewModel : INotifyPropertyChanged
public Visibility ProgressBarVisibility => ProgressValue > 0 ? Visibility.Visible : Visibility.Collapsed;
public AsyncRelayCommand InstallCommand => new(async () => Debug.WriteLine(SelectedPackage.GithubUrl));
public AsyncRelayCommand InstallCommand => new(async () => await SelectedPackage.DownloadPackage());
private async Task<bool> InstallGitIfNecessary()
{
var gitOutput = await ProcessRunner.GetProcessOutputAsync("git", "--version");

50
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -0,0 +1,50 @@
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Helper;
using Wpf.Ui.Appearance;
namespace StabilityMatrix.ViewModels;
public partial class MainWindowViewModel : ObservableObject
{
private readonly ISettingsManager settingsManager;
public MainWindowViewModel(ISettingsManager settingsManager)
{
this.settingsManager = settingsManager;
}
[ObservableProperty]
private Visibility advancedModeVisibility;
[ObservableProperty]
private Visibility simpleModeVisibility;
public void OnLoaded()
{
SetTheme();
GoAdvancedMode();
}
[RelayCommand]
private void GoAdvancedMode()
{
AdvancedModeVisibility = Visibility.Visible;
SimpleModeVisibility = Visibility.Hidden;
}
private void SetTheme()
{
var theme = settingsManager.Settings.Theme;
switch (theme)
{
case "Dark":
Theme.Apply(ThemeType.Dark);
break;
case "Light":
Theme.Apply(ThemeType.Light);
break;
}
}
}

8
StabilityMatrix/ViewModels/SettingsViewModel.cs

@ -1,6 +1,10 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Helper;
@ -82,5 +86,7 @@ public partial class SettingsViewModel : ObservableObject
? "Dark"
: settingsManager.Settings.Theme;
GitInfo = await ProcessRunner.GetProcessOutputAsync("git", "--version");
TestProperty = $"{SystemParameters.PrimaryScreenHeight} x {SystemParameters.PrimaryScreenWidth}";
}
}

Loading…
Cancel
Save