mirror of https://github.com/FreeTubeApp/FreeTube
Electron/History: Implement history synchronization
This commit is contained in:
parent
dab73f8150
commit
b320578807
|
@ -50,7 +50,12 @@ const DBActions = {
|
|||
|
||||
const SyncEvents = {
|
||||
GENERAL: {
|
||||
UPSERT: 'sync-upsert'
|
||||
UPSERT: 'sync-upsert',
|
||||
DELETE: 'sync-delete',
|
||||
DELETE_ALL: 'sync-delete-all'
|
||||
},
|
||||
HISTORY: {
|
||||
UPDATE_WATCH_PROGRESS: 'sync-history-update-watch-progress'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -386,7 +386,7 @@ function runApp() {
|
|||
|
||||
// *********** //
|
||||
// History
|
||||
ipcMain.handle(IpcChannels.DB_HISTORY, async (_, { action, data }) => {
|
||||
ipcMain.handle(IpcChannels.DB_HISTORY, async (event, { action, data }) => {
|
||||
try {
|
||||
switch (action) {
|
||||
case DBActions.GENERAL.FIND:
|
||||
|
@ -394,26 +394,38 @@ function runApp() {
|
|||
|
||||
case DBActions.GENERAL.UPSERT:
|
||||
await baseHandlers.history.upsert(data)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_HISTORY, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_HISTORY,
|
||||
event,
|
||||
{ event: SyncEvents.GENERAL.UPSERT, data }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.HISTORY.UPDATE_WATCH_PROGRESS:
|
||||
await baseHandlers.history.updateWatchProgress(data.videoId, data.watchProgress)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_HISTORY, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_HISTORY,
|
||||
event,
|
||||
{ event: SyncEvents.HISTORY.UPDATE_WATCH_PROGRESS, data }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.DELETE:
|
||||
await baseHandlers.history.delete(data)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_HISTORY, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_HISTORY,
|
||||
event,
|
||||
{ event: SyncEvents.GENERAL.DELETE, data }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.DELETE_ALL:
|
||||
await baseHandlers.history.deleteAll()
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_HISTORY, event, { event: '_', data })
|
||||
syncOtherWindows(
|
||||
IpcChannels.SYNC_HISTORY,
|
||||
event,
|
||||
{ event: SyncEvents.GENERAL.DELETE_ALL }
|
||||
)
|
||||
return null
|
||||
|
||||
case DBActions.GENERAL.PERSIST:
|
||||
|
|
|
@ -347,8 +347,27 @@ const customActions = {
|
|||
}
|
||||
})
|
||||
|
||||
ipcRenderer.on(IpcChannels.SYNC_HISTORY, (_, __) => {
|
||||
// TODO: Not implemented
|
||||
ipcRenderer.on(IpcChannels.SYNC_HISTORY, (_, { event, data }) => {
|
||||
switch (event) {
|
||||
case SyncEvents.GENERAL.UPSERT:
|
||||
commit('upsertToHistoryCache', data)
|
||||
break
|
||||
|
||||
case SyncEvents.HISTORY.UPDATE_WATCH_PROGRESS:
|
||||
commit('updateRecordWatchProgressInHistoryCache', data)
|
||||
break
|
||||
|
||||
case SyncEvents.GENERAL.DELETE:
|
||||
commit('removeFromHistoryCacheById', data)
|
||||
break
|
||||
|
||||
case SyncEvents.GENERAL.DELETE_ALL:
|
||||
commit('setHistoryCache', [])
|
||||
break
|
||||
|
||||
default:
|
||||
console.error('history: invalid sync event received')
|
||||
}
|
||||
})
|
||||
|
||||
ipcRenderer.on(IpcChannels.SYNC_PROFILES, (_, __) => {
|
||||
|
|
Loading…
Reference in New Issue