diff --git a/src/renderer/store/modules/history.js b/src/renderer/store/modules/history.js index 96aaa033d..ee5ab1f8e 100644 --- a/src/renderer/store/modules/history.js +++ b/src/renderer/store/modules/history.js @@ -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(_) { diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index 6b3d7b258..cdf943a5d 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -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':