refactor: Use invoke for ipc to get global header

This commit is contained in:
AkiraFukushima 2020-11-29 22:43:59 +09:00
parent 61602afcf9
commit 2b84a9402e
2 changed files with 7 additions and 12 deletions

View File

@ -950,11 +950,10 @@ ipcMain.handle('change-global-header', async (_: IpcMainInvokeEvent, value: bool
return conf return conf
}) })
ipcMain.on('get-global-header', (event: IpcMainEvent) => { ipcMain.handle('get-global-header', async (_: IpcMainInvokeEvent) => {
const preferences = new Preferences(preferencesDBPath) const preferences = new Preferences(preferencesDBPath)
preferences.load().then(conf => { const conf = await preferences.load()
event.sender.send('response-get-global-header', conf.state.hideGlobalHeader) return conf.state.hideGlobalHeader
})
}) })
// proxy // proxy

View File

@ -95,14 +95,10 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
win.ipcRenderer.removeAllListeners('change-account') win.ipcRenderer.removeAllListeners('change-account')
return true return true
}, },
loadHide: ({ commit }): Promise<boolean> => { loadHide: async ({ commit }): Promise<boolean> => {
return new Promise(resolve => { const hide: boolean = await win.ipcRenderer.invoke('get-global-header')
win.ipcRenderer.send('get-global-header') commit(MUTATION_TYPES.CHANGE_HIDE, hide)
win.ipcRenderer.once('response-get-global-header', (_, hide: boolean) => { return hide
commit(MUTATION_TYPES.CHANGE_HIDE, hide)
resolve(hide)
})
})
}, },
switchHide: async ({ dispatch }, hide: boolean): Promise<boolean> => { switchHide: async ({ dispatch }, hide: boolean): Promise<boolean> => {
await win.ipcRenderer.invoke('change-global-header', hide) await win.ipcRenderer.invoke('change-global-header', hide)