playlist.handlers.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { ipcMain } from 'electron'
  2. import { IpcChannels } from '@shared/ipc-channels'
  3. import type { PlaylistSettings } from '@shared/types'
  4. import * as playlists from '../services/playlist.service'
  5. import * as player from '../services/playlist-player.service'
  6. export function registerPlaylistHandlers(): void {
  7. ipcMain.handle(IpcChannels.PLAYLIST_GET_ALL, () => playlists.getAllPlaylists())
  8. ipcMain.handle(IpcChannels.PLAYLIST_GET_ONE, (_e, id: string) => playlists.getPlaylist(id))
  9. ipcMain.handle(IpcChannels.PLAYLIST_CREATE, (_e, title: string) =>
  10. playlists.createPlaylist(title)
  11. )
  12. ipcMain.handle(IpcChannels.PLAYLIST_RENAME, (_e, id: string, title: string) =>
  13. playlists.renamePlaylist(id, title)
  14. )
  15. ipcMain.handle(IpcChannels.PLAYLIST_DELETE, (_e, id: string) => {
  16. if (player.getPlaybackState().playlistId === id) player.stopPlaylist()
  17. playlists.deletePlaylist(id)
  18. return { ok: true }
  19. })
  20. ipcMain.handle(
  21. IpcChannels.PLAYLIST_UPDATE_SETTINGS,
  22. (_e, id: string, patch: Partial<PlaylistSettings>) =>
  23. playlists.updatePlaylistSettings(id, patch)
  24. )
  25. ipcMain.handle(IpcChannels.PLAYLIST_ADD_ITEMS, (_e, id: string, wallpaperIds: string[]) =>
  26. playlists.addItemsToPlaylist(id, wallpaperIds)
  27. )
  28. ipcMain.handle(IpcChannels.PLAYLIST_REMOVE_ITEMS, (_e, id: string, wallpaperIds: string[]) =>
  29. playlists.removeItemsFromPlaylist(id, wallpaperIds)
  30. )
  31. ipcMain.handle(
  32. IpcChannels.PLAYLIST_REORDER_ITEMS,
  33. (_e, id: string, orderedWallpaperIds: string[]) =>
  34. playlists.reorderPlaylistItems(id, orderedWallpaperIds)
  35. )
  36. ipcMain.handle(
  37. IpcChannels.PLAYLIST_UPDATE_ITEM,
  38. (_e, id: string, wallpaperId: string, patch: { volume?: number; durationSec?: number }) =>
  39. playlists.updatePlaylistItem(id, wallpaperId, patch)
  40. )
  41. ipcMain.handle(IpcChannels.PLAYLIST_START, (_e, id: string) => player.startPlaylist(id))
  42. ipcMain.handle(IpcChannels.PLAYLIST_PLAY_ITEM, (_e, id: string, wallpaperId: string) =>
  43. player.playItem(id, wallpaperId)
  44. )
  45. ipcMain.handle(IpcChannels.PLAYLIST_STOP, () => player.stopPlaylist())
  46. ipcMain.handle(IpcChannels.PLAYLIST_PAUSE, () => player.pausePlaylist())
  47. ipcMain.handle(IpcChannels.PLAYLIST_RESUME, () => player.resumePlaylist())
  48. ipcMain.handle(IpcChannels.PLAYLIST_NEXT, () => player.nextItem())
  49. ipcMain.handle(IpcChannels.PLAYLIST_PREVIOUS, () => player.previousItem())
  50. ipcMain.handle(IpcChannels.PLAYLIST_GET_STATE, () => player.getPlaybackState())
  51. }