From 865b3039ccf6eec4f277dbb33296ab767d2ed7ce Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 28 Jul 2024 14:44:15 +0900 Subject: fix: deck uiの通知音が重なる問題 (#14029) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: deck uiの通知音が重なる * docs: Fix: deck uiの通知音が重なる問題 * unexport internal function * fix Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> * chore: improve condition * docs: move js dco comment --------- Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> --- packages/frontend/src/scripts/sound.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'packages/frontend/src/scripts') diff --git a/packages/frontend/src/scripts/sound.ts b/packages/frontend/src/scripts/sound.ts index bba855cd64..814e080811 100644 --- a/packages/frontend/src/scripts/sound.ts +++ b/packages/frontend/src/scripts/sound.ts @@ -124,10 +124,23 @@ export async function loadAudio(url: string, options?: { useCache?: boolean; }) */ export function playMisskeySfx(operationType: OperationType) { const sound = defaultStore.state[`sound_${operationType}`]; - if (sound.type == null || !canPlay || ('userActivation' in navigator && !navigator.userActivation.hasBeenActive)) return; + playMisskeySfxFile(sound); +} + +/** + * サウンド設定形式で指定された音声を再生する + * @param soundStore サウンド設定 + */ +export function playMisskeySfxFile(soundStore: SoundStore) { + // 連続して再生しない + if (!canPlay) return; + // ユーザーアクティベーションが必要な場合はそれがない場合は再生しない + if ('userActivation' in navigator && !navigator.userActivation.hasBeenActive) return; + // サウンドがない場合は再生しない + if (soundStore.type === null || soundStore.type === '_driveFile_' && !soundStore.fileUrl) return; canPlay = false; - playMisskeySfxFile(sound).finally(() => { + playMisskeySfxFileInternal(soundStore).finally(() => { // ごく短時間に音が重複しないように setTimeout(() => { canPlay = true; @@ -135,11 +148,7 @@ export function playMisskeySfx(operationType: OperationType) { }); } -/** - * サウンド設定形式で指定された音声を再生する - * @param soundStore サウンド設定 - */ -export async function playMisskeySfxFile(soundStore: SoundStore) { +async function playMisskeySfxFileInternal(soundStore: SoundStore) { if (soundStore.type === null || (soundStore.type === '_driveFile_' && !soundStore.fileUrl)) { return; } -- cgit v1.2.3-freya