From ccb951f11e8cc3c884eef799bef82d09f138d28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sun, 26 Nov 2023 14:38:34 +0900 Subject: [PATCH] chore: create AudioContext when it is needed (#12460) --- packages/frontend/src/scripts/sound.ts | 5 ++++- packages/frontend/src/widgets/WidgetJobQueue.vue | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/scripts/sound.ts b/packages/frontend/src/scripts/sound.ts index 47ec4171af..d28d629227 100644 --- a/packages/frontend/src/scripts/sound.ts +++ b/packages/frontend/src/scripts/sound.ts @@ -5,7 +5,7 @@ import { defaultStore } from '@/store.js'; -const ctx = new AudioContext(); +let ctx: AudioContext; const cache = new Map(); let canPlay = true; @@ -65,6 +65,9 @@ export const soundsTypes = [ ] as const; export async function loadAudio(file: string, useCache = true) { + if (ctx == null) { + ctx = new AudioContext(); + } if (useCache && cache.has(file)) { return cache.get(file)!; } diff --git a/packages/frontend/src/widgets/WidgetJobQueue.vue b/packages/frontend/src/widgets/WidgetJobQueue.vue index fa82997570..8c990e8e49 100644 --- a/packages/frontend/src/widgets/WidgetJobQueue.vue +++ b/packages/frontend/src/widgets/WidgetJobQueue.vue @@ -58,6 +58,7 @@ import { useStream } from '@/stream.js'; import number from '@/filters/number.js'; import * as sound from '@/scripts/sound.js'; import { deepClone } from '@/scripts/clone.js'; +import { defaultStore } from '@/store.js'; const name = 'jobQueue'; @@ -102,7 +103,9 @@ const prev = reactive({} as typeof current); let jammedAudioBuffer: AudioBuffer | null = $ref(null); let jammedSoundNodePlaying: boolean = $ref(false); -sound.loadAudio('syuilo/queue-jammed').then(buf => jammedAudioBuffer = buf); +if (defaultStore.state.sound_masterVolume) { + sound.loadAudio('syuilo/queue-jammed').then(buf => jammedAudioBuffer = buf); +} for (const domain of ['inbox', 'deliver']) { prev[domain] = deepClone(current[domain]);