2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="_formRoot">
|
|
|
|
<FormRange
|
|
|
|
v-model="masterVolume"
|
|
|
|
:min="0"
|
|
|
|
:max="1"
|
|
|
|
:step="0.05"
|
|
|
|
:text-converter="(v) => `${Math.floor(v * 100)}%`"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label>{{ i18n.ts.masterVolume }}</template>
|
|
|
|
</FormRange>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<FormSection>
|
|
|
|
<template #label>{{ i18n.ts.sounds }}</template>
|
|
|
|
<FormButton
|
|
|
|
v-for="type in Object.keys(sounds)"
|
|
|
|
:key="type"
|
|
|
|
style="margin-bottom: 8px"
|
|
|
|
@click="edit(type)"
|
|
|
|
>
|
|
|
|
{{ i18n.t("_sfx." + type) }}
|
|
|
|
<template #suffix>{{
|
|
|
|
sounds[type].type || i18n.ts.none
|
|
|
|
}}</template>
|
|
|
|
<template #suffixIcon
|
|
|
|
><i class="ph-caret-down ph-bold ph-lg"></i
|
|
|
|
></template>
|
|
|
|
</FormButton>
|
|
|
|
</FormSection>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<FormButton danger class="_formBlock" @click="reset()"
|
|
|
|
><i class="ph-arrow-clockwise ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.default }}</FormButton
|
|
|
|
>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-05 15:51:05 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { computed, ref } from "vue";
|
|
|
|
import FormRange from "@/components/form/range.vue";
|
|
|
|
import FormButton from "@/components/MkButton.vue";
|
|
|
|
import FormSection from "@/components/form/section.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { ColdDeviceStorage } from "@/store";
|
|
|
|
import { playFile } from "@/scripts/sound";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
2022-05-05 15:51:05 +02:00
|
|
|
|
|
|
|
const masterVolume = computed({
|
|
|
|
get: () => {
|
2023-04-08 02:01:42 +02:00
|
|
|
return ColdDeviceStorage.get("sound_masterVolume");
|
2022-05-05 15:51:05 +02:00
|
|
|
},
|
|
|
|
set: (value) => {
|
2023-04-08 02:01:42 +02:00
|
|
|
ColdDeviceStorage.set("sound_masterVolume", value);
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
2022-05-05 15:51:05 +02:00
|
|
|
});
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const volumeIcon = computed(() =>
|
|
|
|
masterVolume.value === 0
|
|
|
|
? "ph-speaker-none ph-bold ph-lg"
|
|
|
|
: "ph-speaker-high ph-bold ph-lg"
|
|
|
|
);
|
2022-05-05 15:51:05 +02:00
|
|
|
|
|
|
|
const sounds = ref({
|
2023-04-08 02:01:42 +02:00
|
|
|
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"),
|
2022-05-05 15:51:05 +02:00
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const soundsTypes = await os.api("get-sounds");
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:05 +02:00
|
|
|
async function edit(type) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const { canceled, result } = await os.form(i18n.t("_sfx." + type), {
|
2022-05-05 15:51:05 +02:00
|
|
|
type: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "enum",
|
|
|
|
enum: soundsTypes.map((x) => ({
|
2022-05-05 15:51:05 +02:00
|
|
|
value: x,
|
|
|
|
label: x == null ? i18n.ts.none : x,
|
|
|
|
})),
|
|
|
|
label: i18n.ts.sound,
|
|
|
|
default: sounds.value[type].type,
|
|
|
|
},
|
|
|
|
volume: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "range",
|
2022-08-26 08:39:31 +02:00
|
|
|
min: 0,
|
2022-05-05 15:51:05 +02:00
|
|
|
max: 1,
|
|
|
|
step: 0.05,
|
|
|
|
textConverter: (v) => `${Math.floor(v * 100)}%`,
|
|
|
|
label: i18n.ts.volume,
|
2022-06-20 10:38:49 +02:00
|
|
|
default: sounds.value[type].volume,
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
2022-05-05 15:51:05 +02:00
|
|
|
listen: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "button",
|
2022-05-05 15:51:05 +02:00
|
|
|
content: i18n.ts.listen,
|
|
|
|
action: (_, values) => {
|
|
|
|
playFile(values.type, values.volume);
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
|
|
|
},
|
2022-05-05 15:51:05 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:05 +02:00
|
|
|
const v = {
|
|
|
|
type: result.type,
|
|
|
|
volume: result.volume,
|
|
|
|
};
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
ColdDeviceStorage.set("sound_" + type, v);
|
2022-05-05 15:51:05 +02:00
|
|
|
sounds.value[type] = v;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:05 +02:00
|
|
|
function reset() {
|
|
|
|
for (const sound of Object.keys(sounds.value)) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const v = ColdDeviceStorage.default["sound_" + sound];
|
|
|
|
ColdDeviceStorage.set("sound_" + sound, v);
|
2022-05-05 15:51:05 +02:00
|
|
|
sounds.value[sound] = v;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.sounds,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-speaker-high ph-bold ph-lg",
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
</script>
|