Skip to content

Commit b949f69

Browse files
committed
fix: repeated danmaku problem
1 parent 9207258 commit b949f69

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

electron-builder.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,4 @@ afterPack: scripts/cleaned-unused-arch-deps.js
6868
afterSign: scripts/notarize.js
6969
releaseInfo:
7070
releaseNotes: |
71-
修复历史记录丢失问题
72-
新增联系作者功能
73-
Web 版本添加下载客户端功能
74-
优化图标显示效果
75-
支持清除弹幕缓存
71+
修复会出现重复弹幕的问题

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const useVideo = () => {
6666
url = `${MARCHEN_PROTOCOL_PREFIX}${path}`
6767
tipcClient?.addRecentDocument({ path })
6868
}
69-
const { size, name:fileName } = file
69+
const { size, name: fileName } = file
7070
try {
7171
const hash = await calculateFileHash(file)
7272
setVideo((prev) => ({ ...prev, url, hash, size, name: fileName, playList }))
@@ -197,9 +197,26 @@ export const useDanmakuData = () => {
197197
const fetchData = await apiClient.comment.getExtcomment({ url: related.url })
198198
const history = await db.history.get(video.hash)
199199
const historyDanmaku = history?.danmaku?.find((item) => item.source === related.url)
200+
201+
const handleIsSelected = () => {
202+
// 如果历史记录中有选中的弹幕库,就返回 true
203+
if (historyDanmaku?.selected) {
204+
return true
205+
}
206+
207+
if (!related.url.includes('bilibili')) {
208+
return true
209+
}
210+
211+
// bilibili 弹幕库感觉有重复的弹幕,目前只默认加载一个 bilibili 弹幕库
212+
return (
213+
related.url ===
214+
thirdPartyDanmakuUrlData?.relateds.find((item) => item.url.includes('bilibili'))?.url
215+
)
216+
}
200217
return {
201218
...fetchData,
202-
selected: historyDanmaku?.selected ?? true,
219+
selected: handleIsSelected(),
203220
}
204221
},
205222
enabled: !!episodeId && !onlyLoadDandanplayDanmaku,
@@ -237,7 +254,7 @@ export const useDanmakuData = () => {
237254
combine: (results) => {
238255
const manualResult = results.at(-1)?.data as DB_Danmaku[]
239256
const dandanplayResult = results.at(-2)?.data as CommentsModel & { selected: boolean }
240-
const thirdPartyplayResult = results.slice(0, -2) as UseQueryResult<
257+
const thirdPartyResult = results.slice(0, -2) as UseQueryResult<
241258
CommentsModel & { selected: boolean }
242259
>[]
243260
const dandanplayDanmakuData = {
@@ -246,7 +263,7 @@ export const useDanmakuData = () => {
246263
content: dandanplayResult,
247264
selected: dandanplayResult?.selected,
248265
} satisfies DB_Danmaku
249-
const thirdPartyDanmakuData = thirdPartyplayResult.map((result, index) => ({
266+
const thirdPartyDanmakuData = thirdPartyResult.map((result, index) => ({
250267
type: 'third-party-auto',
251268
content: result.data,
252269
source: thirdPartyDanmakuUrlData?.relateds[index].url,
@@ -305,7 +322,7 @@ export const saveToHistory = async (
305322
}
306323
if (animeId) {
307324
const { bangumi } = await apiClient.bangumi.getBangumiDetailById(animeId)
308-
325+
309326
Object.assign(historyData, {
310327
cover: bangumi.imageUrl,
311328
})

0 commit comments

Comments
 (0)