Browse Source

Add nlog logger to LaunchViewModel

pull/5/head
Ionite 1 year ago
parent
commit
b254e78ade
No known key found for this signature in database
  1. 32
      StabilityMatrix/ViewModels/LaunchViewModel.cs

32
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -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,15 +53,19 @@ 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);
@ -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});
} }
} }
@ -117,6 +120,7 @@ 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)
{ {
@ -132,7 +136,7 @@ public partial class LaunchViewModel : ObservableObject
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;
} }

Loading…
Cancel
Save