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: 'sync-delete',
|
||||||
DELETE_ALL: 'sync-delete-all'
|
DELETE_ALL: 'sync-delete-all'
|
||||||
},
|
},
|
||||||
|
|
||||||
HISTORY: {
|
HISTORY: {
|
||||||
UPDATE_WATCH_PROGRESS: 'sync-history-update-watch-progress'
|
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
|
// 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 {
|
try {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case DBActions.GENERAL.CREATE:
|
case DBActions.GENERAL.CREATE:
|
||||||
await baseHandlers.playlists.create(data)
|
await baseHandlers.playlists.create(data)
|
||||||
// TODO: Syncing
|
// TODO: Syncing (implement only when it starts being used)
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
@ -508,49 +512,55 @@ function runApp() {
|
||||||
|
|
||||||
case DBActions.PLAYLISTS.UPSERT_VIDEO:
|
case DBActions.PLAYLISTS.UPSERT_VIDEO:
|
||||||
await baseHandlers.playlists.upsertVideoByPlaylistName(data.playlistName, data.videoData)
|
await baseHandlers.playlists.upsertVideoByPlaylistName(data.playlistName, data.videoData)
|
||||||
// TODO: Syncing
|
syncOtherWindows(
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
IpcChannels.SYNC_PLAYLISTS,
|
||||||
|
event,
|
||||||
|
{ event: SyncEvents.PLAYLISTS.UPSERT_VIDEO, data }
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.PLAYLISTS.UPSERT_VIDEO_IDS:
|
case DBActions.PLAYLISTS.UPSERT_VIDEO_IDS:
|
||||||
await baseHandlers.playlists.upsertVideoIdsByPlaylistId(data._id, data.videoIds)
|
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 })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.GENERAL.DELETE:
|
case DBActions.GENERAL.DELETE:
|
||||||
await baseHandlers.playlists.delete(data)
|
await baseHandlers.playlists.delete(data)
|
||||||
// TODO: Syncing
|
// TODO: Syncing (implement only when it starts being used)
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.PLAYLISTS.DELETE_VIDEO_ID:
|
case DBActions.PLAYLISTS.DELETE_VIDEO_ID:
|
||||||
await baseHandlers.playlists.deleteVideoIdByPlaylistName(data.playlistName, data.videoId)
|
await baseHandlers.playlists.deleteVideoIdByPlaylistName(data.playlistName, data.videoId)
|
||||||
// TODO: Syncing
|
syncOtherWindows(
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
IpcChannels.SYNC_PLAYLISTS,
|
||||||
|
event,
|
||||||
|
{ event: SyncEvents.PLAYLISTS.DELETE_VIDEO, data }
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.PLAYLISTS.DELETE_VIDEO_IDS:
|
case DBActions.PLAYLISTS.DELETE_VIDEO_IDS:
|
||||||
await baseHandlers.playlists.deleteVideoIdsByPlaylistName(data.playlistName, data.videoIds)
|
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 })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.PLAYLISTS.DELETE_ALL_VIDEOS:
|
case DBActions.PLAYLISTS.DELETE_ALL_VIDEOS:
|
||||||
await baseHandlers.playlists.deleteAllVideosByPlaylistName(data)
|
await baseHandlers.playlists.deleteAllVideosByPlaylistName(data)
|
||||||
// TODO: Syncing
|
// TODO: Syncing (implement only when it starts being used)
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.GENERAL.DELETE_MULTIPLE:
|
case DBActions.GENERAL.DELETE_MULTIPLE:
|
||||||
await baseHandlers.playlists.deleteMultiple(data)
|
await baseHandlers.playlists.deleteMultiple(data)
|
||||||
// TODO: Syncing
|
// TODO: Syncing (implement only when it starts being used)
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
case DBActions.GENERAL.DELETE_ALL:
|
case DBActions.GENERAL.DELETE_ALL:
|
||||||
await baseHandlers.playlists.deleteAll()
|
await baseHandlers.playlists.deleteAll()
|
||||||
// TODO: Syncing
|
// TODO: Syncing (implement only when it starts being used)
|
||||||
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
// syncOtherWindows(IpcChannels.SYNC_PLAYLISTS, event, { event: '_', data })
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
|
@ -389,8 +389,19 @@ const customActions = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, __) => {
|
ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, { event, data }) => {
|
||||||
// TODO: Not implemented
|
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