Store/Settings: Propagate side effects to other existing windows

When syncing a setting between windows, if that setting has any
side effects, a trigger is fired in all other windows to perform
those side effects in their own environment.
This commit is contained in:
Svallinn 2021-06-11 02:44:47 +01:00
parent b26e8b68ef
commit b6bd3e6434
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
1 changed files with 11 additions and 2 deletions

View File

@ -286,11 +286,20 @@ const customActions = {
}) })
}, },
setUpListenerToSyncSettings: ({ commit, getters }) => { setUpListenerToSyncSettings: ({ commit, dispatch, getters }) => {
if (getters.getUsingElectron) { const {
getUsingElectron: usingElectron,
settingHasSideEffects
} = getters
if (usingElectron) {
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
ipcRenderer.on('syncSetting', (_, setting) => { ipcRenderer.on('syncSetting', (_, setting) => {
const { _id, value } = setting const { _id, value } = setting
if (settingHasSideEffects(_id)) {
dispatch(defaultSideEffectsTriggerId(_id), value)
}
commit(defaultMutationId(_id), value) commit(defaultMutationId(_id), value)
}) })
} }