Electron/History: Implement history synchronization

This commit is contained in:
Svallinn 2021-10-17 23:48:28 +01:00
parent dab73f8150
commit b320578807
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
3 changed files with 48 additions and 12 deletions

View File

@ -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'
}
}

View File

@ -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:

View File

@ -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, (_, __) => {