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:local="clr-namespace:StabilityMatrix"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Exit="App_OnExit"
Startup="App_OnStartup"
>
<Application.Resources>

11
StabilityMatrix/App.xaml.cs

@ -20,6 +20,8 @@ namespace StabilityMatrix
/// </summary>
public partial class App : Application
{
private ServiceProvider? serviceProvider;
private void App_OnStartup(object sender, StartupEventArgs e)
{
var serviceCollection = new ServiceCollection();
@ -50,9 +52,14 @@ namespace StabilityMatrix
log.AddNLog(logConfig);
});
var provider = serviceCollection.BuildServiceProvider();
var window = provider.GetRequiredService<MainWindow>();
serviceProvider = serviceCollection.BuildServiceProvider();
var window = serviceProvider.GetRequiredService<MainWindow>();
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 = "";
private InstalledPackage? selectedPackage;
public InstalledPackage? SelectedPackage
{
get => selectedPackage;
@ -42,6 +41,8 @@ public partial class LaunchViewModel : ObservableObject
}
public ObservableCollection<InstalledPackage> InstalledPackages = new();
public Process? CurrentRunningProcess { get; set; }
public event EventHandler ScrollNeeded;
public LaunchViewModel(ISettingsManager settingsManager)
@ -97,6 +98,7 @@ public partial class LaunchViewModel : ObservableObject
var args = "\"" + Path.Combine(packagePath, "launch.py") + "\"";
venv.RunDetached(args, onConsoleOutput, onExit);
CurrentRunningProcess = venv.Process;
});
public void OnLoaded()
@ -104,8 +106,16 @@ public partial class LaunchViewModel : ObservableObject
LoadPackages();
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()

Loading…
Cancel
Save