From b3bd90f7482d5f58827085b1052d390ae3cf0408 Mon Sep 17 00:00:00 2001
From: Miayui <774713819@qq.com>
Date: Mon, 21 Sep 2026 11:04:18 +0800
Subject: [PATCH] fix(web): reveal NFC peripherals after detection
---
apps/web-console/index.html | 2 +-
apps/web-console/self-extension.js | 23 ++++++++++++-----
apps/web-console/service-worker.js | 2 +-
.../application/extension_toy_publisher.py | 11 ++++++++
tests/e2e/test_seat_web_api.py | 4 +--
tests/unit/test_extension_toy_publisher.py | 25 +++++++++++++++++++
.../test_frontend_performance_contract.py | 2 +-
tests/unit/test_nfc_frontend_contract.py | 6 ++---
.../test_self_extension_nfc_sync_contract.py | 14 +++++++++++
9 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/apps/web-console/index.html b/apps/web-console/index.html
index d3bc96f..71e1aa0 100755
--- a/apps/web-console/index.html
+++ b/apps/web-console/index.html
@@ -44,7 +44,7 @@
-
+
diff --git a/apps/web-console/self-extension.js b/apps/web-console/self-extension.js
index 6427c58..0803621 100644
--- a/apps/web-console/self-extension.js
+++ b/apps/web-console/self-extension.js
@@ -378,6 +378,7 @@
state: "stopped",
topic: "extension/toy",
burst_published_count: 0,
+ detected_nfc_ids: [],
last_error: null,
};
let peripheralCatalogRevision = null;
@@ -4015,6 +4016,9 @@
active_extension_names: Array.isArray(value.active_extension_names)
? value.active_extension_names.map((item) => String(item || "")).filter(Boolean)
: [],
+ detected_nfc_ids: Array.isArray(value.detected_nfc_ids)
+ ? value.detected_nfc_ids.map(normalizeCardUid).filter(Boolean)
+ : [],
last_delivery_status: value.last_delivery_status || null,
last_error: value.last_error || null,
};
@@ -4035,11 +4039,14 @@
function applyNfcSnapshot(value, { announce = true } = {}) {
if (!value || typeof value !== "object") return;
if (value.pet_cards) applyPetCardSnapshot(value.pet_cards);
- if (value.extension_toy) {
- applyExtensionToySnapshot(value.extension_toy, { announce });
- }
+ const extensionToyChanged = value.extension_toy
+ ? applyExtensionToySnapshot(value.extension_toy, { announce })
+ : false;
const revision = Number(value.revision ?? -1);
- if (revision === nfcSnapshot.revision) return;
+ if (revision === nfcSnapshot.revision) {
+ if (extensionToyChanged) renderUnifiedExtensionView?.();
+ return;
+ }
if (Array.isArray(value.legacy_profiles) && value.legacy_profiles.length) {
importLegacyProfiles(value.legacy_profiles);
}
@@ -4229,6 +4236,7 @@
reader: nfcSnapshot.reader,
card: nfcSnapshot.card,
},
+ detectedExtensionNfcIds: extensionToySnapshot.detected_nfc_ids,
pets: petCardSnapshot,
localDevices: state.devices.map((device) => ({
id: device.id,
@@ -4331,7 +4339,10 @@
item.enabled === false ? `${actionName}(已停用)` : actionName,
);
});
- const devices = [...grouped.values()];
+ const detectedNfcIds = new Set(extensionToySnapshot.detected_nfc_ids);
+ const devices = [...grouped.values()].filter(
+ (device) => detectedNfcIds.has(normalizeCardUid(device.cardUid)),
+ );
const lastAction = snapshot?.extension?.last_action;
const lastResult = snapshot?.extension?.result;
const nfcCapabilities = nfcDevice
@@ -4414,7 +4425,7 @@
${device.actions.slice(0, 8).map((action) => `${escapeHtml(action)}`).join("")}
`).join("") : nfcPet ? "" : `
-
当前没有已绑定外设外设绑定 NFC 后将持续显示,解除绑定后移除
+
等待 NFC 外设靠近检测到已绑定的 NFC 后,外设将在本次运行期间持续显示
`}