mirror of https://github.com/FreeTubeApp/FreeTube
Electron/Playlists: Implement playlist synchronization
This commit is contained in:
parent
cf72a86606
commit
0745f5cec8
|
@ -55,8 +55,14 @@ const SyncEvents = {
|
|||
DELETE: 'sync-delete',
|
||||
DELETE_ALL: 'sync-delete-all'
|
||||
},
|
||||
|
||||
HISTORY: {
|
||||
UPDATE_WATCH_PROGRESS: 'sync-history-update-watch-progress'
|
||||
},
|
||||
|
||||
PLAYLISTS: {
|
||||
UPSERT_VIDEO: 'sync-playlists-upsert-video',
|
||||
DELETE_VIDEO: 'sync-playlists-delete-video'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -494,12 +494,16 @@ function runApp() {
|
|||
|
||||
// *********** //
|
||||
// Playlists
|
||||
ipcMain.handle(IpcChannels.DB_PLAYLISTS, async (_, { action, data }) => {
|
||||
// ! NOTE: A lot of these actions are currently not used for anything
|
||||
// As such, only the currently used actions have synchronization implemented
|
||||
// The remaining should have it implemented only when playlists
|
||||
// get fully implemented into the app
|
||||
ipcMain.handle(IpcChannels.DB_PLAYLISTS, async (event, { action, data }) => {
|
||||
try {
|
||||
switch (action) {
|
||||
case DBActions.GENERAL.CREATE:
|
||||
await baseHandlers.playlists.create(data)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
|
@ -508,49 +512,55 @@ function runApp() {
|
|||
|
||||
case DBActions.PLAYLISTS.UPSERT_VIDEO:
|
||||
await baseHandlers.playlists.upsertVideoByPlaylistName(data.playlistName, data.videoData)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_PLAYLISTS,
|
||||
event,
|
||||
{ event: SyncEvents.PLAYLISTS.UPSERT_VIDEO, data }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.PLAYLISTS.UPSERT_VIDEO_IDS:
|
||||
await baseHandlers.playlists.upsertVideoIdsByPlaylistId(data._id, data.videoIds)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.DELETE:
|
||||
await baseHandlers.playlists.delete(data)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
case DBActions.PLAYLISTS.DELETE_VIDEO_ID:
|
||||
await baseHandlers.playlists.deleteVideoIdByPlaylistName(data.playlistName, data.videoId)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_PLAYLISTS,
|
||||
event,
|
||||
{ event: SyncEvents.PLAYLISTS.DELETE_VIDEO, data }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.PLAYLISTS.DELETE_VIDEO_IDS:
|
||||
await baseHandlers.playlists.deleteVideoIdsByPlaylistName(data.playlistName, data.videoIds)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
case DBActions.PLAYLISTS.DELETE_ALL_VIDEOS:
|
||||
await baseHandlers.playlists.deleteAllVideosByPlaylistName(data)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.DELETE_MULTIPLE:
|
||||
await baseHandlers.playlists.deleteMultiple(data)
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.DELETE_ALL:
|
||||
await baseHandlers.playlists.deleteAll()
|
||||
// TODO: Syncing
|
||||
// TODO: Syncing (implement only when it starts being used)
|
||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||
return null
|
||||
|
||||
|
|
|
@ -389,8 +389,19 @@ const customActions = {
|
|||
}
|
||||
})
|
||||
|
||||
ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, __) => {
|
||||
// TODO: Not implemented
|
||||
ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, { event, data }) => {
|
||||
switch (event) {
|
||||
case SyncEvents.PLAYLISTS.UPSERT_VIDEO:
|
||||
commit('addVideo', data)
|
||||
break
|
||||
|
||||
case SyncEvents.PLAYLISTS.DELETE_VIDEO:
|
||||
commit('removeVideo', data)
|
||||
break
|
||||
|
||||
default:
|
||||
console.error('playlists: invalid sync event received')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue