mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 03:13:07 +02:00
Refactor settings/sounds to use Composition API (#8594)
* refactor(client): refactor settings/sounds to use Composition API * Apply review suggestion from @Johann150 Co-authored-by: Johann150 <johann@qwertqwefsday.eu> * chore(client): remove old sound reference Co-authored-by: Johann150 <johann@qwertqwefsday.eu>
This commit is contained in:
parent
31c73fdfa2
commit
a6c138600f
1 changed files with 76 additions and 90 deletions
|
@ -1,24 +1,24 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="_formRoot">
|
<div class="_formRoot">
|
||||||
<FormRange v-model="masterVolume" :min="0" :max="1" :step="0.05" :text-converter="(v) => `${Math.floor(v * 100)}%`" class="_formBlock">
|
<FormRange v-model="masterVolume" :min="0" :max="1" :step="0.05" :text-converter="(v) => `${Math.floor(v * 100)}%`" class="_formBlock">
|
||||||
<template #label>{{ $ts.masterVolume }}</template>
|
<template #label>{{ i18n.ts.masterVolume }}</template>
|
||||||
</FormRange>
|
</FormRange>
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ $ts.sounds }}</template>
|
<template #label>{{ i18n.ts.sounds }}</template>
|
||||||
<FormLink v-for="type in Object.keys(sounds)" :key="type" style="margin-bottom: 8px;" @click="edit(type)">
|
<FormLink v-for="type in Object.keys(sounds)" :key="type" style="margin-bottom: 8px;" @click="edit(type)">
|
||||||
{{ $t('_sfx.' + type) }}
|
{{ $t('_sfx.' + type) }}
|
||||||
<template #suffix>{{ sounds[type].type || $ts.none }}</template>
|
<template #suffix>{{ sounds[type].type || i18n.ts.none }}</template>
|
||||||
<template #suffixIcon><i class="fas fa-chevron-down"></i></template>
|
<template #suffixIcon><i class="fas fa-chevron-down"></i></template>
|
||||||
</FormLink>
|
</FormLink>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
||||||
<FormButton danger class="_formBlock" @click="reset()"><i class="fas fa-redo"></i> {{ $ts.default }}</FormButton>
|
<FormButton danger class="_formBlock" @click="reset()"><i class="fas fa-redo"></i> {{ i18n.ts.default }}</FormButton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { computed, defineExpose, ref } from 'vue';
|
||||||
import FormRange from '@/components/form/range.vue';
|
import FormRange from '@/components/form/range.vue';
|
||||||
import FormButton from '@/components/ui/button.vue';
|
import FormButton from '@/components/ui/button.vue';
|
||||||
import FormLink from '@/components/form/link.vue';
|
import FormLink from '@/components/form/link.vue';
|
||||||
|
@ -27,6 +27,28 @@ import * as os from '@/os';
|
||||||
import { ColdDeviceStorage } from '@/store';
|
import { ColdDeviceStorage } from '@/store';
|
||||||
import { playFile } from '@/scripts/sound';
|
import { playFile } from '@/scripts/sound';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
|
const masterVolume = computed({
|
||||||
|
get: () => {
|
||||||
|
return ColdDeviceStorage.get('sound_masterVolume');
|
||||||
|
},
|
||||||
|
set: (value) => {
|
||||||
|
ColdDeviceStorage.set('sound_masterVolume', value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const volumeIcon = computed(() => masterVolume.value === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up');
|
||||||
|
|
||||||
|
const sounds = ref({
|
||||||
|
note: ColdDeviceStorage.get('sound_note'),
|
||||||
|
noteMy: ColdDeviceStorage.get('sound_noteMy'),
|
||||||
|
notification: ColdDeviceStorage.get('sound_notification'),
|
||||||
|
chat: ColdDeviceStorage.get('sound_chat'),
|
||||||
|
chatBg: ColdDeviceStorage.get('sound_chatBg'),
|
||||||
|
antenna: ColdDeviceStorage.get('sound_antenna'),
|
||||||
|
channel: ColdDeviceStorage.get('sound_channel'),
|
||||||
|
});
|
||||||
|
|
||||||
const soundsTypes = [
|
const soundsTypes = [
|
||||||
null,
|
null,
|
||||||
|
@ -55,94 +77,58 @@ const soundsTypes = [
|
||||||
'noizenecio/kick_gaba2',
|
'noizenecio/kick_gaba2',
|
||||||
];
|
];
|
||||||
|
|
||||||
export default defineComponent({
|
async function edit(type) {
|
||||||
components: {
|
const { canceled, result } = await os.form(i18n.t('_sfx.' + type), {
|
||||||
FormLink,
|
type: {
|
||||||
FormButton,
|
type: 'enum',
|
||||||
FormRange,
|
enum: soundsTypes.map(x => ({
|
||||||
FormSection,
|
value: x,
|
||||||
},
|
label: x == null ? i18n.ts.none : x,
|
||||||
|
})),
|
||||||
emits: ['info'],
|
label: i18n.ts.sound,
|
||||||
|
default: sounds.value[type].type,
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
[symbols.PAGE_INFO]: {
|
|
||||||
title: this.$ts.sounds,
|
|
||||||
icon: 'fas fa-music',
|
|
||||||
bg: 'var(--bg)',
|
|
||||||
},
|
|
||||||
sounds: {},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
masterVolume: { // TODO: (外部)関数にcomputedを使うのはアレなので直す
|
|
||||||
get() { return ColdDeviceStorage.get('sound_masterVolume'); },
|
|
||||||
set(value) { ColdDeviceStorage.set('sound_masterVolume', value); }
|
|
||||||
},
|
},
|
||||||
volumeIcon() {
|
volume: {
|
||||||
return this.masterVolume === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up';
|
type: 'range',
|
||||||
}
|
mim: 0,
|
||||||
},
|
max: 1,
|
||||||
|
step: 0.05,
|
||||||
created() {
|
textConverter: (v) => `${Math.floor(v * 100)}%`,
|
||||||
this.sounds.note = ColdDeviceStorage.get('sound_note');
|
label: i18n.ts.volume,
|
||||||
this.sounds.noteMy = ColdDeviceStorage.get('sound_noteMy');
|
default: sounds.value[type].volume
|
||||||
this.sounds.notification = ColdDeviceStorage.get('sound_notification');
|
|
||||||
this.sounds.chat = ColdDeviceStorage.get('sound_chat');
|
|
||||||
this.sounds.chatBg = ColdDeviceStorage.get('sound_chatBg');
|
|
||||||
this.sounds.antenna = ColdDeviceStorage.get('sound_antenna');
|
|
||||||
this.sounds.channel = ColdDeviceStorage.get('sound_channel');
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
async edit(type) {
|
|
||||||
const { canceled, result } = await os.form(this.$t('_sfx.' + type), {
|
|
||||||
type: {
|
|
||||||
type: 'enum',
|
|
||||||
enum: soundsTypes.map(x => ({
|
|
||||||
value: x,
|
|
||||||
label: x == null ? this.$ts.none : x,
|
|
||||||
})),
|
|
||||||
label: this.$ts.sound,
|
|
||||||
default: this.sounds[type].type,
|
|
||||||
},
|
|
||||||
volume: {
|
|
||||||
type: 'range',
|
|
||||||
mim: 0,
|
|
||||||
max: 1,
|
|
||||||
step: 0.05,
|
|
||||||
textConverter: (v) => `${Math.floor(v * 100)}%`,
|
|
||||||
label: this.$ts.volume,
|
|
||||||
default: this.sounds[type].volume
|
|
||||||
},
|
|
||||||
listen: {
|
|
||||||
type: 'button',
|
|
||||||
content: this.$ts.listen,
|
|
||||||
action: (_, values) => {
|
|
||||||
playFile(values.type, values.volume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (canceled) return;
|
|
||||||
|
|
||||||
const v = {
|
|
||||||
type: result.type,
|
|
||||||
volume: result.volume,
|
|
||||||
};
|
|
||||||
|
|
||||||
ColdDeviceStorage.set('sound_' + type, v);
|
|
||||||
this.sounds[type] = v;
|
|
||||||
},
|
},
|
||||||
|
listen: {
|
||||||
reset() {
|
type: 'button',
|
||||||
for (const sound of Object.keys(this.sounds)) {
|
content: i18n.ts.listen,
|
||||||
const v = ColdDeviceStorage.default['sound_' + sound];
|
action: (_, values) => {
|
||||||
ColdDeviceStorage.set('sound_' + sound, v);
|
playFile(values.type, values.volume);
|
||||||
this.sounds[sound] = v;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if (canceled) return;
|
||||||
|
|
||||||
|
const v = {
|
||||||
|
type: result.type,
|
||||||
|
volume: result.volume,
|
||||||
|
};
|
||||||
|
|
||||||
|
ColdDeviceStorage.set('sound_' + type, v);
|
||||||
|
sounds.value[type] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
for (const sound of Object.keys(sounds.value)) {
|
||||||
|
const v = ColdDeviceStorage.default['sound_' + sound];
|
||||||
|
ColdDeviceStorage.set('sound_' + sound, v);
|
||||||
|
sounds.value[sound] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
[symbols.PAGE_INFO]: {
|
||||||
|
title: i18n.ts.sounds,
|
||||||
|
icon: 'fas fa-music',
|
||||||
|
bg: 'var(--bg)',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue