Skip to content

Commit cc95609

Browse files
PureWeenCopilot
andcommitted
fix: PR 322 review fixes - overlay visibility, TCS race, JsonDocument disposal, error logging, UX improvements
- QrScannerPage: Set IsVisible=true on all 4 overlay BoxViews in LayoutOverlays() - QrScannerService: Guard against TCS race condition on concurrent ScanAsync() calls - Settings.razor: Dispose JsonDocument with 'using', add StateHasChanged after ShowStatus, log errors in TryGenerateFiestaPairingString, check WsBridgeServer.IsRunning after Start, show pairing string inline in Direct Connection section - Dashboard.razor: Dispose JsonDocument with 'using' - PolyPilot.csproj: Pin QRCoder=1.6.0 and ZXing.Net.Maui.Controls=0.4.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b2c155a commit cc95609

5 files changed

Lines changed: 51 additions & 6 deletions

File tree

PolyPilot/Components/Pages/Dashboard.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@
584584
try
585585
{
586586
// Try JSON format first: { "url": "...", "token": "...", "lanUrl": "...", "lanToken": "..." }
587-
var doc = System.Text.Json.JsonDocument.Parse(result);
587+
using var doc = System.Text.Json.JsonDocument.Parse(result);
588588
if (doc.RootElement.TryGetProperty("url", out var urlProp))
589589
mobileRemoteUrl = urlProp.GetString() ?? "";
590590
if (doc.RootElement.TryGetProperty("token", out var tokenProp))

PolyPilot/Components/Pages/Settings.razor

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@
271271
</div>
272272
}
273273

274+
@if (fiestaPairingString != null)
275+
{
276+
<div class="tunnel-url">
277+
<label>Pairing string:</label>
278+
<code class="token-value @(showFiestaPairingString ? "" : "blurred")">@fiestaPairingString</code>
279+
<button class="copy-btn" @onclick="() => showFiestaPairingString = !showFiestaPairingString"
280+
title="@(showFiestaPairingString ? "Hide" : "Reveal")">
281+
@if (showFiestaPairingString)
282+
{
283+
<svg class="icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
284+
}
285+
else
286+
{
287+
<svg class="icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
288+
}
289+
</button>
290+
<button class="copy-btn" @onclick="CopyFiestaPairingString" title="Copy to clipboard">
291+
<svg class="icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
292+
</button>
293+
</div>
294+
<p class="hint">Paste this string into the hub machine's Settings → Fiesta Workers → "Paste pairing string" field.</p>
295+
}
296+
274297
@if (!string.IsNullOrEmpty(directQrCodeDataUri))
275298
{
276299
<div class="qr-code">
@@ -1126,7 +1149,7 @@
11261149
string? url = null;
11271150
try
11281151
{
1129-
var doc = System.Text.Json.JsonDocument.Parse(result);
1152+
using var doc = System.Text.Json.JsonDocument.Parse(result);
11301153
if (doc.RootElement.TryGetProperty("url", out var urlProp))
11311154
url = urlProp.GetString();
11321155
if (doc.RootElement.TryGetProperty("token", out var tokenProp))
@@ -1155,6 +1178,7 @@
11551178
settings.RemoteUrl = url;
11561179

11571180
ShowStatus("QR code scanned!", "success");
1181+
StateHasChanged();
11581182
}
11591183

11601184
private async Task TunnelLogin()
@@ -1351,8 +1375,16 @@
13511375

13521376
private void TryGenerateFiestaPairingString()
13531377
{
1354-
try { fiestaPairingString = FiestaService.GeneratePairingString(); }
1355-
catch { fiestaPairingString = null; }
1378+
try
1379+
{
1380+
fiestaPairingString = FiestaService.GeneratePairingString();
1381+
}
1382+
catch (Exception ex)
1383+
{
1384+
fiestaPairingString = null;
1385+
Console.WriteLine($"[Settings] Failed to generate pairing string: {ex.Message}");
1386+
ShowStatus($"Could not generate pairing string: {ex.Message}", "error", 8000);
1387+
}
13561388
}
13571389

13581390
private async Task CopyFiestaPairingString()
@@ -1564,6 +1596,11 @@
15641596
WsBridgeServer.ServerPassword = settings.ServerPassword;
15651597
WsBridgeServer.SetCopilotService(CopilotService);
15661598
WsBridgeServer.Start(DevTunnelService.BridgePort, settings.Port);
1599+
if (!WsBridgeServer.IsRunning)
1600+
{
1601+
ShowStatus($"Failed to start bridge server on port {DevTunnelService.BridgePort} — the port may already be in use.", "error", 10000);
1602+
return;
1603+
}
15671604
settings.DirectSharingEnabled = true;
15681605
settings.Save();
15691606
GenerateDirectQrCode();

PolyPilot/PolyPilot.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
<PackageReference Include="Microsoft.Maui.Essentials.AI" Version="10.0.50-ci.main.26126.2" />
8282
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
8383
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.11" />
84-
<PackageReference Include="QRCoder" Version="*" />
85-
<PackageReference Include="ZXing.Net.Maui.Controls" Version="*" />
84+
<PackageReference Include="QRCoder" Version="1.6.0" />
85+
<PackageReference Include="ZXing.Net.Maui.Controls" Version="0.4.0" />
8686
<PackageReference Include="Redth.MauiDevFlow.Agent" Version="0.12.1" />
8787
<PackageReference Include="Redth.MauiDevFlow.Blazor" Version="0.12.1" />
8888
</ItemGroup>

PolyPilot/QrScannerPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ private void LayoutOverlays(double pageWidth, double pageHeight)
5656
overlayRight.WidthRequest = pageWidth - left - cutoutSize;
5757
overlayRight.HeightRequest = cutoutSize;
5858
overlayRight.Margin = new Thickness(0, top, 0, 0);
59+
60+
overlayTop.IsVisible = true;
61+
overlayBottom.IsVisible = true;
62+
overlayLeft.IsVisible = true;
63+
overlayRight.IsVisible = true;
5964
}
6065

6166
protected override async void OnAppearing()

PolyPilot/Services/QrScannerService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class QrScannerService
1010

1111
public Task<string?> ScanAsync()
1212
{
13+
if (_tcs != null && !_tcs.Task.IsCompleted)
14+
return _tcs.Task;
15+
1316
_tcs = new TaskCompletionSource<string?>();
1417

1518
MainThread.BeginInvokeOnMainThread(async () =>

0 commit comments

Comments
 (0)