refactor: Use invoke for ipc to update unread notification
This commit is contained in:
parent
faa5e27a03
commit
46a0087c78
|
@ -1019,17 +1019,9 @@ ipcMain.handle('get-unread-notification', async (_: IpcMainInvokeEvent, accountI
|
||||||
return doc
|
return doc
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('update-unread-notification', (event: IpcMainEvent, config: UnreadNotificationConfig) => {
|
ipcMain.handle('update-unread-notification', async (_: IpcMainInvokeEvent, config: UnreadNotificationConfig) => {
|
||||||
const { accountID } = config
|
const { accountID } = config
|
||||||
unreadNotification
|
await unreadNotification.insertOrUpdate(accountID!, config)
|
||||||
.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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
|
|
|
@ -44,22 +44,13 @@ const actions: ActionTree<TimelineState, RootState> = {
|
||||||
return false
|
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, {
|
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
||||||
accountID: rootState.Settings.accountID
|
accountID: rootState.Settings.accountID
|
||||||
})
|
})
|
||||||
return new Promise((resolve, reject) => {
|
await win.ipcRenderer.invoke('update-unread-notification', settings)
|
||||||
win.ipcRenderer.once('response-update-unread-notification', () => {
|
dispatch('loadUnreadNotification')
|
||||||
win.ipcRenderer.removeAllListeners('error-update-unread-notification')
|
return true
|
||||||
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)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue