Store: Implement history synchronization between windows
This commit is contained in:
parent
b68e1700c0
commit
99b61e6178
|
@ -16,7 +16,7 @@ const actions = {
|
||||||
commit('setHistoryCache', results)
|
commit('setHistoryCache', results)
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateHistory({ commit, state }, entry) {
|
async updateHistory({ commit, dispatch, state }, entry) {
|
||||||
await historyDb.update(
|
await historyDb.update(
|
||||||
{ videoId: entry.videoId },
|
{ videoId: entry.videoId },
|
||||||
entry,
|
entry,
|
||||||
|
@ -33,9 +33,11 @@ const actions = {
|
||||||
currentIndex: entryIndex,
|
currentIndex: entryIndex,
|
||||||
updatedEntry: entry
|
updatedEntry: entry
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dispatch('propagateHistory')
|
||||||
},
|
},
|
||||||
|
|
||||||
async removeFromHistory({ commit }, videoId) {
|
async removeFromHistory({ commit, dispatch }, videoId) {
|
||||||
await historyDb.remove({ videoId: videoId })
|
await historyDb.remove({ videoId: videoId })
|
||||||
|
|
||||||
const updatedCache = state.historyCache.filter((entry) => {
|
const updatedCache = state.historyCache.filter((entry) => {
|
||||||
|
@ -43,14 +45,17 @@ const actions = {
|
||||||
})
|
})
|
||||||
|
|
||||||
commit('setHistoryCache', updatedCache)
|
commit('setHistoryCache', updatedCache)
|
||||||
|
|
||||||
|
dispatch('propagateHistory')
|
||||||
},
|
},
|
||||||
|
|
||||||
async removeAllHistory({ commit }) {
|
async removeAllHistory({ commit, dispatch }) {
|
||||||
await historyDb.remove({}, { multi: true })
|
await historyDb.remove({}, { multi: true })
|
||||||
commit('setHistoryCache', [])
|
commit('setHistoryCache', [])
|
||||||
|
dispatch('propagateHistory')
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateWatchProgress({ commit }, entry) {
|
async updateWatchProgress({ commit, dispatch }, entry) {
|
||||||
await historyDb.update(
|
await historyDb.update(
|
||||||
{ videoId: entry.videoId },
|
{ videoId: entry.videoId },
|
||||||
{ $set: { watchProgress: entry.watchProgress } },
|
{ $set: { watchProgress: entry.watchProgress } },
|
||||||
|
@ -65,6 +70,18 @@ const actions = {
|
||||||
index: entryIndex,
|
index: entryIndex,
|
||||||
value: entry.watchProgress
|
value: entry.watchProgress
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dispatch('propagateHistory')
|
||||||
|
},
|
||||||
|
|
||||||
|
propagateHistory({ getters: { getUsingElectron: usingElectron } }) {
|
||||||
|
if (usingElectron) {
|
||||||
|
const { ipcRenderer } = require('electron')
|
||||||
|
ipcRenderer.send('syncWindows', {
|
||||||
|
type: 'history',
|
||||||
|
data: state.historyCache
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
compactHistory(_) {
|
compactHistory(_) {
|
||||||
|
|
|
@ -331,7 +331,8 @@ const customActions = {
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'history':
|
case 'history':
|
||||||
// TODO: Not implemented
|
// `data` is the whole history => Array of history entries
|
||||||
|
commit('setHistoryCache', data)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'playlist':
|
case 'playlist':
|
||||||
|
|
Loading…
Reference in New Issue