refactor: Use invoke for ipc to change global header

This commit is contained in:
AkiraFukushima 2020-11-29 22:42:16 +09:00
parent 69ac0bb3e9
commit 61602afcf9
2 changed files with 11 additions and 21 deletions

View File

@ -940,20 +940,14 @@ ipcMain.handle('get-collapse', async (_: IpcMainInvokeEvent) => {
return conf.state.collapse return conf.state.collapse
}) })
ipcMain.on('change-global-header', (event: IpcMainEvent, value: boolean) => { ipcMain.handle('change-global-header', async (_: IpcMainInvokeEvent, value: boolean) => {
const preferences = new Preferences(preferencesDBPath) const preferences = new Preferences(preferencesDBPath)
preferences const conf = await preferences.update({
.update({
state: { state: {
hideGlobalHeader: value hideGlobalHeader: value
} }
}) })
.then(conf => { return conf
event.sender.send('response-change-global-header', conf)
})
.catch(err => {
log.error(err)
})
}) })
ipcMain.on('get-global-header', (event: IpcMainEvent) => { ipcMain.on('get-global-header', (event: IpcMainEvent) => {

View File

@ -104,14 +104,10 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
}) })
}) })
}, },
switchHide: ({ dispatch }, hide: boolean): Promise<boolean> => { switchHide: async ({ dispatch }, hide: boolean): Promise<boolean> => {
return new Promise(resolve => { await win.ipcRenderer.invoke('change-global-header', hide)
win.ipcRenderer.send('change-global-header', hide)
win.ipcRenderer.once('response-change-global-header', () => {
dispatch('loadHide') dispatch('loadHide')
resolve(true) return true
})
})
}, },
startUserStreamings: ({ state }): Promise<{}> => { startUserStreamings: ({ state }): Promise<{}> => {
// @ts-ignore // @ts-ignore