|
2 | 2 | @inherits ConnectionComponentBase |
3 | 3 |
|
4 | 4 | <div class="bg-body-tertiary rounded p-3 d-flex flex-column h-100"> |
5 | | - <div class="d-flex align-items-center mb-2"> |
| 5 | + <div class="d-flex align-items-center justify-content-between mb-2"> |
| 6 | + <div class="d-flex align-items-center gap-2"> |
| 7 | + @if (!string.IsNullOrEmpty(_activePrinterName)) |
| 8 | + { |
| 9 | + <span class="badge bg-secondary"> |
| 10 | + <i class="bi bi-terminal me-1"></i>@_activePrinterName |
| 11 | + </span> |
| 12 | + } |
| 13 | + </div> |
6 | 14 | <div class="form-check form-switch mb-0"> |
7 | 15 | <input class="form-check-input" type="checkbox" id="toggle-telemetry-echo" @bind="_showTelemetry" /> |
8 | 16 | <label class="form-check-label ms-2" for="toggle-telemetry-echo"> |
|
64 | 72 | private bool _expectTelemetryEcho; |
65 | 73 | private bool _showTelemetry; |
66 | 74 |
|
| 75 | + // Multi-printer: track which printer the terminal is attached to |
| 76 | + private string _activePrinterName = string.Empty; |
| 77 | + private string _lastPrinterConnectionName = string.Empty; |
| 78 | + |
67 | 79 | private async Task SendCommand() |
68 | 80 | { |
69 | 81 | if (string.IsNullOrWhiteSpace(inputCommand) || PrinterServiceFactory.Current == null) return; |
|
124 | 136 | protected override void HandleConnectionChanged(object? sender, bool connected) |
125 | 137 | { |
126 | 138 | base.HandleConnectionChanged(sender, connected); |
127 | | - var message = connected ? string.Format(Localizer[Resources.CommandPrompt_ConnectedMessage], PrinterServiceFactory.Current?.ConnectionName) |
128 | | - : string.Format(Localizer[Resources.CommandPrompt_DisconnectedMessage], PrinterServiceFactory.Current?.ConnectionName); |
| 139 | + |
| 140 | + var currentName = PrinterServiceFactory.Current?.ConnectionName ?? string.Empty; |
| 141 | + |
| 142 | + // Detect printer switch — clear history and notify |
| 143 | + if (connected && !string.IsNullOrEmpty(currentName) && currentName != _lastPrinterConnectionName && !string.IsNullOrEmpty(_lastPrinterConnectionName)) |
| 144 | + { |
| 145 | + lock (_historyLock) |
| 146 | + { |
| 147 | + history.Clear(); |
| 148 | + } |
| 149 | + AddSystemMessage($"Switched to {currentName}"); |
| 150 | + } |
| 151 | + |
| 152 | + _lastPrinterConnectionName = currentName; |
| 153 | + _activePrinterName = connected ? currentName : string.Empty; |
| 154 | + |
| 155 | + var message = connected ? string.Format(Localizer[Resources.CommandPrompt_ConnectedMessage], currentName) |
| 156 | + : string.Format(Localizer[Resources.CommandPrompt_DisconnectedMessage], currentName); |
129 | 157 | AddSystemMessage(message); |
130 | 158 | InvokeAsync(StateHasChanged); |
131 | 159 | } |
|
0 commit comments