diff --git a/src/main/index.js b/src/main/index.js index a0fc0bcc..6f2df386 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -367,13 +367,13 @@ function runApp() { createWindow(false) }) - ipcMain.on('syncSetting', (event, setting) => { + ipcMain.on('syncWindows', (event, payload) => { const otherWindows = openedWindows.filter((window) => { return window.webContents.id !== event.sender.id }) for (const window of otherWindows) { - window.webContents.send('syncSetting', setting) + window.webContents.send('syncWindows', payload) } }) diff --git a/src/renderer/App.js b/src/renderer/App.js index 693e7eb4..3e2074cd 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -83,7 +83,6 @@ export default Vue.extend({ }, mounted: function () { this.grabUserSettings().then(() => { - this.setUpListenerToSyncSettings() this.grabAllProfiles(this.$t('Profile.All Channels')).then(async () => { this.grabHistory() this.grabAllPlaylists() @@ -92,6 +91,7 @@ export default Vue.extend({ if (this.usingElectron) { console.log('User is using Electron') ipcRenderer = require('electron').ipcRenderer + this.setupListenerToSyncWindows() this.activateKeyboardShortcuts() this.openAllLinksExternally() this.enableOpenUrl() @@ -387,7 +387,7 @@ export default Vue.extend({ 'grabAllPlaylists', 'getYoutubeUrlInfo', 'getExternalPlayerCmdArgumentsData', - 'setUpListenerToSyncSettings' + 'setupListenerToSyncWindows' ]) } }) diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index d43c2b7d..6b3d7b25 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -314,23 +314,35 @@ const customActions = { } }, - setUpListenerToSyncSettings: ({ commit, dispatch, getters }) => { - const { - getUsingElectron: usingElectron, - settingHasSideEffects - } = getters + // Should be a root action, but we'll tolerate + setupListenerToSyncWindows: ({ commit, dispatch, getters }) => { + // Already known to be Electron, no need to check + const { ipcRenderer } = require('electron') + ipcRenderer.on('syncWindows', (_, payload) => { + const { type, data } = payload + switch (type) { + case 'setting': + // `data` is a single setting => { _id, value } + if (getters.settingHasSideEffects(data._id)) { + dispatch(defaultSideEffectsTriggerId(data._id), data.value) + } - if (usingElectron) { - const { ipcRenderer } = require('electron') - ipcRenderer.on('syncSetting', (_, setting) => { - const { _id, value } = setting - if (settingHasSideEffects(_id)) { - dispatch(defaultSideEffectsTriggerId(_id), value) - } + commit(defaultMutationId(data._id), data.value) + break - commit(defaultMutationId(_id), value) - }) - } + case 'history': + // TODO: Not implemented + break + + case 'playlist': + // TODO: Not implemented + break + + case 'profile': + // TODO: Not implemented + break + } + }) } } @@ -393,8 +405,9 @@ for (const settingId of Object.keys(state)) { const { ipcRenderer } = require('electron') // Propagate settings to all other existing windows - ipcRenderer.send('syncSetting', { - _id: settingId, value: value + ipcRenderer.send('syncWindows', { + type: 'setting', + data: { _id: settingId, value: value } }) } }