2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-12-22 00:01:58 +00:00
|
|
|
<template>
|
2023-01-06 04:40:17 +00:00
|
|
|
<div class="_gaps_m">
|
2023-01-07 06:09:46 +00:00
|
|
|
<MkSelect v-model="type">
|
2022-12-22 00:01:58 +00:00
|
|
|
<template #label>{{ i18n.ts.sound }}</template>
|
2023-11-27 08:33:42 +00:00
|
|
|
<option v-for="x in soundsTypes" :key="x ?? 'null'" :value="x">{{ getSoundTypeName(x) }}</option>
|
2023-01-07 06:09:46 +00:00
|
|
|
</MkSelect>
|
2023-11-27 08:33:42 +00:00
|
|
|
<div v-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>
|
2023-05-19 11:52:15 +00:00
|
|
|
<MkRange v-model="volume" :min="0" :max="1" :step="0.05" :textConverter="(v) => `${Math.floor(v * 100)}%`">
|
2022-12-22 00:01:58 +00:00
|
|
|
<template #label>{{ i18n.ts.volume }}</template>
|
2023-01-07 06:09:46 +00:00
|
|
|
</MkRange>
|
2022-12-22 00:01:58 +00:00
|
|
|
|
2023-01-06 00:41:14 +00:00
|
|
|
<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>
|
2022-12-22 00:01:58 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-11-27 08:33:42 +00:00
|
|
|
import { ref, computed } from 'vue';
|
|
|
|
import type { SoundType } from '@/scripts/sound.js';
|
2023-01-07 06:09:46 +00:00
|
|
|
import MkSelect from '@/components/MkSelect.vue';
|
2023-01-06 00:41:14 +00:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 06:09:46 +00:00
|
|
|
import MkRange from '@/components/MkRange.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { i18n } from '@/i18n.js';
|
2023-11-27 08:33:42 +00:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 09:32:46 +00:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2024-01-09 04:25:33 +00:00
|
|
|
import { playMisskeySfxFile, soundsTypes, getSoundDuration } from '@/scripts/sound.js';
|
2023-11-27 08:33:42 +00:00
|
|
|
import { selectFile } from '@/scripts/select-file.js';
|
2022-12-22 00:01:58 +00:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2023-11-27 08:33:42 +00:00
|
|
|
type: SoundType;
|
|
|
|
fileId?: string;
|
|
|
|
fileUrl?: string;
|
2022-12-22 00:01:58 +00:00
|
|
|
volume: number;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2023-11-27 08:33:42 +00:00
|
|
|
(ev: 'update', result: { type: SoundType; fileId?: string; fileUrl?: string; volume: number; }): void;
|
2022-12-22 00:01:58 +00:00
|
|
|
}>();
|
|
|
|
|
2023-11-27 08:33:42 +00:00
|
|
|
const type = ref<SoundType>(props.type);
|
|
|
|
const fileId = ref(props.fileId);
|
|
|
|
const fileUrl = ref(props.fileUrl);
|
|
|
|
const fileName = ref<string>('');
|
|
|
|
const volume = ref(props.volume);
|
|
|
|
|
|
|
|
if (type.value === '_driveFile_' && fileId.value) {
|
2024-01-04 09:32:46 +00:00
|
|
|
const apiRes = await misskeyApi('drive/files/show', {
|
2023-11-27 08:33:42 +00:00
|
|
|
fileId: fileId.value,
|
|
|
|
});
|
|
|
|
fileName.value = apiRes.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSoundTypeName(f: SoundType): string {
|
|
|
|
switch (f) {
|
|
|
|
case null:
|
|
|
|
return i18n.ts.none;
|
|
|
|
case '_driveFile_':
|
|
|
|
return i18n.ts._soundSettings.driveFile;
|
|
|
|
default:
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const friendlyFileName = computed<string>(() => {
|
|
|
|
if (fileName.value) {
|
|
|
|
return fileName.value;
|
|
|
|
}
|
|
|
|
if (fileUrl.value) {
|
|
|
|
return fileUrl.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i18n.ts._soundSettings.driveFileWarn;
|
|
|
|
});
|
|
|
|
|
|
|
|
function selectSound(ev) {
|
|
|
|
selectFile(ev.currentTarget ?? ev.target, i18n.ts._soundSettings.driveFile).then(async (file) => {
|
|
|
|
if (!file.type.startsWith('audio')) {
|
|
|
|
os.alert({
|
|
|
|
type: 'warning',
|
|
|
|
title: i18n.ts._soundSettings.driveFileTypeWarn,
|
|
|
|
text: i18n.ts._soundSettings.driveFileTypeWarnDescription,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const duration = await getSoundDuration(file.url);
|
|
|
|
if (duration >= 2000) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
title: i18n.ts._soundSettings.driveFileDurationWarn,
|
|
|
|
text: i18n.ts._soundSettings.driveFileDurationWarnDescription,
|
|
|
|
okText: i18n.ts.continue,
|
|
|
|
cancelText: i18n.ts.cancel,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileUrl.value = file.url;
|
|
|
|
fileName.value = file.name;
|
|
|
|
fileId.value = file.id;
|
|
|
|
});
|
|
|
|
}
|
2022-12-22 00:01:58 +00:00
|
|
|
|
|
|
|
function listen() {
|
2023-11-27 08:33:42 +00:00
|
|
|
if (type.value === '_driveFile_' && (!fileUrl.value || !fileId.value)) {
|
|
|
|
os.alert({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts._soundSettings.driveFileWarn,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-09 04:25:33 +00:00
|
|
|
playMisskeySfxFile(type.value === '_driveFile_' ? {
|
2023-11-27 08:33:42 +00:00
|
|
|
type: '_driveFile_',
|
|
|
|
fileId: fileId.value as string,
|
|
|
|
fileUrl: fileUrl.value as string,
|
|
|
|
volume: volume.value,
|
|
|
|
} : {
|
|
|
|
type: type.value,
|
|
|
|
volume: volume.value,
|
|
|
|
});
|
2022-12-22 00:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2023-11-27 08:33:42 +00:00
|
|
|
if (type.value === '_driveFile_' && !fileUrl.value) {
|
|
|
|
os.alert({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts._soundSettings.driveFileWarn,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.value !== '_driveFile_') {
|
|
|
|
fileUrl.value = undefined;
|
|
|
|
fileName.value = '';
|
|
|
|
fileId.value = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit('update', {
|
|
|
|
type: type.value,
|
|
|
|
fileId: fileId.value,
|
|
|
|
fileUrl: fileUrl.value,
|
|
|
|
volume: volume.value,
|
|
|
|
});
|
|
|
|
|
|
|
|
os.success();
|
2022-12-22 00:01:58 +00:00
|
|
|
}
|
|
|
|
</script>
|
2023-11-27 08:33:42 +00:00
|
|
|
|
|
|
|
<style module>
|
|
|
|
.fileSelectorRoot {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fileSelectorButton {
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fileNotSelected {
|
|
|
|
font-weight: 700;
|
|
|
|
color: var(--infoWarnFg);
|
|
|
|
}
|
|
|
|
</style>
|