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