Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): ドライブの音声が再生できない場合の処理を追加 #14073

Merged
merged 17 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Fix: リアクションしたユーザー一覧のユーザー名がはみ出る問題を修正
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/672)
- Fix: `/share`ページにおいて絵文字ピッカーを開くことができない問題を修正
- Fix: サウンドにドライブの音声を使用している際にドライブの音声が再生できなくなると設定が変更できなくなる問題を修正

### Server
- Feat: レートリミット制限に引っかかったときに`Retry-After`ヘッダーを返すように (#13949)
Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7581,6 +7581,10 @@ export interface Locale extends ILocale {
* 長い音声を使用するとMisskeyの使用に支障をきたす可能性があります。それでも続行しますか?
*/
"driveFileDurationWarnDescription": string;
/**
* 音声が読み込めませんでした。設定を変更してください
*/
"driveFileError": string;
};
"_ago": {
/**
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ _soundSettings:
driveFileTypeWarnDescription: "音声ファイルを選択してください"
driveFileDurationWarn: "音声が長すぎます"
driveFileDurationWarnDescription: "長い音声を使用するとMisskeyの使用に支障をきたす可能性があります。それでも続行しますか?"
driveFileError: "音声が読み込めませんでした。設定を変更してください"

_ago:
future: "未来"
Expand Down
44 changes: 39 additions & 5 deletions packages/frontend/src/pages/settings/sounds.sound.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.sound }}</template>
<option v-for="x in soundsTypes" :key="x ?? 'null'" :value="x">{{ getSoundTypeName(x) }}</option>
</MkSelect>
<div v-if="type === '_driveFile_'" :class="$style.fileSelectorRoot">
<div v-if="type === '_driveFile_' && driveFileError === true" :class="$style.fileSelectorRoot">
<MkButton :class="$style.fileSelectorButton" inline rounded primary @click="selectSound">{{ i18n.ts.selectFile }}</MkButton>
<div :class="$style.fileErrorRoot">
<MkCondensedLine>{{ i18n.ts._soundSettings.driveFileError }}</MkCondensedLine>
</div>
</div>
<div v-else-if="type === '_driveFile_'" :class="$style.fileSelectorRoot">
<MkButton :class="$style.fileSelectorButton" inline rounded primary @click="selectSound">{{ i18n.ts.selectFile }}</MkButton>
<div :class="['_nowrap', !fileUrl && $style.fileNotSelected]">{{ friendlyFileName }}</div>
</div>
Expand All @@ -19,13 +25,13 @@ SPDX-License-Identifier: AGPL-3.0-only

<div class="_buttons">
<MkButton inline @click="listen"><i class="ti ti-player-play"></i> {{ i18n.ts.listen }}</MkButton>
<MkButton inline primary @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
<MkButton inline primary :disabled="hasChanged === false || driveFileError === true" @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
</div>
</div>
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue';
import { ref, computed, watch } from 'vue';
import type { SoundType } from '@/scripts/sound.js';
import MkSelect from '@/components/MkSelect.vue';
import MkButton from '@/components/MkButton.vue';
Expand All @@ -51,13 +57,18 @@ const type = ref<SoundType>(props.type);
const fileId = ref(props.fileId);
const fileUrl = ref(props.fileUrl);
const fileName = ref<string>('');
const driveFileError = ref(false);
const hasChanged = ref(false);
const volume = ref(props.volume);

if (type.value === '_driveFile_' && fileId.value) {
const apiRes = await misskeyApi('drive/files/show', {
await misskeyApi('drive/files/show', {
fileId: fileId.value,
}).then((res) => {
fileName.value = res.name;
}).catch((res) => {
driveFileError.value = true;
});
fileName.value = apiRes.name;
}

function getSoundTypeName(f: SoundType): string {
Expand Down Expand Up @@ -107,9 +118,21 @@ function selectSound(ev) {
fileUrl.value = file.url;
fileName.value = file.name;
fileId.value = file.id;
driveFileError.value = false;
hasChanged.value = true;
});
}

watch([type, volume], ([typeTo, volumeTo], [typeFrom, volumeFrom]) => {
if (typeFrom !== typeTo && typeTo !== '_driveFile_') {
fileUrl.value = undefined;
fileName.value = '';
fileId.value = undefined;
driveFileError.value = false;
}
hasChanged.value = true;
});

function listen() {
if (type.value === '_driveFile_' && (!fileUrl.value || !fileId.value)) {
os.alert({
Expand All @@ -131,6 +154,10 @@ function listen() {
}

function save() {
if (hasChanged.value === false || driveFileError.value === true) {
return;
}

if (type.value === '_driveFile_' && !fileUrl.value) {
os.alert({
type: 'warning',
Expand Down Expand Up @@ -163,6 +190,13 @@ function save() {
gap: 8px;
}

.fileErrorRoot {
flex-grow: 1;
min-width: 0;
font-weight: 700;
color: var(--error);
}

.fileSelectorButton {
flex-shrink: 0;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/src/pages/settings/sounds.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder v-for="type in operationTypes" :key="type">
<template #label>{{ i18n.ts._sfx[type] }}</template>
<template #suffix>{{ getSoundTypeName(sounds[type].type) }}</template>

<XSound :type="sounds[type].type" :volume="sounds[type].volume" :fileId="sounds[type].fileId" :fileUrl="sounds[type].fileUrl" @update="(res) => updated(type, res)"/>
<Suspense>
<template #default>
<XSound :type="sounds[type].type" :volume="sounds[type].volume" :fileId="sounds[type].fileId" :fileUrl="sounds[type].fileUrl" @update="(res) => updated(type, res)"/>
</template>
<template #fallback>
<MkLoading/>
</template>
</Suspense>
</MkFolder>
</div>
</FormSection>
Expand Down
24 changes: 19 additions & 5 deletions packages/frontend/src/scripts/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ export function playMisskeySfx(operationType: OperationType) {
if (sound.type == null || !canPlay || ('userActivation' in navigator && !navigator.userActivation.hasBeenActive)) return;

canPlay = false;
playMisskeySfxFile(sound).finally(() => {
playMisskeySfxFile(sound).then((succeed) => {
if (!succeed && sound.type === '_driveFile_') {
// ドライブファイルが存在しない場合はデフォルトのサウンドを再生する
const soundName = defaultStore.def[`sound_${operationType}`].default.type as Exclude<SoundType, '_driveFile_'>;
if (_DEV_) console.log(`Failed to play sound: ${sound.fileUrl}, so play default sound: ${soundName}`);
playMisskeySfxFile({
type: soundName,
volume: sound.volume,
});
}
}).finally(() => {
// ごく短時間に音が重複しないように
setTimeout(() => {
canPlay = true;
Expand All @@ -138,20 +148,24 @@ export function playMisskeySfx(operationType: OperationType) {
/**
* サウンド設定形式で指定された音声を再生する
* @param soundStore サウンド設定
* @returns 再生が成功したかどうか
*/
export async function playMisskeySfxFile(soundStore: SoundStore) {
if (soundStore.type === null || (soundStore.type === '_driveFile_' && !soundStore.fileUrl)) {
return;
return false;
}
const masterVolume = defaultStore.state.sound_masterVolume;
if (isMute() || masterVolume === 0 || soundStore.volume === 0) {
return;
return true; // ミュート時は成功として扱う
}
const url = soundStore.type === '_driveFile_' ? soundStore.fileUrl : `/client-assets/sounds/${soundStore.type}.mp3`;
const buffer = await loadAudio(url);
if (!buffer) return;
const buffer = await loadAudio(url).catch(() => {
return undefined;
});
if (!buffer) return false;
const volume = soundStore.volume * masterVolume;
createSourceNode(buffer, { volume }).soundSource.start();
return true;
}

export async function playUrl(url: string, opts: {
Expand Down
Loading