Browse Source

Fix ActiveInstalledPackage

pull/5/head
JT 2 years ago
parent
commit
862525a86f
  1. 1
      StabilityMatrix/Helper/ProcessRunner.cs
  2. 2
      StabilityMatrix/PyVenvRunner.cs
  3. 34
      StabilityMatrix/ViewModels/LaunchViewModel.cs

1
StabilityMatrix/Helper/ProcessRunner.cs

@ -42,6 +42,7 @@ public static class ProcessRunner
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.CreateNoWindow = true;
if (environmentVariables != null)

2
StabilityMatrix/PyVenvRunner.cs

@ -65,7 +65,7 @@ public class PyVenvRunner: IDisposable
}
}
public void RunDetached(string arguments, Action<string?> outputDataReceived, Action<int>? onExit = null, bool unbuffered = true)
public void RunDetached(string arguments, Action<string>? outputDataReceived, Action<int>? onExit = null, bool unbuffered = true)
{
if (!Exists())
{

34
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -22,6 +22,7 @@ public partial class LaunchViewModel : ObservableObject
{
private readonly ISettingsManager settingsManager;
private PyVenvRunner? venvRunner;
private bool clearingPackages = false;
[ObservableProperty]
private string consoleInput = "";
@ -44,7 +45,12 @@ public partial class LaunchViewModel : ObservableObject
{
if (value == selectedPackage) return;
selectedPackage = value;
settingsManager.SetActiveInstalledPackage(value);
if (!clearingPackages)
{
settingsManager.SetActiveInstalledPackage(value);
}
OnPropertyChanged();
}
}
@ -56,6 +62,7 @@ public partial class LaunchViewModel : ObservableObject
public LaunchViewModel(ISettingsManager settingsManager)
{
this.settingsManager = settingsManager;
SetProcessRunning(false);
}
public AsyncRelayCommand LaunchCommand => new(async () =>
@ -82,8 +89,8 @@ public partial class LaunchViewModel : ObservableObject
{
await venvRunner.Setup();
}
var onConsoleOutput = new Action<string?>(s =>
void OnConsoleOutput(string? s)
{
if (s == null) return;
Dispatcher.CurrentDispatcher.Invoke(() =>
@ -92,9 +99,9 @@ public partial class LaunchViewModel : ObservableObject
ConsoleOutput += s + "\n";
ScrollNeeded?.Invoke(this, EventArgs.Empty);
});
});
var onExit = new Action<int>(i =>
}
void OnExit(int i)
{
Dispatcher.CurrentDispatcher.Invoke(() =>
{
@ -103,17 +110,16 @@ public partial class LaunchViewModel : ObservableObject
ScrollNeeded?.Invoke(this, EventArgs.Empty);
SetProcessRunning(false);
});
});
}
var args = "\"" + Path.Combine(packagePath, "launch.py") + "\"";
venvRunner.RunDetached(args, onConsoleOutput, onExit);
venvRunner.RunDetached(args, OnConsoleOutput, OnExit);
SetProcessRunning(true);
});
public void OnLoaded()
{
SetProcessRunning(false);
LoadPackages();
if (InstalledPackages.Any() && settingsManager.Settings.ActiveInstalledPackage != null)
{
@ -134,9 +140,13 @@ public partial class LaunchViewModel : ObservableObject
}
[RelayCommand]
private void Stop()
private async Task Stop()
{
venvRunner?.Dispose();
if (venvRunner?.Process != null)
{
await venvRunner.Process.WaitForExitAsync();
}
venvRunner = null;
SetProcessRunning(false);
ConsoleOutput += $"{Environment.NewLine}Stopped process at {DateTimeOffset.Now}{Environment.NewLine}";
@ -149,13 +159,15 @@ public partial class LaunchViewModel : ObservableObject
{
return;
}
clearingPackages = true;
InstalledPackages.Clear();
foreach (var package in packages)
{
InstalledPackages.Add(package);
}
clearingPackages = false;
}
private void SetProcessRunning(bool running)

Loading…
Cancel
Save