From 99b61e617873412eb393d8f4dfccd8f8c172021f Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Sun, 20 Jun 2021 19:35:14 +0100 Subject: [PATCH] Store: Implement history synchronization between windows --- src/renderer/store/modules/history.js | 25 +++++++++++++++++++++---- src/renderer/store/modules/settings.js | 3 ++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/renderer/store/modules/history.js b/src/renderer/store/modules/history.js index 96aaa033..ee5ab1f8 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 6b3d7b25..cdf943a5 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':