mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-12-15 22:20:19 +01:00
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)
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -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'
|
||||
])
|
||||
}
|
||||
})
|
||||
|
@ -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 }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user