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:
parent
8f4a5ee1bd
commit
b68e1700c0
|
@ -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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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'
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue