|
|
@ -7,6 +7,7 @@ using System.Windows; |
|
|
|
using System.Windows.Threading; |
|
|
|
using System.Windows.Threading; |
|
|
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
|
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Toolkit.Uwp.Notifications; |
|
|
|
using Microsoft.Toolkit.Uwp.Notifications; |
|
|
|
using StabilityMatrix.Helper; |
|
|
|
using StabilityMatrix.Helper; |
|
|
|
using StabilityMatrix.Models; |
|
|
|
using StabilityMatrix.Models; |
|
|
@ -20,23 +21,21 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
private readonly IPackageFactory packageFactory; |
|
|
|
private readonly IPackageFactory packageFactory; |
|
|
|
private readonly IContentDialogService contentDialogService; |
|
|
|
private readonly IContentDialogService contentDialogService; |
|
|
|
private readonly LaunchOptionsDialogViewModel launchOptionsDialogViewModel; |
|
|
|
private readonly LaunchOptionsDialogViewModel launchOptionsDialogViewModel; |
|
|
|
|
|
|
|
private readonly ILogger<LaunchViewModel> logger; |
|
|
|
private BasePackage? runningPackage; |
|
|
|
private BasePackage? runningPackage; |
|
|
|
private bool clearingPackages = false; |
|
|
|
private bool clearingPackages = false; |
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] private string consoleInput = ""; |
|
|
|
private string consoleInput = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] private string consoleOutput = ""; |
|
|
|
private string consoleOutput = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] private Visibility launchButtonVisibility; |
|
|
|
private Visibility launchButtonVisibility; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] private Visibility stopButtonVisibility; |
|
|
|
private Visibility stopButtonVisibility; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private InstalledPackage? selectedPackage; |
|
|
|
private InstalledPackage? selectedPackage; |
|
|
|
|
|
|
|
|
|
|
|
public InstalledPackage? SelectedPackage |
|
|
|
public InstalledPackage? SelectedPackage |
|
|
|
{ |
|
|
|
{ |
|
|
|
get => selectedPackage; |
|
|
|
get => selectedPackage; |
|
|
@ -54,19 +53,23 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] private ObservableCollection<InstalledPackage> installedPackages = new(); |
|
|
|
private ObservableCollection<InstalledPackage> installedPackages = new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler? ScrollNeeded; |
|
|
|
public event EventHandler? ScrollNeeded; |
|
|
|
|
|
|
|
|
|
|
|
public LaunchViewModel(ISettingsManager settingsManager, IPackageFactory packageFactory, IContentDialogService contentDialogService, LaunchOptionsDialogViewModel launchOptionsDialogViewModel) |
|
|
|
public LaunchViewModel(ISettingsManager settingsManager, |
|
|
|
|
|
|
|
IPackageFactory packageFactory, |
|
|
|
|
|
|
|
IContentDialogService contentDialogService, |
|
|
|
|
|
|
|
LaunchOptionsDialogViewModel launchOptionsDialogViewModel, |
|
|
|
|
|
|
|
ILogger<LaunchViewModel> logger) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.contentDialogService = contentDialogService; |
|
|
|
this.contentDialogService = contentDialogService; |
|
|
|
this.launchOptionsDialogViewModel = launchOptionsDialogViewModel; |
|
|
|
this.launchOptionsDialogViewModel = launchOptionsDialogViewModel; |
|
|
|
|
|
|
|
this.logger = logger; |
|
|
|
this.settingsManager = settingsManager; |
|
|
|
this.settingsManager = settingsManager; |
|
|
|
this.packageFactory = packageFactory; |
|
|
|
this.packageFactory = packageFactory; |
|
|
|
SetProcessRunning(false); |
|
|
|
SetProcessRunning(false); |
|
|
|
|
|
|
|
|
|
|
|
ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompatOnOnActivated; |
|
|
|
ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompatOnOnActivated; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -74,7 +77,7 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (e.Argument.StartsWith("http")) |
|
|
|
if (e.Argument.StartsWith("http")) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Process.Start(new ProcessStartInfo(e.Argument) { UseShellExecute = true }); |
|
|
|
Process.Start(new ProcessStartInfo(e.Argument) {UseShellExecute = true}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -98,7 +101,7 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Package not found"); |
|
|
|
throw new InvalidOperationException("Package not found"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
basePackage.ConsoleOutput += OnConsoleOutput; |
|
|
|
basePackage.ConsoleOutput += OnConsoleOutput; |
|
|
|
basePackage.Exited += OnExit; |
|
|
|
basePackage.Exited += OnExit; |
|
|
|
basePackage.StartupComplete += RunningPackageOnStartupComplete; |
|
|
|
basePackage.StartupComplete += RunningPackageOnStartupComplete; |
|
|
@ -117,22 +120,23 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
Debug.WriteLine($"Selected package is null"); |
|
|
|
Debug.WriteLine($"Selected package is null"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var package = packageFactory.FindPackageByName(name); |
|
|
|
var package = packageFactory.FindPackageByName(name); |
|
|
|
if (package == null) |
|
|
|
if (package == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Debug.WriteLine($"Package {name} not found"); |
|
|
|
Debug.WriteLine($"Package {name} not found"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vm.SelectedPackage = package; |
|
|
|
vm.SelectedPackage = package; |
|
|
|
|
|
|
|
|
|
|
|
// Open a config page |
|
|
|
// Open a config page |
|
|
|
var dialog = new LaunchOptionsDialog(contentDialogService.GetContentPresenter()) |
|
|
|
var dialog = new LaunchOptionsDialog(contentDialogService.GetContentPresenter()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DataContext = vm, |
|
|
|
DataContext = vm, |
|
|
|
IsPrimaryButtonEnabled = true, |
|
|
|
IsPrimaryButtonEnabled = true, |
|
|
|
PrimaryButtonText = "Save", |
|
|
|
PrimaryButtonText = "Save", |
|
|
|
CloseButtonText= "Cancel", |
|
|
|
CloseButtonText = "Cancel", |
|
|
|
}; |
|
|
|
}; |
|
|
|
await dialog.ShowAsync(); |
|
|
|
await dialog.ShowAsync(); |
|
|
|
} |
|
|
|
} |
|
|
@ -175,6 +179,7 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
runningPackage.ConsoleOutput -= OnConsoleOutput; |
|
|
|
runningPackage.ConsoleOutput -= OnConsoleOutput; |
|
|
|
runningPackage.Exited -= OnExit; |
|
|
|
runningPackage.Exited -= OnExit; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
runningPackage?.Shutdown(); |
|
|
|
runningPackage?.Shutdown(); |
|
|
|
runningPackage = null; |
|
|
|
runningPackage = null; |
|
|
|
SetProcessRunning(false); |
|
|
|
SetProcessRunning(false); |
|
|
@ -197,6 +202,7 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
{ |
|
|
|
{ |
|
|
|
InstalledPackages.Add(package); |
|
|
|
InstalledPackages.Add(package); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearingPackages = false; |
|
|
|
clearingPackages = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -213,7 +219,7 @@ public partial class LaunchViewModel : ObservableObject |
|
|
|
StopButtonVisibility = Visibility.Collapsed; |
|
|
|
StopButtonVisibility = Visibility.Collapsed; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void OnConsoleOutput(object? sender, string output) |
|
|
|
private void OnConsoleOutput(object? sender, string output) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (output == null) return; |
|
|
|
if (output == null) return; |
|
|
|