fix(web): reveal NFC peripherals after detection

This commit is contained in:
Miayui
2026-09-21 11:04:18 +08:00
parent 448c8b31a0
commit b3bd90f748
9 changed files with 75 additions and 14 deletions
+17 -6
View File
@@ -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 @@
<div>${device.actions.slice(0, 8).map((action) => `<span>${escapeHtml(action)}</span>`).join("")}</div>
</article>`).join("") : nfcPet ? "" : `
<div class="v2-extension-empty">
<i data-lucide="link-2-off"></i><div><strong>当前没有已绑定外设</strong><span>外设绑定 NFC 后将持续显示,解除绑定后移除</span></div>
<i data-lucide="scan-line"></i><div><strong>等待 NFC 外设靠近</strong><span>检测到已绑定的 NFC 后,外设将在本次运行期间持续显示</span></div>
</div>`}
</div>
<footer class="v2-extension-linkage" data-active="${String(Boolean(visibleLastAction))}">