Main+App+Store: Implement basic setting sync between Electron windows
The app utilizes the Electron IPC to communicate settings' updates to the other existing windows. This is still at a fairly rudimentary stage, since some settings are not syncing at all, while other settings have related side effects that are not currently being propagated to the remaining windows. An example of this would be the 'uiScale' setting, in which the value is properly synced, but the app's actual scaling isn't.
This commit is contained in:
parent
5e105f5584
commit
7e94abb3b4
|
@ -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()
|
||||
|
|
|
@ -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'
|
||||
])
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue