refactor: Use invoke for ipc to remove all accounts

This commit is contained in:
AkiraFukushima 2020-11-29 01:21:39 +09:00
parent bad77b4e60
commit 070995b465
2 changed files with 4 additions and 22 deletions

View File

@ -463,16 +463,8 @@ ipcMain.handle('refresh-accounts', async (_: IpcMainInvokeEvent) => {
return accounts
})
ipcMain.on('remove-all-accounts', (event: IpcMainEvent) => {
accountManager
.removeAll()
.then(() => {
event.sender.send('response-remove-all-accounts')
})
.catch(err => {
log.error(err)
event.sender.send('error-remove-all-accounts', err)
})
ipcMain.handle('remove-all-accounts', async (_: IpcMainInvokeEvent) => {
await accountManager.removeAll()
})
ipcMain.on('change-auto-launch', (event: IpcMainEvent, enable: boolean) => {

View File

@ -44,18 +44,8 @@ const actions: ActionTree<AccountState, RootState> = {
backwardAccount: async (_, account: LocalAccount) => {
await win.ipcRenderer.invoke('backward-account', account)
},
removeAllAccounts: () => {
return new Promise((resolve, reject) => {
win.ipcRenderer.send('remove-all-accounts')
win.ipcRenderer.once('error-remove-all-accounts', (_, err: Error) => {
win.ipcRenderer.removeAllListeners('response-remove-all-accounts')
reject(err)
})
win.ipcRenderer.once('response-remove-all-accounts', () => {
win.ipcRenderer.removeAllListeners('error-remove-all-accounts')
resolve()
})
})
removeAllAccounts: async () => {
await win.ipcRenderer.invoke('remove-all-accounts')
}
}