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