Main+Renderer: Make IRC window syncing channels more generic

This commit renames the 'syncSettings' IRC channels to 'syncWindows' and
changes the renderer's listener setup for this channel more generic
so that it can cover other store modules besides the settings' module.
This commit is contained in:
Svallinn 2021-06-20 19:34:11 +01:00
parent 8f4a5ee1bd
commit b68e1700c0
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
3 changed files with 34 additions and 21 deletions

View File

@ -367,13 +367,13 @@ function runApp() {
createWindow(false) createWindow(false)
}) })
ipcMain.on('syncSetting', (event, setting) => { ipcMain.on('syncWindows', (event, payload) => {
const otherWindows = openedWindows.filter((window) => { const otherWindows = openedWindows.filter((window) => {
return window.webContents.id !== event.sender.id return window.webContents.id !== event.sender.id
}) })
for (const window of otherWindows) { for (const window of otherWindows) {
window.webContents.send('syncSetting', setting) window.webContents.send('syncWindows', payload)
} }
}) })

View File

@ -83,7 +83,6 @@ export default Vue.extend({
}, },
mounted: function () { mounted: function () {
this.grabUserSettings().then(() => { this.grabUserSettings().then(() => {
this.setUpListenerToSyncSettings()
this.grabAllProfiles(this.$t('Profile.All Channels')).then(async () => { this.grabAllProfiles(this.$t('Profile.All Channels')).then(async () => {
this.grabHistory() this.grabHistory()
this.grabAllPlaylists() this.grabAllPlaylists()
@ -92,6 +91,7 @@ export default Vue.extend({
if (this.usingElectron) { if (this.usingElectron) {
console.log('User is using Electron') console.log('User is using Electron')
ipcRenderer = require('electron').ipcRenderer ipcRenderer = require('electron').ipcRenderer
this.setupListenerToSyncWindows()
this.activateKeyboardShortcuts() this.activateKeyboardShortcuts()
this.openAllLinksExternally() this.openAllLinksExternally()
this.enableOpenUrl() this.enableOpenUrl()
@ -387,7 +387,7 @@ export default Vue.extend({
'grabAllPlaylists', 'grabAllPlaylists',
'getYoutubeUrlInfo', 'getYoutubeUrlInfo',
'getExternalPlayerCmdArgumentsData', 'getExternalPlayerCmdArgumentsData',
'setUpListenerToSyncSettings' 'setupListenerToSyncWindows'
]) ])
} }
}) })

View File

@ -314,23 +314,35 @@ const customActions = {
} }
}, },
setUpListenerToSyncSettings: ({ commit, dispatch, getters }) => { // Should be a root action, but we'll tolerate
const { setupListenerToSyncWindows: ({ commit, dispatch, getters }) => {
getUsingElectron: usingElectron, // Already known to be Electron, no need to check
settingHasSideEffects
} = getters
if (usingElectron) {
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
ipcRenderer.on('syncSetting', (_, setting) => { ipcRenderer.on('syncWindows', (_, payload) => {
const { _id, value } = setting const { type, data } = payload
if (settingHasSideEffects(_id)) { switch (type) {
dispatch(defaultSideEffectsTriggerId(_id), value) case 'setting':
// `data` is a single setting => { _id, value }
if (getters.settingHasSideEffects(data._id)) {
dispatch(defaultSideEffectsTriggerId(data._id), data.value)
} }
commit(defaultMutationId(_id), value) commit(defaultMutationId(data._id), data.value)
}) break
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') const { ipcRenderer } = require('electron')
// Propagate settings to all other existing windows // Propagate settings to all other existing windows
ipcRenderer.send('syncSetting', { ipcRenderer.send('syncWindows', {
_id: settingId, value: value type: 'setting',
data: { _id: settingId, value: value }
}) })
} }
} }