fix: AudioContext 复用 + 盲盒加载错误提示 + icon 按钮 aria-label

- #27: panic/blindbox/ShareCardModal/AuthModal 中 icon-only 按钮补 aria-label
- #28: playChime 缓存复用单个 AudioContext,避免超出浏览器 ~6 个上限
- #29: 已完成(上一批次 ApiError.name = "ApiError")
- #30: blindbox lobby fetchRooms 失败时显示"加载失败/点击重试"
- #31: 已完成(theme.ts VALID_THEMES 校验)
This commit is contained in:
2026-02-26 20:25:56 +08:00
parent f4a8fd7fee
commit deba7ab2bb
6 changed files with 41 additions and 5 deletions
+12 -3
View File
@@ -62,9 +62,20 @@ export function fireCelebration() {
setTimeout(frame, 300);
}
let _audioCtx: AudioContext | null = null;
function getAudioContext(): AudioContext {
if (!_audioCtx || _audioCtx.state === "closed") {
_audioCtx = new AudioContext();
}
return _audioCtx;
}
export function playChime() {
try {
const ctx = new AudioContext();
const ctx = getAudioContext();
if (ctx.state === "suspended") ctx.resume();
const gain = ctx.createGain();
gain.connect(ctx.destination);
gain.gain.setValueAtTime(0.15, ctx.currentTime);
@@ -88,8 +99,6 @@ export function playChime() {
osc.start(start);
osc.stop(start + 0.6);
});
setTimeout(() => ctx.close(), 2000);
} catch {
// Audio not available — silent fallback
}