From 46a0087c78e3c7b00ff119ec3da0dc464e1c574c Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sun, 29 Nov 2020 23:36:36 +0900 Subject: [PATCH] refactor: Use invoke for ipc to update unread notification --- src/main/index.ts | 12 ++---------- src/renderer/store/Settings/Timeline.ts | 17 ++++------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 9d4fb9bd..9820fb3b 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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 diff --git a/src/renderer/store/Settings/Timeline.ts b/src/renderer/store/Settings/Timeline.ts index 858a6b7c..f1beed79 100644 --- a/src/renderer/store/Settings/Timeline.ts +++ b/src/renderer/store/Settings/Timeline.ts @@ -44,22 +44,13 @@ const actions: ActionTree = { return false } }, - changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise => { + changeUnreadNotification: async ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise => { 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 } }