diff --git a/src/PSLauncher.App/ViewModels/MainViewModel.cs b/src/PSLauncher.App/ViewModels/MainViewModel.cs index b1ac8b6..fe1fb0e 100644 --- a/src/PSLauncher.App/ViewModels/MainViewModel.cs +++ b/src/PSLauncher.App/ViewModels/MainViewModel.cs @@ -424,13 +424,41 @@ public sealed partial class MainViewModel : ObservableObject if (row.Installed is null) return; try { - _processLauncher.Launch(row.Installed); + var proc = _processLauncher.Launch(row.Installed); _config.LastLaunchedVersion = row.Version; _configStore.Save(_config); // Réduit la fenêtre du launcher pour ne pas gêner Proserve qui démarre if (Application.Current.MainWindow is { } mw) mw.WindowState = WindowState.Minimized; + + // Quand Proserve se termine, on remet la fenêtre du launcher au premier plan. + // EnableRaisingEvents est requis pour recevoir l'event Exited. + try + { + proc.EnableRaisingEvents = true; + proc.Exited += (_, _) => + { + _logger.LogInformation("Proserve v{Version} a quitté — restauration du launcher", row.Version); + Application.Current?.Dispatcher.Invoke(() => + { + if (Application.Current.MainWindow is { } main) + { + if (main.WindowState == WindowState.Minimized) + main.WindowState = WindowState.Normal; + main.Activate(); + // Pop temporaire pour amener la fenêtre au premier plan + main.Topmost = true; + main.Topmost = false; + } + }); + }; + } + catch (Exception ex) + { + // ShellExecute peut renvoyer un Process sans accès aux events — non bloquant + _logger.LogDebug(ex, "Could not hook Exited on launched process"); + } } catch (Exception ex) {