Browse Source

UI Tweaks

- Save NavExpanded state to settings
- Added installed checkbox on Install page
- made more stuff [ObservableProperty]
pull/5/head
JT 2 years ago
parent
commit
a323fe40d3
  1. 1
      StabilityMatrix/Helper/ISettingsManager.cs
  2. 6
      StabilityMatrix/Helper/SettingsManager.cs
  3. 18
      StabilityMatrix/InstallPage.xaml
  4. 4
      StabilityMatrix/MainWindow.xaml
  5. 18
      StabilityMatrix/MainWindow.xaml.cs
  6. 1
      StabilityMatrix/Models/BasePackage.cs
  7. 1
      StabilityMatrix/Models/Packages/A3WebUI.cs
  8. 1
      StabilityMatrix/Models/Settings.cs
  9. 45
      StabilityMatrix/ViewModels/InstallerViewModel.cs

1
StabilityMatrix/Helper/ISettingsManager.cs

@ -10,4 +10,5 @@ public interface ISettingsManager
void SetActiveInstalledPackage(InstalledPackage? p);
void SetHasInstalledPip(bool hasInstalledPip);
void SetHasInstalledVenv(bool hasInstalledVenv);
void SetNavExpanded(bool navExpanded);
}

6
StabilityMatrix/Helper/SettingsManager.cs

@ -68,6 +68,12 @@ public class SettingsManager : ISettingsManager
SaveSettings();
}
public void SetNavExpanded(bool navExpanded)
{
Settings.IsNavExpanded = navExpanded;
SaveSettings();
}
private void LoadSettings()
{
var settingsContent = File.ReadAllText(SettingsPath);

18
StabilityMatrix/InstallPage.xaml

@ -6,8 +6,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:models="clr-namespace:StabilityMatrix.Models"
d:DesignHeight="700"
d:DesignWidth="1100"
d:DesignHeight="450"
d:DesignWidth="700"
Loaded="InstallPage_OnLoaded"
Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
@ -47,8 +47,18 @@
</ListView.ItemTemplate>
</ListView>
<StackPanel Orientation="Vertical" Margin="32,0,0,0">
<TextBlock Text="{Binding SelectedPackage.DisplayName}"/>
<TextBlock Text="{Binding SelectedPackage.ByAuthor}"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}"
FontSize="24" FontWeight="Bold" />
<Grid Visibility="{Binding PackageInstalledVisibility}">
<Ellipse Width="24" Height="24" Fill="Green" Margin="8,0,0,0"/>
<ui:SymbolIcon Symbol="Checkmark24" Foreground="White" Margin="8,0,0,0"/>
</Grid>
<TextBlock Text="Installed" VerticalAlignment="Center" Margin="8,0,0,0"
Visibility="{Binding PackageInstalledVisibility}"/>
</StackPanel>
<TextBlock Text="{Binding SelectedPackage.ByAuthor, FallbackValue=by Automatic111}"
FontSize="12" Margin="0,5, 0, 5" />
<ui:Hyperlink NavigateUri="{Binding SelectedPackage.GithubUrl}">
<TextBlock>
<Run Text="GitHub Page:"/>

4
StabilityMatrix/MainWindow.xaml

@ -26,7 +26,9 @@
</ui:TitleBar>
<Grid Grid.Row="1" Visibility="{Binding AdvancedModeVisibility, FallbackValue=Visible}">
<ui:NavigationView x:Name="RootNavigation"
IsBackButtonVisible="Collapsed">
IsBackButtonVisible="Collapsed"
PaneOpened="RootNavigation_OnPaneOpened"
PaneClosed="RootNavigation_OnPaneClosed">
<ui:NavigationView.Header>
<ui:BreadcrumbBar
Margin="42,32,0,16"

18
StabilityMatrix/MainWindow.xaml.cs

@ -1,7 +1,9 @@
using System.Diagnostics;
using System.Windows;
using StabilityMatrix.Helper;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.Navigation;
using Wpf.Ui.Controls.Window;
namespace StabilityMatrix
@ -12,13 +14,15 @@ namespace StabilityMatrix
public partial class MainWindow : FluentWindow
{
private readonly MainWindowViewModel mainWindowViewModel;
private readonly ISettingsManager settingsManager;
public MainWindow(IPageService pageService, IContentDialogService contentDialogService,
MainWindowViewModel mainWindowViewModel)
MainWindowViewModel mainWindowViewModel, ISettingsManager settingsManager)
{
InitializeComponent();
this.mainWindowViewModel = mainWindowViewModel;
this.settingsManager = settingsManager;
DataContext = mainWindowViewModel;
@ -32,7 +36,17 @@ namespace StabilityMatrix
{
RootNavigation.Navigate(typeof(LaunchPage));
mainWindowViewModel.OnLoaded();
RootNavigation.IsPaneOpen = settingsManager.Settings.IsNavExpanded;
}
private void RootNavigation_OnPaneOpened(NavigationView sender, RoutedEventArgs args)
{
settingsManager.SetNavExpanded(true);
}
private void RootNavigation_OnPaneClosed(NavigationView sender, RoutedEventArgs args)
{
settingsManager.SetNavExpanded(false);
}
}
}

1
StabilityMatrix/Models/BasePackage.cs

@ -9,6 +9,7 @@ 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";

1
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -17,6 +17,7 @@ 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");

1
StabilityMatrix/Models/Settings.cs

@ -10,4 +10,5 @@ public class Settings
public Guid? ActiveInstalledPackage { get; set; }
public bool HasInstalledPip { get; set; }
public bool HasInstalledVenv { get; set; }
public bool IsNavExpanded { get; set; }
}

45
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -5,26 +5,29 @@ using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using System.ComponentModel;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.IO.Compression;
using System.Runtime.CompilerServices;
using StabilityMatrix.Models.Packages;
using System.Linq;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
namespace StabilityMatrix.ViewModels;
public class InstallerViewModel : INotifyPropertyChanged
public partial class InstallerViewModel : ObservableObject
{
private readonly ILogger<InstallerViewModel> logger;
private readonly ISettingsManager settingsManager;
private string installedText;
private int progressValue;
private bool isIndeterminate;
private BasePackage selectedPackage;
[ObservableProperty]
private string installedText;
[ObservableProperty]
private bool isIndeterminate;
public InstallerViewModel(ILogger<InstallerViewModel> logger, ISettingsManager settingsManager)
{
@ -47,16 +50,9 @@ public class InstallerViewModel : INotifyPropertyChanged
public ObservableCollection<BasePackage> Packages { get; }
public string InstalledText
{
get => installedText;
private set
{
if (value == installedText) return;
installedText = value;
OnPropertyChanged();
}
}
[ObservableProperty]
private Visibility packageInstalledVisibility;
public int ProgressValue
{
@ -70,17 +66,6 @@ public class InstallerViewModel : INotifyPropertyChanged
}
}
public bool IsIndeterminate
{
get => isIndeterminate;
set
{
if (value == isIndeterminate) return;
isIndeterminate = value;
OnPropertyChanged();
}
}
public BasePackage SelectedPackage
{
get => selectedPackage;
@ -88,6 +73,11 @@ public class InstallerViewModel : INotifyPropertyChanged
{
selectedPackage = value;
OnPropertyChanged();
PackageInstalledVisibility =
settingsManager.Settings.InstalledPackages.Any(p => p.Name == selectedPackage.Name)
? Visibility.Visible
: Visibility.Collapsed;
}
}
@ -222,9 +212,4 @@ public class InstallerViewModel : INotifyPropertyChanged
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

Loading…
Cancel
Save