diff --git a/src/main/index.js b/src/main/index.js index ebca3a07..a5c0c534 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -387,6 +387,16 @@ function runApp() { createWindow(false, '', false) }) + ipcMain.on('syncSetting', (event, setting) => { + const otherWindows = openedWindows.filter((window) => { + return window.webContents.id !== event.sender.id + }) + + for (const window of otherWindows) { + window.webContents.send('syncSetting', setting) + } + }) + app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() diff --git a/src/renderer/App.js b/src/renderer/App.js index 7337b17a..11af0ef6 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -80,6 +80,7 @@ export default Vue.extend({ }, mounted: function () { this.grabUserSettings().then(() => { + this.setUpListenerToSyncSettings() this.grabAllProfiles(this.$t('Profile.All Channels')).then(async () => { this.grabHistory() this.grabAllPlaylists() @@ -404,7 +405,8 @@ export default Vue.extend({ 'grabAllPlaylists', 'getRegionData', 'getYoutubeUrlInfo', - 'getLocale' + 'getLocale', + 'setUpListenerToSyncSettings' ]) } }) diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index c69e5657..d8d32555 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -121,6 +121,13 @@ for (const settingId of Object.keys(state)) { (err, _) => { if (!err) { commit(mutationId, value) + if (getters.getUsingElectron) { + const { ipcRenderer } = require('electron') + // Propagate setting values to all other existing windows + ipcRenderer.send('syncSetting', { + _id: settingId, value: value + }) + } } } ) @@ -190,6 +197,18 @@ Object.assign(actions, { } ) }) + }, + + setUpListenerToSyncSettings: ({ commit, getters }) => { + if (getters.getUsingElectron) { + const { ipcRenderer } = require('electron') + ipcRenderer.on('syncSetting', (_, setting) => { + const capitalizedSettingId = + setting._id.replace(/^\w/, (c) => c.toUpperCase()) + + commit('set' + capitalizedSettingId, setting.value) + }) + } } })