refactor: Use invoke for ipc to refresh accounts
This commit is contained in:
parent
5b969b39c3
commit
bad77b4e60
|
@ -456,16 +456,11 @@ ipcMain.handle('backward-account', async (_: IpcMainInvokeEvent, acct: LocalAcco
|
|||
await accountManager.backwardAccount(acct)
|
||||
})
|
||||
|
||||
ipcMain.on('refresh-accounts', async (event: IpcMainEvent) => {
|
||||
ipcMain.handle('refresh-accounts', async (_: IpcMainInvokeEvent) => {
|
||||
const proxy = await proxyConfiguration.forMastodon()
|
||||
accountManager
|
||||
.refreshAccounts(proxy)
|
||||
.then(accounts => {
|
||||
event.sender.send('response-refresh-accounts', accounts)
|
||||
})
|
||||
.catch(err => {
|
||||
event.sender.send('error-refresh-accounts', err)
|
||||
})
|
||||
const accounts = await accountManager.refreshAccounts(proxy)
|
||||
|
||||
return accounts
|
||||
})
|
||||
|
||||
ipcMain.on('remove-all-accounts', (event: IpcMainEvent) => {
|
||||
|
|
|
@ -68,19 +68,10 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
|||
return accounts
|
||||
},
|
||||
// Fetch account informations and save current state when GlobalHeader is displayed
|
||||
refreshAccounts: ({ commit }): Promise<Array<LocalAccount>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
win.ipcRenderer.send('refresh-accounts')
|
||||
win.ipcRenderer.once('error-refresh-accounts', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-refresh-accounts')
|
||||
reject(err)
|
||||
})
|
||||
win.ipcRenderer.once('response-refresh-accounts', (_, accounts: Array<LocalAccount>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-refresh-accounts')
|
||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||
resolve(accounts)
|
||||
})
|
||||
})
|
||||
refreshAccounts: async ({ commit }): Promise<Array<LocalAccount>> => {
|
||||
const accounts: Array<LocalAccount> = await win.ipcRenderer.invoke('refresh-accounts')
|
||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||
return accounts
|
||||
},
|
||||
watchShortcutEvents: ({ state, commit, rootState, rootGetters }) => {
|
||||
win.ipcRenderer.on('change-account', (_, account: LocalAccount) => {
|
||||
|
|
Loading…
Reference in New Issue