mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-09 08:18:44 +01:00
refactor: Use invoke for ipc to get unread notification
This commit is contained in:
parent
ad94355eda
commit
faa5e27a03
@ -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) => {
|
||||
|
@ -29,25 +29,20 @@ const mutations: MutationTree<TimelineState> = {
|
||||
}
|
||||
|
||||
const actions: ActionTree<TimelineState, RootState> = {
|
||||
loadUnreadNotification: ({ commit, rootState }): Promise<boolean> => {
|
||||
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<boolean> => {
|
||||
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<boolean> => {
|
||||
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
||||
|
@ -184,24 +184,17 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
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 })
|
||||
|
Loading…
x
Reference in New Issue
Block a user