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 return account
}) })
ipcMain.on('update-account', async (event: IpcMainEvent, acct: LocalAccount) => { ipcMain.handle('update-account', async (_: IpcMainInvokeEvent, acct: LocalAccount) => {
const proxy = await proxyConfiguration.forMastodon() const proxy = await proxyConfiguration.forMastodon()
accountManager const ac: LocalAccount = await accountManager.refresh(acct, proxy)
.refresh(acct, proxy) return ac
.then(ac => {
event.sender.send('response-update-account', ac)
})
.catch(err => {
event.sender.send('error-update-account', err)
})
}) })
ipcMain.on('remove-account', (event: IpcMainEvent, id: string) => { ipcMain.on('remove-account', (event: IpcMainEvent, id: string) => {

View File

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