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
})
ipcMain.on('get-global-header', (event: IpcMainEvent) => {
ipcMain.handle('get-global-header', async (_: IpcMainInvokeEvent) => {
const preferences = new Preferences(preferencesDBPath)
preferences.load().then(conf => {
event.sender.send('response-get-global-header', conf.state.hideGlobalHeader)
})
const conf = await preferences.load()
return conf.state.hideGlobalHeader
})
// proxy

View File

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