refactor: Use invoke for ipc to update unread notification

This commit is contained in:
AkiraFukushima 2020-11-29 23:36:36 +09:00
parent faa5e27a03
commit 46a0087c78
2 changed files with 6 additions and 23 deletions

View File

@ -1019,17 +1019,9 @@ ipcMain.handle('get-unread-notification', async (_: IpcMainInvokeEvent, accountI
return doc
})
ipcMain.on('update-unread-notification', (event: IpcMainEvent, config: UnreadNotificationConfig) => {
ipcMain.handle('update-unread-notification', async (_: IpcMainInvokeEvent, config: UnreadNotificationConfig) => {
const { accountID } = config
unreadNotification
.insertOrUpdate(accountID!, config)
.then(_ => {
event.sender.send('response-update-unread-notification', true)
})
.catch(err => {
console.error(err)
event.sender.send('error-update-unread-notification', err)
})
await unreadNotification.insertOrUpdate(accountID!, config)
})
// Cache

View File

@ -44,22 +44,13 @@ const actions: ActionTree<TimelineState, RootState> = {
return false
}
},
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise<boolean> => {
changeUnreadNotification: async ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise<boolean> => {
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
accountID: rootState.Settings.accountID
})
return new Promise((resolve, reject) => {
win.ipcRenderer.once('response-update-unread-notification', () => {
win.ipcRenderer.removeAllListeners('error-update-unread-notification')
dispatch('loadUnreadNotification')
resolve(true)
})
win.ipcRenderer.once('error-update-unread-notification', (_, err: Error) => {
win.ipcRenderer.removeAllListeners('response-update-unread-notification')
reject(err)
})
win.ipcRenderer.send('update-unread-notification', settings)
})
await win.ipcRenderer.invoke('update-unread-notification', settings)
dispatch('loadUnreadNotification')
return true
}
}