2022-05-12 02:45:43 +08:00
|
|
|
import { player } from '@/web/store'
|
2022-05-01 19:53:25 +08:00
|
|
|
import {
|
|
|
|
IpcChannels,
|
|
|
|
IpcChannelsReturns,
|
|
|
|
IpcChannelsParams,
|
|
|
|
} from '@/shared/IpcChannels'
|
2022-04-20 20:25:20 +08:00
|
|
|
|
|
|
|
const on = <T extends keyof IpcChannelsParams>(
|
|
|
|
channel: T,
|
|
|
|
listener: (event: any, params: IpcChannelsReturns[T]) => void
|
|
|
|
) => {
|
|
|
|
window.ipcRenderer?.on(channel, listener)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ipcRenderer() {
|
|
|
|
on(IpcChannels.Play, () => {
|
|
|
|
player.play(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
on(IpcChannels.Pause, () => {
|
|
|
|
player.pause(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
on(IpcChannels.PlayOrPause, () => {
|
|
|
|
player.playOrPause()
|
|
|
|
})
|
|
|
|
|
|
|
|
on(IpcChannels.Next, () => {
|
|
|
|
player.nextTrack()
|
|
|
|
})
|
|
|
|
|
|
|
|
on(IpcChannels.Previous, () => {
|
|
|
|
player.prevTrack()
|
|
|
|
})
|
|
|
|
|
|
|
|
on(IpcChannels.Repeat, (e, mode) => {
|
|
|
|
player.repeatMode = mode
|
|
|
|
})
|
|
|
|
}
|