diff --git a/anime/routes.py b/anime/routes.py index fc34140b849fd51c68035fdd29ac3db57dbb998b..51d0f2d02aa027a53fdaac5b862e91fb03b56858 100644 --- a/anime/routes.py +++ b/anime/routes.py @@ -51,8 +51,6 @@ def start_watching(request: Request) -> None: cwd=anime_dir, ) request.app.state.pid = ret.pid - ret.wait() - request.app.state.pid = None @router.post("/player/offset") diff --git a/frontend/src/components/PlayerComponent.vue b/frontend/src/components/PlayerComponent.vue index 3e75a5a308c5363a33c579daebef891d1fb8ca84..fcf01dcba27d0f96834001b8da658be50a03ad04 100644 --- a/frontend/src/components/PlayerComponent.vue +++ b/frontend/src/components/PlayerComponent.vue @@ -1,40 +1,29 @@ <script setup> import { ActionBar, ActionBarButton } from 'vant'; import { postRequest } from '@/utils' -import { ref } from 'vue' +import { useBackendStateStore } from '@/stores/backendState'; -const is_playing = ref(false); +const backendStore = useBackendStateStore(); async function offsetRequest(offset, forward) { await postRequest(`/api/player/offset`, { offset, forward, }) + await backendStore.updatePlaying() } async function playPauseRequest() { await postRequest(`/api/player/play-pause`) - update_state() + await backendStore.updatePlaying() } - -function update_state() { - fetch('/api/player/playing').then((response) => { - if (response.ok) { - response.json().then((resp_json) => { - is_playing.value = resp_json.playing - }) - } - }) -} - -update_state() </script> <template> <ActionBar> <ActionBarButton icon="arrow-double-left" @click="offsetRequest(85, false)"></ActionBarButton> <ActionBarButton icon="arrow-left" @click="offsetRequest(10, false)"></ActionBarButton> - <ActionBarButton :icon="is_playing ? 'pause' : 'play'" @click="playPauseRequest()"></ActionBarButton> + <ActionBarButton :icon="backendStore.backendState.playing ? 'pause' : 'play'" @click="playPauseRequest()"></ActionBarButton> <ActionBarButton icon="arrow" @click="offsetRequest(10, true)"></ActionBarButton> <ActionBarButton icon="arrow-double-right" @click="offsetRequest(85, true)"></ActionBarButton> </ActionBar> diff --git a/frontend/src/stores/backendState.js b/frontend/src/stores/backendState.js new file mode 100644 index 0000000000000000000000000000000000000000..dc5af41dcda477552536007faeb9495465096694 --- /dev/null +++ b/frontend/src/stores/backendState.js @@ -0,0 +1,25 @@ +import { defineStore } from "pinia"; +import { ref } from 'vue' + +export const useBackendStateStore = defineStore('backendState', () => { + const backendState = ref({ + canWatch: false, + playing: false + }) + + async function updateCanWatch() { + const response = await fetch("/api/can-start-watching"); + backendState.value.canWatch = response.ok; + } + + + async function updatePlaying() { + const response = await fetch('/api/player/playing'); + if (response.ok) { + let resp_json = await response.json() + backendState.value.playing = resp_json.playing + } + } + + return { backendState, updateCanWatch, updatePlaying } +}); \ No newline at end of file diff --git a/frontend/src/stores/counter.js b/frontend/src/stores/counter.js deleted file mode 100644 index b6757ba5723c5b89b35d011b9558d025bbcde402..0000000000000000000000000000000000000000 --- a/frontend/src/stores/counter.js +++ /dev/null @@ -1,12 +0,0 @@ -import { ref, computed } from 'vue' -import { defineStore } from 'pinia' - -export const useCounterStore = defineStore('counter', () => { - const count = ref(0) - const doubleCount = computed(() => count.value * 2) - function increment() { - count.value++ - } - - return { count, doubleCount, increment } -}) diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index 177de7a5f8345ecc0173eb44d4f521d6447d21d7..33663f84389d3ac068e742aac51bbf54dd0ca049 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -1,4 +1,5 @@ import { showFailToast } from 'vant'; +import { usePlayingStore } from '@/stores/playing'; async function postRequest(url, data) { const response = await fetch(url, { @@ -17,7 +18,6 @@ async function postRequest(url, data) { return resp_data } - export { - postRequest + postRequest, } \ No newline at end of file diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index f19dba1a286e5b47efa79e29ac9de20262cffbc4..1a63b6ce20e0081c6bae2107f640fc6925a2c6e2 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -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 />