diff --git a/src/main/index.ts b/src/main/index.ts index fad01606..9d4fb9bd 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1012,18 +1012,11 @@ ipcMain.handle('list-fonts', async (_: IpcMainInvokeEvent) => { }) // Unread notifications -ipcMain.on('get-unread-notification', (event: IpcMainEvent, accountID: string) => { - unreadNotification - .findOne({ - accountID: accountID - }) - .then(doc => { - event.sender.send('response-get-unread-notification', doc) - }) - .catch(err => { - console.warn(err) - event.sender.send('error-get-unread-notification', err) - }) +ipcMain.handle('get-unread-notification', async (_: IpcMainInvokeEvent, accountID: string) => { + const doc = await unreadNotification.findOne({ + accountID: accountID + }) + return doc }) ipcMain.on('update-unread-notification', (event: IpcMainEvent, config: UnreadNotificationConfig) => { diff --git a/src/renderer/store/Settings/Timeline.ts b/src/renderer/store/Settings/Timeline.ts index 46a0e437..858a6b7c 100644 --- a/src/renderer/store/Settings/Timeline.ts +++ b/src/renderer/store/Settings/Timeline.ts @@ -29,25 +29,20 @@ const mutations: MutationTree = { } const actions: ActionTree = { - loadUnreadNotification: ({ commit, rootState }): Promise => { - return new Promise(resolve => { - win.ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => { - win.ipcRenderer.removeAllListeners('error-get-unread-notification') - commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) - resolve(true) - }) - win.ipcRenderer.once('error-get-unread-notification', () => { - win.ipcRenderer.removeAllListeners('response-get-unread-notification') - const settings: UnreadNotification = { - direct: unreadSettings.Direct.default, - local: unreadSettings.Local.default, - public: unreadSettings.Public.default - } - commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) - resolve(false) - }) - win.ipcRenderer.send('get-unread-notification', rootState.Settings.accountID) - }) + loadUnreadNotification: async ({ commit, rootState }): Promise => { + try { + const settings: UnreadNotification = await win.ipcRenderer.invoke('get-unread-notification', rootState.Settings.accountID) + commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) + return true + } catch (err) { + const settings: UnreadNotification = { + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default + } + commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) + return false + } }, changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise => { const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, { diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index 774582ec..0763cf2a 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -184,24 +184,17 @@ const actions: ActionTree = { commit(MUTATION_TYPES.UPDATE_TOOT_MAX, res.data.max_toot_chars) return true }, - loadUnreadNotification: ({ commit }, accountID: string) => { - return new Promise(resolve => { - win.ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => { - win.ipcRenderer.removeAllListeners('error-get-unread-notification') - commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) - resolve(settings) - }) - win.ipcRenderer.once('error-get-unread-notification', () => { - win.ipcRenderer.removeAllListeners('response-get-unread-notification') - commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, { - direct: unreadSettings.Direct.default, - local: unreadSettings.Local.default, - public: unreadSettings.Public.default - } as UnreadNotification) - resolve({}) - }) - win.ipcRenderer.send('get-unread-notification', accountID) - }) + loadUnreadNotification: async ({ commit }, accountID: string) => { + try { + const settings: UnreadNotification = await win.ipcRenderer.invoke('get-unread-notification', accountID) + commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings) + } catch (err) { + commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, { + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default + } as UnreadNotification) + } }, fetchContentsTimelines: async ({ dispatch, state }) => { dispatch('TimelineSpace/Contents/changeLoading', true, { root: true })