Store: Implement history synchronization between windows

This commit is contained in:
Svallinn 2021-06-20 19:35:14 +01:00
parent b68e1700c0
commit 99b61e6178
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
2 changed files with 23 additions and 5 deletions

View File

@ -16,7 +16,7 @@ const actions = {
commit('setHistoryCache', results)
},
async updateHistory({ commit, state }, entry) {
async updateHistory({ commit, dispatch, state }, entry) {
await historyDb.update(
{ videoId: entry.videoId },
entry,
@ -33,9 +33,11 @@ const actions = {
currentIndex: entryIndex,
updatedEntry: entry
})
dispatch('propagateHistory')
},
async removeFromHistory({ commit }, videoId) {
async removeFromHistory({ commit, dispatch }, videoId) {
await historyDb.remove({ videoId: videoId })
const updatedCache = state.historyCache.filter((entry) => {
@ -43,14 +45,17 @@ const actions = {
})
commit('setHistoryCache', updatedCache)
dispatch('propagateHistory')
},
async removeAllHistory({ commit }) {
async removeAllHistory({ commit, dispatch }) {
await historyDb.remove({}, { multi: true })
commit('setHistoryCache', [])
dispatch('propagateHistory')
},
async updateWatchProgress({ commit }, entry) {
async updateWatchProgress({ commit, dispatch }, entry) {
await historyDb.update(
{ videoId: entry.videoId },
{ $set: { watchProgress: entry.watchProgress } },
@ -65,6 +70,18 @@ const actions = {
index: entryIndex,
value: entry.watchProgress
})
dispatch('propagateHistory')
},
propagateHistory({ getters: { getUsingElectron: usingElectron } }) {
if (usingElectron) {
const { ipcRenderer } = require('electron')
ipcRenderer.send('syncWindows', {
type: 'history',
data: state.historyCache
})
}
},
compactHistory(_) {

View File

@ -331,7 +331,8 @@ const customActions = {
break
case 'history':
// TODO: Not implemented
// `data` is the whole history => Array of history entries
commit('setHistoryCache', data)
break
case 'playlist':