From 81c0781dae3cdd5d3f393513f6aa19178f3ff836 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sun, 29 Nov 2020 23:46:45 +0900 Subject: [PATCH] refactor: Use invoke for ipc to get cache accounts --- src/main/index.ts | 4 +-- .../TimelineSpace/Modals/NewToot/Status.ts | 26 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 349589ca..726b369f 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1038,9 +1038,9 @@ ipcMain.handle('insert-cache-hashtags', async (_: IpcMainInvokeEvent, tags: Arra ) }) -ipcMain.on('get-cache-accounts', async (event: IpcMainEvent, ownerID: string) => { +ipcMain.handle('get-cache-accounts', async (_: IpcMainInvokeEvent, ownerID: string) => { const accounts = await accountCache.listAccounts(ownerID) - event.sender.send('response-get-cache-accounts', accounts) + return accounts }) ipcMain.on('insert-cache-accounts', (event: IpcMainEvent, obj: InsertAccountCache) => { diff --git a/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts b/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts index 37cc159f..e17c9662 100644 --- a/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts +++ b/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts @@ -150,21 +150,17 @@ const actions: ActionTree = { commit(MUTATION_TYPES.CLEAR_FILTERED_ACCOUNTS) commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS) const { word, start } = wordStart - const searchCache = () => { - return new Promise(resolve => { - const target = word.replace('@', '') - win.ipcRenderer.once('response-get-cache-accounts', (_, accounts: Array) => { - const matched = accounts.map(account => account.acct).filter(acct => acct.includes(target)) - if (matched.length === 0) throw new Error('Empty') - commit(MUTATION_TYPES.APPEND_FILTERED_ACCOUNTS, matched) - commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true) - commit(MUTATION_TYPES.CHANGE_START_INDEX, start) - commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word) - commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS) - resolve(matched) - }) - win.ipcRenderer.send('get-cache-accounts', rootState.TimelineSpace.account._id) - }) + const searchCache = async () => { + const target = word.replace('@', '') + const accounts: Array = await win.ipcRenderer.invoke('get-cache-accounts', rootState.TimelineSpace.account._id) + const matched = accounts.map(account => account.acct).filter(acct => acct.includes(target)) + if (matched.length === 0) throw new Error('Empty') + commit(MUTATION_TYPES.APPEND_FILTERED_ACCOUNTS, matched) + commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true) + commit(MUTATION_TYPES.CHANGE_START_INDEX, start) + commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word) + commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS) + return matched } const searchAPI = async () => { const client = generator(