mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 06:07:48 +00:00
feat: monorepo
This commit is contained in:
parent
4d54060a4f
commit
42089d4996
200 changed files with 1530 additions and 1521 deletions
|
|
@ -1,59 +0,0 @@
|
|||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import useUserLikedTracksIDs, {
|
||||
useMutationLikeATrack,
|
||||
} from '@/renderer/hooks/useUserLikedTracksIDs'
|
||||
import { player } from '@/renderer/store'
|
||||
import useIpcRenderer from '@/renderer/hooks/useIpcRenderer'
|
||||
import { State as PlayerState } from '@/renderer/utils/player'
|
||||
|
||||
const IpcRendererReact = () => {
|
||||
const [isPlaying, setIsPlaying] = useState(false)
|
||||
const playerSnapshot = useSnapshot(player)
|
||||
const track = useMemo(() => playerSnapshot.track, [playerSnapshot.track])
|
||||
const state = useMemo(() => playerSnapshot.state, [playerSnapshot.state])
|
||||
const trackIDRef = useRef(0)
|
||||
|
||||
// Liked songs ids
|
||||
const { data: userLikedSongs } = useUserLikedTracksIDs()
|
||||
const mutationLikeATrack = useMutationLikeATrack()
|
||||
|
||||
useIpcRenderer(IpcChannels.Like, () => {
|
||||
const id = trackIDRef.current
|
||||
id && mutationLikeATrack.mutate(id)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
trackIDRef.current = track?.id ?? 0
|
||||
|
||||
const text = track?.name ? `${track.name} - YesPlayMusic` : 'YesPlayMusic'
|
||||
window.ipcRenderer?.send(IpcChannels.SetTrayTooltip, {
|
||||
text,
|
||||
})
|
||||
document.title = text
|
||||
}, [track])
|
||||
|
||||
useEffect(() => {
|
||||
window.ipcRenderer?.send(IpcChannels.Like, {
|
||||
isLiked: userLikedSongs?.ids?.includes(track?.id ?? 0) ?? false,
|
||||
})
|
||||
}, [userLikedSongs, track])
|
||||
|
||||
useEffect(() => {
|
||||
const playing = [PlayerState.Playing, PlayerState.Loading].includes(state)
|
||||
if (isPlaying === playing) return
|
||||
|
||||
window.ipcRenderer?.send(playing ? IpcChannels.Play : IpcChannels.Pause)
|
||||
setIsPlaying(playing)
|
||||
}, [state])
|
||||
|
||||
useEffectOnce(() => {
|
||||
// 用于显示 windows taskbar buttons
|
||||
if (playerSnapshot.track?.id) {
|
||||
window.ipcRenderer?.send(IpcChannels.Pause)
|
||||
}
|
||||
})
|
||||
|
||||
return <></>
|
||||
}
|
||||
|
||||
export default IpcRendererReact
|
||||
Loading…
Add table
Add a link
Reference in a new issue