Browse Source

Merge pull request #18 from ionite34/on-exit

pull/5/head
Ionite 2 years ago committed by GitHub
parent
commit
8963af3cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      StabilityMatrix/App.xaml
  2. 11
      StabilityMatrix/App.xaml.cs
  3. 14
      StabilityMatrix/ViewModels/LaunchViewModel.cs

1
StabilityMatrix/App.xaml

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StabilityMatrix" xmlns:local="clr-namespace:StabilityMatrix"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Exit="App_OnExit"
Startup="App_OnStartup" Startup="App_OnStartup"
> >
<Application.Resources> <Application.Resources>

11
StabilityMatrix/App.xaml.cs

@ -20,6 +20,8 @@ namespace StabilityMatrix
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private ServiceProvider? serviceProvider;
private void App_OnStartup(object sender, StartupEventArgs e) private void App_OnStartup(object sender, StartupEventArgs e)
{ {
var serviceCollection = new ServiceCollection(); var serviceCollection = new ServiceCollection();
@ -50,9 +52,14 @@ namespace StabilityMatrix
log.AddNLog(logConfig); log.AddNLog(logConfig);
}); });
var provider = serviceCollection.BuildServiceProvider(); serviceProvider = serviceCollection.BuildServiceProvider();
var window = provider.GetRequiredService<MainWindow>(); var window = serviceProvider.GetRequiredService<MainWindow>();
window.Show(); window.Show();
} }
private void App_OnExit(object sender, ExitEventArgs e)
{
serviceProvider?.GetRequiredService<LaunchViewModel>().OnShutdown();
}
} }
} }

14
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -28,7 +28,6 @@ public partial class LaunchViewModel : ObservableObject
public string consoleOutput = ""; public string consoleOutput = "";
private InstalledPackage? selectedPackage; private InstalledPackage? selectedPackage;
public InstalledPackage? SelectedPackage public InstalledPackage? SelectedPackage
{ {
get => selectedPackage; get => selectedPackage;
@ -42,6 +41,8 @@ public partial class LaunchViewModel : ObservableObject
} }
public ObservableCollection<InstalledPackage> InstalledPackages = new(); public ObservableCollection<InstalledPackage> InstalledPackages = new();
public Process? CurrentRunningProcess { get; set; }
public event EventHandler ScrollNeeded; public event EventHandler ScrollNeeded;
public LaunchViewModel(ISettingsManager settingsManager) public LaunchViewModel(ISettingsManager settingsManager)
@ -97,6 +98,7 @@ public partial class LaunchViewModel : ObservableObject
var args = "\"" + Path.Combine(packagePath, "launch.py") + "\""; var args = "\"" + Path.Combine(packagePath, "launch.py") + "\"";
venv.RunDetached(args, onConsoleOutput, onExit); venv.RunDetached(args, onConsoleOutput, onExit);
CurrentRunningProcess = venv.Process;
}); });
public void OnLoaded() public void OnLoaded()
@ -104,10 +106,18 @@ public partial class LaunchViewModel : ObservableObject
LoadPackages(); LoadPackages();
if (InstalledPackages.Any()) if (InstalledPackages.Any())
{ {
SelectedPackage = InstalledPackages[0]; SelectedPackage =
InstalledPackages[
InstalledPackages.IndexOf(InstalledPackages.FirstOrDefault(x =>
x.Id == settingsManager.Settings.ActiveInstalledPackage))];
} }
} }
public void OnShutdown()
{
CurrentRunningProcess?.Kill();
}
private void LoadPackages() private void LoadPackages()
{ {
var packages = settingsManager.Settings.InstalledPackages; var packages = settingsManager.Settings.InstalledPackages;

Loading…
Cancel
Save