Added backendState for playing and canWatch.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2024-05-02 10:26:22 +02:00
parent 24937da840
commit bcf991a3b1
6 changed files with 45 additions and 42 deletions

View File

@ -1,21 +1,23 @@
<script setup>
import PlayerComponent from '@/components/PlayerComponent.vue';
import { Space, Button } from 'vant';
import { ref } from 'vue';
import { postRequest } from '@/utils';
import { useBackendStateStore } from '@/stores/backendState'
const can_watch = ref(false);
const backendStateStore = useBackendStateStore()
fetch("/api/can-start-watching").then((response) => {
can_watch.value = response.ok
})
backendStateStore.updateCanWatch()
async function kill(...names) {
postRequest("/api/kill", { names })
function kill(...names) {
postRequest("/api/kill", { names }).then(() => {
setTimeout(() => backendStateStore.updatePlaying(), 500)
})
}
async function startWatching() {
await postRequest("/api/start-watching")
function startWatching() {
postRequest("/api/start-watching").then(() => {
setTimeout(() => backendStateStore.updatePlaying(), 500)
})
}
</script>
@ -23,7 +25,8 @@ async function startWatching() {
<Space fill direction="vertical" :size="20">
<Button type="warning" round size="large" @click="kill('mpv')">Убить MPV</Button>
<Button type="danger" round size="large" @click="kill('awatch', 'mpv')">Убить awatch</Button>
<Button type="primary" round size="large" :disabled="!can_watch" @click="startWatching">Начать потребление
<Button type="primary" round size="large" :disabled="!backendStateStore.backendState.canWatch"
@click="startWatching">Начать потребление
анимы</Button>
</Space>
<PlayerComponent />