Skip to content

Commit 4836f98

Browse files
committed
fix: unable to open video settings and subtitle matching failed
1 parent fade5d4 commit 4836f98

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

electron-builder.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ afterSign: scripts/notarize.js
6969
releaseInfo:
7070
releaseNotes: |
7171
添加检查更新发生错误的提示信息
72+
修复初次播放视频时无法显示设置的问题
73+
修复自动匹配字幕无法显示的问题

src/renderer/src/components/modules/player/loading/PlayerProvider.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,25 @@ export const VideoProvider: FC<PropsWithChildren> = ({ children }) => {
2929

3030
// 当上方 useQuery 获取弹幕成功后,会触发下方 useEffect, 保存到历史记录并开始播放
3131
useEffect(() => {
32-
if (danmakuData && currentMatchedVideo && hash) {
33-
saveToHistory({
34-
...currentMatchedVideo,
35-
hash,
36-
danmaku: danmakuData,
37-
path: url,
38-
})
39-
setLoadingProgress(LoadingStatus.READY_PLAY)
40-
const timeoutId = setTimeout(() => {
41-
setLoadingProgress(LoadingStatus.START_PLAY)
42-
}, 100)
43-
return () => clearTimeout(timeoutId)
32+
let timeoutId: NodeJS.Timeout
33+
const handleSaveToHistory = async () => {
34+
if (danmakuData && currentMatchedVideo && hash) {
35+
await saveToHistory({
36+
...currentMatchedVideo,
37+
hash,
38+
danmaku: danmakuData,
39+
path: url,
40+
})
41+
setLoadingProgress(LoadingStatus.READY_PLAY)
42+
timeoutId = setTimeout(() => {
43+
setLoadingProgress(LoadingStatus.START_PLAY)
44+
}, 100)
45+
}
46+
}
47+
handleSaveToHistory()
48+
return () => {
49+
clearTimeout(timeoutId)
4450
}
45-
return () => {}
4651
}, [danmakuData, currentMatchedVideo])
4752

4853
if (loadingProgress !== null && loadingProgress < LoadingStatus.START_PLAY) {
@@ -53,11 +58,11 @@ export const VideoProvider: FC<PropsWithChildren> = ({ children }) => {
5358
{/* 如果在 useMatchAnimeData() 里面没有匹配弹幕库成功, 就会弹出下方对话框,让用户手动匹配*/}
5459
<MatchAnimeDialog
5560
matchData={currentMatchedVideo.episodeId ? undefined : matchData}
56-
onSelected={(params) => {
61+
onSelected={async(params) => {
5762
// 如果用户选择不加载弹幕
5863
if (!params) {
5964
// 保存到历史记录
60-
saveToHistory({
65+
await saveToHistory({
6166
hash,
6267
path: url,
6368
animeTitle: name,

src/renderer/src/components/modules/player/loading/hooks.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,29 @@ export const saveToHistory = async (
347347
})
348348
}
349349

350-
const [bangumiDetail, bangumiShin] = await Promise.all([
351-
apiClient.bangumi.getBangumiDetailById(animeId),
352-
apiClient.bangumi.getBangumiShin(),
353-
])
354-
355-
Object.assign(historyData, {
356-
cover: bangumiDetail.bangumi.imageUrl,
357-
newBangumi: bangumiShin.bangumiList.some((item) => item.animeId === +animeId),
358-
})
359-
return db.history.add({
350+
const primaryKey = await db.history.add({
360351
...historyData,
361352
progress: 0,
362353
duration: 0,
363354
})
355+
const updateBangumiData = async () => {
356+
const [bangumiDetail, bangumiShin] = await Promise.all([
357+
apiClient.bangumi.getBangumiDetailById(animeId),
358+
apiClient.bangumi.getBangumiShin(),
359+
])
360+
361+
Object.assign(historyData, {
362+
cover: bangumiDetail.bangumi.imageUrl,
363+
newBangumi: bangumiShin.bangumiList.some((item) => item.animeId === +animeId),
364+
})
365+
return db.history.update(primaryKey, historyData)
366+
}
367+
368+
// 减少加载时长,先插入数据库,直接播放动漫,之后再获取动漫详情
369+
updateBangumiData()
370+
return
364371
}
372+
365373
return db.history.update(existingAnime.hash, historyData)
366374
}
367375

src/renderer/src/components/modules/shared/MatchDanmakuDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const MatchDanmakuDialog = () => {
4848
return
4949
}
5050
const { episodeId, episodeTitle, animeId, animeTitle } = params
51-
saveToHistory({
51+
await saveToHistory({
5252
path,
5353
subtitles,
5454
hash,

0 commit comments

Comments
 (0)