mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 05:38:04 +00:00
feat: updates
This commit is contained in:
parent
0b4baa3eff
commit
222fb02355
77 changed files with 654 additions and 551 deletions
25
packages/web/hooks/useIntersectionObserver.ts
Normal file
25
packages/web/hooks/useIntersectionObserver.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { useState, useEffect, RefObject } from 'react'
|
||||
|
||||
const useIntersectionObserver = (
|
||||
element: RefObject<Element>
|
||||
): { onScreen: boolean } => {
|
||||
const [onScreen, setOnScreen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (element.current) {
|
||||
const observer = new IntersectionObserver(([entry]) =>
|
||||
setOnScreen(entry.isIntersecting)
|
||||
)
|
||||
observer.observe(element.current)
|
||||
return () => {
|
||||
observer.disconnect()
|
||||
}
|
||||
}
|
||||
}, [element, setOnScreen])
|
||||
|
||||
return {
|
||||
onScreen,
|
||||
}
|
||||
}
|
||||
|
||||
export default useIntersectionObserver
|
||||
|
|
@ -13,23 +13,21 @@ export default function useVideoCover(props: {
|
|||
async () => {
|
||||
if (!id || !name || !artist) return
|
||||
|
||||
const fromCache = window.ipcRenderer?.sendSync(
|
||||
const fromMainProcess = await window.ipcRenderer?.invoke(
|
||||
IpcChannels.GetVideoCover,
|
||||
{
|
||||
id,
|
||||
name,
|
||||
artist,
|
||||
}
|
||||
)
|
||||
if (fromCache) {
|
||||
return fromCache === 'no' ? undefined : fromCache
|
||||
if (fromMainProcess) {
|
||||
return fromMainProcess
|
||||
}
|
||||
|
||||
const fromRemote = await axios.get('/yesplaymusic/video-cover', {
|
||||
params: props,
|
||||
})
|
||||
window.ipcRenderer?.send(IpcChannels.SetVideoCover, {
|
||||
id,
|
||||
url: fromRemote.data.url || '',
|
||||
})
|
||||
if (fromRemote?.data?.url) {
|
||||
return fromRemote.data.url
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue