Browse Source

package manager launch page now actually launches package

pull/55/head
JT 1 year ago
parent
commit
c797fdc93f
  1. 12
      StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs
  2. 11
      StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
  3. 6
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  4. 2
      StabilityMatrix.Avalonia/Views/LaunchPageView.axaml
  5. 1
      StabilityMatrix.Avalonia/Views/MainWindow.axaml
  6. 3
      StabilityMatrix.Core/Helper/EventManager.cs

12
StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs

@ -17,6 +17,7 @@ using Microsoft.Extensions.Logging;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.Packages;
@ -67,6 +68,17 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable
this.packageFactory = packageFactory;
this.pyRunner = pyRunner;
this.notificationService = notificationService;
EventManager.Instance.PackageLaunchRequested +=
async (s, e) => await OnPackageLaunchRequested(s, e);
}
private async Task OnPackageLaunchRequested(object? sender, Guid e)
{
SelectedPackage = InstalledPackages.FirstOrDefault(x => x.Id == e);
if (SelectedPackage is null) return;
await LaunchAsync();
}
public override void OnLoaded()

11
StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
namespace StabilityMatrix.Avalonia.ViewModels;
@ -27,6 +29,13 @@ public partial class MainWindowViewModel : ViewModelBase
{
CurrentPage = Pages.FirstOrDefault();
SelectedCategory = Pages.FirstOrDefault();
EventManager.Instance.PageChangeRequested += OnPageChangeRequested;
}
private void OnPageChangeRequested(object? sender, Type e)
{
CurrentPage = Pages.FirstOrDefault(p => p.GetType() == e);
SelectedCategory = Pages.FirstOrDefault(p => p.GetType() == e);
}
partial void OnSelectedCategoryChanged(object? value)

6
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -152,7 +152,11 @@ public partial class PackageManagerViewModel : PageViewModelBase
[RelayCommand]
private async Task Install()
{
if (InstallButtonText == "Launch")
{
EventManager.Instance.RequestPageChange(typeof(LaunchPageViewModel));
EventManager.Instance.OnPackageLaunchRequested(SelectedPackage.Id);
}
}
[RelayCommand]

2
StabilityMatrix.Avalonia/Views/LaunchPageView.axaml

@ -62,7 +62,7 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
ItemsSource="{Binding InstalledPackages}"
SelectedValue="{Binding SelectedPackage}">
SelectedItem="{Binding SelectedPackage}">
<ComboBox.Styles>
<Style Selector="ComboBox /template/ ContentControl#ContentPresenter &gt; StackPanel &gt; TextBlock:nth-child(2)">
<Setter Property="IsVisible" Value="False" />

1
StabilityMatrix.Avalonia/Views/MainWindow.axaml

@ -57,7 +57,6 @@
IsPaneOpen="False"
OpenPaneLength="200"
IsSettingsVisible="False"
Name="NavView"
Content="{Binding CurrentPage}"
MenuItemsSource="{Binding Pages, Mode=OneWay}"
FooterMenuItemsSource="{Binding FooterPages, Mode=OneWay}"

3
StabilityMatrix.Core/Helper/EventManager.cs

@ -18,6 +18,7 @@ public class EventManager
public event EventHandler? TeachingTooltipNeeded;
public event EventHandler<bool>? DevModeSettingChanged;
public event EventHandler<UpdateInfo>? UpdateAvailable;
public event EventHandler<Guid> PackageLaunchRequested;
public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress);
public void RequestPageChange(Type pageType) => PageChangeRequested?.Invoke(this, pageType);
public void OnInstalledPackagesChanged() => InstalledPackagesChanged?.Invoke(this, EventArgs.Empty);
@ -25,4 +26,6 @@ public class EventManager
public void OnTeachingTooltipNeeded() => TeachingTooltipNeeded?.Invoke(this, EventArgs.Empty);
public void OnDevModeSettingChanged(bool value) => DevModeSettingChanged?.Invoke(this, value);
public void OnUpdateAvailable(UpdateInfo args) => UpdateAvailable?.Invoke(this, args);
public void OnPackageLaunchRequested(Guid packageId) =>
PackageLaunchRequested?.Invoke(this, packageId);
}

Loading…
Cancel
Save