mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-03 18:57:43 +01:00
refactor: Use invoke for ipc to list accounts
This commit is contained in:
parent
6b03d5a015
commit
07a94c96da
@ -427,16 +427,9 @@ ipcMain.handle('get-access-token', async (_: IpcMainInvokeEvent, request: TokenR
|
|||||||
})
|
})
|
||||||
|
|
||||||
// nedb
|
// nedb
|
||||||
ipcMain.on('list-accounts', (event: IpcMainEvent) => {
|
ipcMain.handle('list-accounts', async (_: IpcMainInvokeEvent) => {
|
||||||
accountManager
|
const accounts = await accountManager.listAccounts()
|
||||||
.listAccounts()
|
return accounts
|
||||||
.catch(err => {
|
|
||||||
log.error(err)
|
|
||||||
event.sender.send('error-list-accounts', err)
|
|
||||||
})
|
|
||||||
.then(accounts => {
|
|
||||||
event.sender.send('response-list-accounts', accounts)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('get-local-account', (event: IpcMainEvent, id: string) => {
|
ipcMain.on('get-local-account', (event: IpcMainEvent, id: string) => {
|
||||||
@ -1191,8 +1184,6 @@ app.on('ready', () => {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class EmptyTokenError {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Genrate application menu
|
* Genrate application menu
|
||||||
*/
|
*/
|
||||||
|
@ -61,20 +61,11 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
|||||||
dispatch('bindNotification')
|
dispatch('bindNotification')
|
||||||
dispatch('startUserStreamings')
|
dispatch('startUserStreamings')
|
||||||
},
|
},
|
||||||
listAccounts: ({ dispatch, commit }): Promise<Array<LocalAccount>> => {
|
listAccounts: async ({ dispatch, commit }): Promise<Array<LocalAccount>> => {
|
||||||
return new Promise((resolve, reject) => {
|
const accounts = await win.ipcRenderer.invoke('list-accounts')
|
||||||
win.ipcRenderer.send('list-accounts', 'list')
|
|
||||||
win.ipcRenderer.once('error-list-accounts', (_, err: Error) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('response-list-accounts')
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
win.ipcRenderer.once('response-list-accounts', (_, accounts: Array<LocalAccount>) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('error-list-accounts')
|
|
||||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||||
dispatch('refreshAccounts')
|
dispatch('refreshAccounts')
|
||||||
resolve(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: ({ commit }): Promise<Array<LocalAccount>> => {
|
||||||
|
@ -30,19 +30,10 @@ const mutations: MutationTree<AccountState> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const actions: ActionTree<AccountState, RootState> = {
|
const actions: ActionTree<AccountState, RootState> = {
|
||||||
loadAccounts: ({ commit }): Promise<Array<LocalAccount>> => {
|
loadAccounts: async ({ commit }): Promise<Array<LocalAccount>> => {
|
||||||
return new Promise((resolve, reject) => {
|
const accounts = await win.ipcRenderer.invoke('list-accounts')
|
||||||
win.ipcRenderer.send('list-accounts', 'list')
|
|
||||||
win.ipcRenderer.once('error-list-accounts', (_, err: Error) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('response-list-accounts')
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
win.ipcRenderer.once('response-list-accounts', (_, accounts: Array<LocalAccount>) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('error-list-accounts')
|
|
||||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||||
resolve(accounts)
|
return accounts
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
removeAccount: (_, account: LocalAccount) => {
|
removeAccount: (_, account: LocalAccount) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user