Skip to content

Commit 6db54fa

Browse files
committed
crosscheck
1 parent 603dfe0 commit 6db54fa

28 files changed

Lines changed: 3717 additions & 41 deletions

MakerPrompt.Blazor/App.razor

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<ProcessError>
22
<GlobalErrorBoundary>
3-
<Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="[typeof(MainLayout).Assembly]">
4-
<Found Context="routeData">
5-
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
6-
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
7-
</Found>
8-
<NotFound>
9-
<PageTitle>Not found</PageTitle>
10-
<LayoutView Layout="@typeof(MainLayout)">
11-
<p role="alert">Sorry, there's nothing at this address.</p>
12-
</LayoutView>
13-
</NotFound>
14-
</Router>
3+
<AppInitializer>
4+
<Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="[typeof(MainLayout).Assembly]">
5+
<Found Context="routeData">
6+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
7+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
8+
</Found>
9+
<NotFound>
10+
<PageTitle>Not found</PageTitle>
11+
<LayoutView Layout="@typeof(MainLayout)">
12+
<p role="alert">Sorry, there's nothing at this address.</p>
13+
</LayoutView>
14+
</NotFound>
15+
</Router>
16+
</AppInitializer>
1517
</GlobalErrorBoundary>
1618
</ProcessError>

MakerPrompt.Blazor/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using MakerPrompt.Blazor;
33
using MakerPrompt.Blazor.Services;
44
using MakerPrompt.Blazor.Storage;
5+
using MakerPrompt.Shared.Services;
56
using MakerPrompt.Shared.Utils;
67
using Microsoft.AspNetCore.Components.Web;
78
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@@ -13,6 +14,8 @@
1314

1415
builder.Services.RegisterMakerPromptSharedServices<AppConfigurationService, WebSerialService>();
1516
builder.Services.AddScoped<MakerPrompt.Shared.Infrastructure.IAppLocalStorageProvider, BlazorAppLocalStorageProvider>();
17+
// WASM: AES-GCM not supported in browser — use Base64 encoding fallback
18+
builder.Services.AddSingleton<IConnectionEncryptionService, Base64ConnectionEncryptionService>();
1619

1720
var host = builder.Build();
1821
const string defaultCulture = "en-US";
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<ProcessError>
22
<GlobalErrorBoundary>
3-
<Router AppAssembly="@typeof(MauiProgram).Assembly" AdditionalAssemblies="[typeof(MainLayout).Assembly]">
4-
<Found Context="routeData">
5-
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
6-
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
7-
</Found>
8-
</Router>
3+
<AppInitializer>
4+
<Router AppAssembly="@typeof(MauiProgram).Assembly" AdditionalAssemblies="[typeof(MainLayout).Assembly]">
5+
<Found Context="routeData">
6+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
7+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
8+
</Found>
9+
</Router>
10+
</AppInitializer>
911
</GlobalErrorBoundary>
1012
</ProcessError>

MakerPrompt.MAUI/MauiProgram.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Logging;
22
using MakerPrompt.Shared.Utils;
3+
using MakerPrompt.Shared.Services;
34
using Microsoft.AspNetCore.Builder;
45
using MakerPrompt.MAUI.Services;
56
using MakerPrompt.MAUI.Storage;
@@ -37,6 +38,11 @@ public static MauiApp CreateMauiApp()
3738
.AddSupportedUICultures(supportedCultures);
3839
builder.Services.RegisterMakerPromptSharedServices<AppConfigurationService, SerialService>();
3940
builder.Services.AddScoped<IAppLocalStorageProvider, MauiAppLocalStorageProvider>();
41+
// MAUI: Use AES-256-GCM encryption for stored credentials
42+
var deviceId = DeviceInfo.Current.Idiom.ToString();
43+
var deviceName = DeviceInfo.Current.Name ?? "default";
44+
builder.Services.AddSingleton<IConnectionEncryptionService>(
45+
new AesConnectionEncryptionService($"MakerPrompt-{deviceId}-{deviceName}"));
4046
return builder.Build();
4147
}
4248
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@*
2+
App-level initializer — ensures PrinterConnectionManager and PrintProjectService
3+
are loaded and auto-connect runs. Place in App.razor or Routes.razor wrapping the Router.
4+
*@
5+
@inject PrinterConnectionManager ConnectionManager
6+
@inject PrintProjectService ProjectService
7+
@inject ILogger<AppInitializer> Logger
8+
9+
@ChildContent
10+
11+
@code {
12+
[Parameter] public RenderFragment? ChildContent { get; set; }
13+
14+
private bool _initialized;
15+
16+
protected override async Task OnAfterRenderAsync(bool firstRender)
17+
{
18+
if (firstRender && !_initialized)
19+
{
20+
_initialized = true;
21+
try
22+
{
23+
await ConnectionManager.InitializeAsync();
24+
await ProjectService.InitializeAsync();
25+
_ = ConnectionManager.AutoConnectAsync();
26+
}
27+
catch (Exception ex)
28+
{
29+
Logger.LogError(ex, "Failed to initialize app services");
30+
}
31+
}
32+
}
33+
}

MakerPrompt.Shared/Components/CommandPrompt.razor

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
@inherits ConnectionComponentBase
33

44
<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>
614
<div class="form-check form-switch mb-0">
715
<input class="form-check-input" type="checkbox" id="toggle-telemetry-echo" @bind="_showTelemetry" />
816
<label class="form-check-label ms-2" for="toggle-telemetry-echo">
@@ -64,6 +72,10 @@
6472
private bool _expectTelemetryEcho;
6573
private bool _showTelemetry;
6674

75+
// Multi-printer: track which printer the terminal is attached to
76+
private string _activePrinterName = string.Empty;
77+
private string _lastPrinterConnectionName = string.Empty;
78+
6779
private async Task SendCommand()
6880
{
6981
if (string.IsNullOrWhiteSpace(inputCommand) || PrinterServiceFactory.Current == null) return;
@@ -124,8 +136,24 @@
124136
protected override void HandleConnectionChanged(object? sender, bool connected)
125137
{
126138
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);
129157
AddSystemMessage(message);
130158
InvokeAsync(StateHasChanged);
131159
}

0 commit comments

Comments
 (0)