You've already forked bilibili-subtitle
fix
This commit is contained in:
26
src/App.tsx
26
src/App.tsx
@@ -1,12 +1,12 @@
|
|||||||
import React, {useCallback, useContext, useEffect, useMemo} from 'react'
|
import React, {useCallback, useContext, useEffect, useMemo} from 'react'
|
||||||
import 'tippy.js/dist/tippy.css'
|
import 'tippy.js/dist/tippy.css'
|
||||||
import {useAppDispatch, useAppSelector} from './hooks/redux'
|
import {useAppDispatch, useAppSelector} from './hooks/redux'
|
||||||
import {setCurFetched, setCurInfo, setData, setEnvData, setEnvReady, setFold, setInfos, setPage, setTempData, setTempReady, setTitle, setUrl} from './redux/envReducer'
|
import {setEnvData, setEnvReady, setFold, setPage, setTempData, setTempReady} from './redux/envReducer'
|
||||||
import Header from './biz/Header'
|
import Header from './biz/Header'
|
||||||
import Body from './biz/Body'
|
import Body from './biz/Body'
|
||||||
import useSubtitleService from './hooks/useSubtitleService'
|
import useSubtitleService from './hooks/useSubtitleService'
|
||||||
import {cloneDeep} from 'lodash-es'
|
import {cloneDeep} from 'lodash-es'
|
||||||
import {EVENT_EXPAND, MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO, MESSAGE_TO_INJECT_FOLD, PAGE_MAIN, PAGE_SETTINGS, STORAGE_ENV, STORAGE_TEMP} from './const'
|
import {EVENT_EXPAND, MESSAGE_TO_INJECT_FOLD, PAGE_MAIN, PAGE_SETTINGS, STORAGE_ENV, STORAGE_TEMP} from './const'
|
||||||
import {EventBusContext} from './Router'
|
import {EventBusContext} from './Router'
|
||||||
import useTranslateService from './hooks/useTranslateService'
|
import useTranslateService from './hooks/useTranslateService'
|
||||||
import Settings from './biz/Settings'
|
import Settings from './biz/Settings'
|
||||||
@@ -15,8 +15,8 @@ import {useLocalStorage} from '@kky002/kky-hooks'
|
|||||||
import {Toaster} from 'react-hot-toast'
|
import {Toaster} from 'react-hot-toast'
|
||||||
import {setTheme} from './util/biz_util'
|
import {setTheme} from './util/biz_util'
|
||||||
import useSearchService from './hooks/useSearchService'
|
import useSearchService from './hooks/useSearchService'
|
||||||
import useMessageService from './messaging/useMessageService'
|
|
||||||
import useMessage from './messaging/useMessage'
|
import useMessage from './messaging/useMessage'
|
||||||
|
import useMessagingService from './hooks/useMessagingService'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@@ -72,29 +72,11 @@ function App() {
|
|||||||
setTheme(envData.theme)
|
setTheme(envData.theme)
|
||||||
}, [envData.theme])
|
}, [envData.theme])
|
||||||
|
|
||||||
//methods
|
|
||||||
const methods = useMemo(() => ({
|
|
||||||
[MESSAGE_TO_APP_SET_INFOS]: (params: any, from: string, context: MethodContext) => {
|
|
||||||
dispatch(setInfos(params.infos))
|
|
||||||
dispatch(setCurInfo(undefined))
|
|
||||||
dispatch(setCurFetched(false))
|
|
||||||
dispatch(setData(undefined))
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
[MESSAGE_TO_APP_SET_VIDEO_INFO]: (params: any, from: string, context: MethodContext) => {
|
|
||||||
dispatch(setInfos(params.infos))
|
|
||||||
dispatch(setUrl(params.url))
|
|
||||||
dispatch(setTitle(params.title))
|
|
||||||
console.debug('video title: ', params.title)
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
}), [dispatch])
|
|
||||||
|
|
||||||
// services
|
// services
|
||||||
useSubtitleService()
|
useSubtitleService()
|
||||||
useTranslateService()
|
useTranslateService()
|
||||||
useSearchService()
|
useSearchService()
|
||||||
useMessageService(methods)
|
useMessagingService()
|
||||||
|
|
||||||
return <div className='select-none w-full' style={{
|
return <div className='select-none w-full' style={{
|
||||||
height: fold?undefined:`${totalHeight}px`,
|
height: fold?undefined:`${totalHeight}px`,
|
||||||
|
31
src/hooks/useMessagingService.ts
Normal file
31
src/hooks/useMessagingService.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
|
||||||
|
import { useMemo } from 'react'
|
||||||
|
import { useAppDispatch } from './redux'
|
||||||
|
import { MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO } from '@/const'
|
||||||
|
import useMessageService from '@/messaging/useMessageService'
|
||||||
|
|
||||||
|
const useMessagingService = () => {
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
|
//methods
|
||||||
|
const methods = useMemo(() => ({
|
||||||
|
[MESSAGE_TO_APP_SET_INFOS]: (params: any, from: string, context: MethodContext) => {
|
||||||
|
dispatch(setInfos(params.infos))
|
||||||
|
dispatch(setCurInfo(undefined))
|
||||||
|
dispatch(setCurFetched(false))
|
||||||
|
dispatch(setData(undefined))
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
[MESSAGE_TO_APP_SET_VIDEO_INFO]: (params: any, from: string, context: MethodContext) => {
|
||||||
|
dispatch(setInfos(params.infos))
|
||||||
|
dispatch(setUrl(params.url))
|
||||||
|
dispatch(setTitle(params.title))
|
||||||
|
console.debug('video title: ', params.title)
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}), [dispatch])
|
||||||
|
|
||||||
|
useMessageService(methods)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useMessagingService
|
Reference in New Issue
Block a user