Browse Source

Implement secondary command launching

pull/55/head
Ionite 1 year ago
parent
commit
d493887183
No known key found for this signature in database
  1. 2
      StabilityMatrix.Avalonia/DesignData/MockLaunchPageViewModel.cs
  2. 19
      StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs
  3. 26
      StabilityMatrix.Avalonia/Views/LaunchPageView.axaml
  4. 28
      StabilityMatrix.Core/Models/Packages/InvokeAI.cs

2
StabilityMatrix.Avalonia/DesignData/MockLaunchPageViewModel.cs

@ -35,7 +35,7 @@ public class MockLaunchPageViewModel : LaunchPageViewModel
SelectedPackage?.PackageName != "dank-diffusion" ? base.SelectedBasePackage :
new DankDiffusion(null!, null!, null!, null!);
protected override Task LaunchImpl()
protected override Task LaunchImpl(string? command)
{
IsLaunchTeachingTipsOpen = false;

19
StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs

@ -65,7 +65,8 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable, IAsyn
[ObservableProperty] private bool isLaunchTeachingTipsOpen;
[ObservableProperty] private bool showWebUiButton;
[ObservableProperty, NotifyPropertyChangedFor(nameof(SelectedBasePackage))]
[ObservableProperty, NotifyPropertyChangedFor(nameof(SelectedBasePackage),
nameof(SelectedPackageExtraCommands))]
private InstalledPackage? selectedPackage;
[ObservableProperty] private ObservableCollection<InstalledPackage> installedPackages = new();
@ -75,6 +76,9 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable, IAsyn
public virtual BasePackage? SelectedBasePackage =>
PackageFactory.FindPackageByName(SelectedPackage?.PackageName);
public IEnumerable<string> SelectedPackageExtraCommands =>
SelectedBasePackage?.ExtraLaunchCommands ?? Enumerable.Empty<string>();
// private bool clearingPackages;
private string webUiUrl = string.Empty;
@ -151,12 +155,12 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable, IAsyn
}
[RelayCommand]
private async Task LaunchAsync()
private async Task LaunchAsync(string? command = null)
{
await notificationService.TryAsync(LaunchImpl());
await notificationService.TryAsync(LaunchImpl(command));
}
protected virtual async Task LaunchImpl()
protected virtual async Task LaunchImpl(string? command)
{
IsLaunchTeachingTipsOpen = false;
@ -235,8 +239,11 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable, IAsyn
// Join with extras, if any
userArgsString = string.Join(" ", userArgsString, basePackage.ExtraLaunchArguments);
// TODO: dropdown multi launch options
await basePackage.RunPackage(packagePath, basePackage.LaunchCommand, userArgsString);
// Use input command if provided, otherwise use package launch command
command ??= basePackage.LaunchCommand;
await basePackage.RunPackage(packagePath, command, userArgsString);
RunningPackage = basePackage;
}

26
StabilityMatrix.Avalonia/Views/LaunchPageView.axaml

@ -35,7 +35,7 @@
<Button
Width="72"
IsVisible="{Binding !SelectedBasePackage.ExtraLaunchCommands.Count, FallbackValue=False}"
Background="{DynamicResource ThemeGreenColor}"
Classes="success"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
Command="{Binding LaunchCommand}"
@ -43,11 +43,31 @@
<SplitButton
Width="104"
IsVisible="{Binding !!SelectedBasePackage.ExtraLaunchCommands.Count, FallbackValue=False}"
Background="{DynamicResource ThemeGreenColor}"
Classes="success"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
Command="{Binding LaunchCommand}"
Content="Launch" />
Content="Launch">
<SplitButton.Flyout>
<ui:FAMenuFlyout
Placement="Bottom"
ItemsSource="{Binding SelectedPackageExtraCommands}">
<ui:FAMenuFlyout.ItemTemplate>
<DataTemplate x:DataType="{x:Type system:String}">
<!-- ReSharper disable Xaml.PossibleNullReferenceException -->
<!-- ReSharper disable Xaml.BindingWithContextNotResolved -->
<ui:MenuFlyoutItem
Text="{Binding}"
CommandParameter="{Binding}"
Command="{ReflectionBinding
#LaunchButtonGrid.DataContext.LaunchCommand}"/>
<!-- ReSharper restore Xaml.BindingWithContextNotResolved -->
<!-- ReSharper restore Xaml.PossibleNullReferenceException -->
</DataTemplate>
</ui:FAMenuFlyout.ItemTemplate>
</ui:FAMenuFlyout>
</SplitButton.Flyout>
</SplitButton>
</Grid>
<ui:TeachingTip Grid.Row="0" Grid.Column="0" Name="TeachingTip1"

28
StabilityMatrix.Core/Models/Packages/InvokeAI.cs

@ -19,7 +19,7 @@ public class InvokeAI : BaseGitPackage
public override string LicenseUrl =>
"https://github.com/invoke-ai/InvokeAI/blob/main/LICENSE";
public override string Blurb => "Professional Creative Tools for Stable Diffusion";
public override string LaunchCommand => "invokeai";
public override string LaunchCommand => "invokeai-web";
public override IReadOnlyList<string> ExtraLaunchCommands => new[]
{
@ -129,8 +129,30 @@ public class InvokeAI : BaseGitPackage
// Compile a startup command according to
// https://packaging.python.org/en/latest/specifications/entry-points/#use-for-scripts
var args = $"-c \"import sys; from {split[0]} import {split[1]}; sys.exit({split[1]}())\"";
// For invokeai, also patch the shutil.get_terminal_size function to return a fixed value
// above the minimum in invokeai.frontend.install.widgets
VenvRunner.RunDetached(args.TrimEnd(), OnConsoleOutput, OnExit);
var code = $"""
try:
import os
import shutil
from invokeai.frontend.install import widgets
_min_cols = widgets.MIN_COLS
_min_lines = widgets.MIN_LINES
static_size_fn = lambda: os.terminal_size((_min_cols, _min_lines))
shutil.get_terminal_size = static_size_fn
widgets.get_terminal_size = static_size_fn
except Exception as e:
import warnings
warnings.warn('Could not patch terminal size for InvokeAI' + str(e))
import sys
from {split[0]} import {split[1]}
sys.exit({split[1]}())
""";
VenvRunner.RunDetached($"-c \"{code}\"".TrimEnd(), OnConsoleOutput, OnExit);
}
}

Loading…
Cancel
Save