refactor: Use invoke for ipc to update account

This commit is contained in:
AkiraFukushima 2020-11-28 23:10:24 +09:00
parent 5cfc344806
commit 5c94bc5cb7
2 changed files with 6 additions and 21 deletions

View File

@ -437,16 +437,10 @@ ipcMain.handle('get-local-account', async (_: IpcMainInvokeEvent, id: string) =>
return account
})
ipcMain.on('update-account', async (event: IpcMainEvent, acct: LocalAccount) => {
ipcMain.handle('update-account', async (_: IpcMainInvokeEvent, acct: LocalAccount) => {
const proxy = await proxyConfiguration.forMastodon()
accountManager
.refresh(acct, proxy)
.then(ac => {
event.sender.send('response-update-account', ac)
})
.catch(err => {
event.sender.send('error-update-account', err)
})
const ac: LocalAccount = await accountManager.refresh(acct, proxy)
return ac
})
ipcMain.on('remove-account', (event: IpcMainEvent, id: string) => {

View File

@ -132,18 +132,9 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
return account
}
},
fetchAccount: (_, account: LocalAccount): Promise<LocalAccount> => {
return new Promise((resolve, reject) => {
win.ipcRenderer.send('update-account', account)
win.ipcRenderer.once('error-update-account', (_, err: Error) => {
win.ipcRenderer.removeAllListeners('response-update-account')
reject(err)
})
win.ipcRenderer.once('response-update-account', (_, account: LocalAccount) => {
win.ipcRenderer.removeAllListeners('error-update-account')
resolve(account)
})
})
fetchAccount: async (_, account: LocalAccount): Promise<LocalAccount> => {
const acct: LocalAccount = await win.ipcRenderer.invoke('update-account', account)
return acct
},
clearAccount: async ({ commit }) => {
commit(MUTATION_TYPES.UPDATE_ACCOUNT, blankAccount)