diff --git a/src/main/index.ts b/src/main/index.ts index 047630f5..d4f0d808 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -994,16 +994,10 @@ ipcMain.handle('save-hashtag', async (_: IpcMainInvokeEvent, tag: string) => { await hashtags.insertTag(tag) }) -ipcMain.on('list-hashtags', (event: IpcMainEvent) => { +ipcMain.handle('list-hashtags', async (_: IpcMainInvokeEvent) => { const hashtags = new Hashtags(hashtagsDB) - hashtags - .listTags() - .then(tags => { - event.sender.send('response-list-hashtags', tags) - }) - .catch(err => { - event.sender.send('error-list-hashtags', err) - }) + const tags = await hashtags.listTags() + return tags }) ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Hashtag/List.ts b/src/renderer/store/TimelineSpace/Contents/Hashtag/List.ts index 79847846..4362690c 100644 --- a/src/renderer/store/TimelineSpace/Contents/Hashtag/List.ts +++ b/src/renderer/store/TimelineSpace/Contents/Hashtag/List.ts @@ -24,19 +24,10 @@ const mutations: MutationTree = { } const actions: ActionTree = { - listTags: ({ commit }) => { - return new Promise((resolve, reject) => { - win.ipcRenderer.once('response-list-hashtags', (_, tags: Array) => { - win.ipcRenderer.removeAllListeners('error-list-hashtags') - commit(MUTATION_TYPES.UPDATE_TAGS, tags) - resolve(tags) - }) - win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => { - win.ipcRenderer.removeAllListeners('response-list-hashtags') - reject(err) - }) - win.ipcRenderer.send('list-hashtags') - }) + listTags: async ({ commit }) => { + const tags: Array = await win.ipcRenderer.invoke('list-hashtags') + commit(MUTATION_TYPES.UPDATE_TAGS, tags) + return tags }, removeTag: ({ dispatch }, tag: LocalTag) => { return new Promise((resolve, reject) => { diff --git a/src/renderer/store/TimelineSpace/SideMenu.ts b/src/renderer/store/TimelineSpace/SideMenu.ts index bc5ccf09..b4079632 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.ts +++ b/src/renderer/store/TimelineSpace/SideMenu.ts @@ -149,19 +149,10 @@ const actions: ActionTree = { commit(MUTATION_TYPES.CHANGE_COLLAPSE, value) return value }, - listTags: ({ commit }) => { - return new Promise((resolve, reject) => { - win.ipcRenderer.once('response-list-hashtags', (_, tags: Array) => { - win.ipcRenderer.removeAllListeners('error-list-hashtags') - commit(MUTATION_TYPES.UPDATE_TAGS, tags) - resolve(tags) - }) - win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => { - win.ipcRenderer.removeAllListeners('response-list-hashtags') - reject(err) - }) - win.ipcRenderer.send('list-hashtags') - }) + listTags: async ({ commit }) => { + const tags: Array = await win.ipcRenderer.invoke('list-hashtags') + commit(MUTATION_TYPES.UPDATE_TAGS, tags) + return tags } }