Skip to content

Commit 2c86fae

Browse files
j2rong4cnCopilot
andauthored
feat(video): keep state when switching videos in fullscreen (#495)
* fix(player): improve cleanup logic and remove title assignment * feat: implement keep state functionality for better user experience * fix(video): destroy old stream instances and reload subtitles/danmaku on URL switch * danmaku * subtitle * revert --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent a3ec3ad commit 2c86fae

6 files changed

Lines changed: 192 additions & 153 deletions

File tree

src/hooks/usePath.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
recoverHistory,
1212
clearHistory,
1313
me,
14+
shouldKeepState,
1415
} from "~/store"
1516
import {
1617
fsGet,
@@ -120,7 +121,7 @@ export const usePath = () => {
120121

121122
// handle enter obj that don't know if it is dir or file
122123
const handleObj = async (path: string, index?: number) => {
123-
ObjStore.setState(State.FetchingObj)
124+
shouldKeepState() || ObjStore.setState(State.FetchingObj)
124125
const resp = await getObj(path)
125126
handleRespWithoutNotify(
126127
resp,
@@ -135,7 +136,7 @@ export const usePath = () => {
135136
ObjStore.setHeader(data.header)
136137
ObjStore.setRelated(data.related ?? [])
137138
ObjStore.setRawUrl(data.raw_url)
138-
ObjStore.setState(State.File)
139+
shouldKeepState() || ObjStore.setState(State.File)
139140
}
140141
},
141142
handleErr,
@@ -157,7 +158,7 @@ export const usePath = () => {
157158
if (size !== undefined && pagination.type === "all") {
158159
size = undefined
159160
}
160-
!onlyList &&
161+
if (!onlyList && !shouldKeepState())
161162
ObjStore.setState(append ? State.FetchingMore : State.FetchingObjs)
162163
const resp = await getObjs({ path, index, size, force })
163164
handleRespWithoutNotify(
@@ -179,7 +180,7 @@ export const usePath = () => {
179180
ObjStore.setWriteContentBypass(data.write_content_bypass)
180181
ObjStore.setProvider(data.provider)
181182
ObjStore.setDirectUploadTools(data.direct_upload_tools)
182-
ObjStore.setState(State.Folder)
183+
shouldKeepState() || ObjStore.setState(State.Folder)
183184
},
184185
handleErr,
185186
)

src/pages/home/previews/aliyun_video.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Box, Center } from "@hope-ui/solid"
22
import { Show, createMemo, createSignal, onCleanup, onMount } from "solid-js"
33
import { useRouter, useLink, useFetch } from "~/hooks"
4-
import { getMainColor, getSettingBool, objStore, password } from "~/store"
4+
import {
5+
getMainColor,
6+
getSettingBool,
7+
objStore,
8+
password,
9+
setShouldKeepState,
10+
} from "~/store"
511
import { ObjType, PResp } from "~/types"
612
import { ext, handleResp, notify, r, pathDir, pathJoin } from "~/utils"
713
import Artplayer from "artplayer"
@@ -78,7 +84,6 @@ const Preview = () => {
7884
let option: Option = {
7985
id: pathname(),
8086
container: "#video-player",
81-
title: objStore.obj.name,
8287
volume: 1.0,
8388
autoplay: getSettingBool("video_autoplay"),
8489
autoSize: false,
@@ -420,7 +425,14 @@ const Preview = () => {
420425
})
421426
}
422427
onCleanup(() => {
423-
player?.destroy()
428+
setShouldKeepState(false)
429+
if (player) {
430+
player.fullscreenWeb = false
431+
player.fullscreen = false
432+
player.pip = false
433+
if (player.video) player.video.src = ""
434+
player.destroy()
435+
}
424436
window.clearInterval(interval)
425437
})
426438
const [autoNext, setAutoNext] = createSignal()

0 commit comments

Comments
 (0)