refs #3119 Create notifications when there are notifications received while Whelbird is not running

This commit is contained in:
AkiraFukushima 2022-02-12 15:36:36 +09:00
parent dfa54aae4d
commit dcb70bd8b9
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
2 changed files with 36 additions and 18 deletions

View File

@ -639,23 +639,8 @@ ipcMain.on('start-all-user-streamings', (event: IpcMainEvent, accounts: Array<Lo
// Cache account
await accountCache.insertAccount(id, update.account.acct).catch(err => console.error(err))
},
(notification: Entity.Notification) => {
const preferences = new Preferences(preferencesDBPath)
preferences.load().then(conf => {
const options = createNotification(notification, conf.notification.notify)
if (options !== null) {
const notify = new Notification(options)
notify.on('click', _ => {
if (!event.sender.isDestroyed()) {
event.sender.send('open-notification-tab', id)
}
})
notify.show()
}
})
if (process.platform === 'darwin') {
app.dock.setBadge('•')
}
async (notification: Entity.Notification) => {
await publishNotification(notification, event, id)
// In macOS and Windows, sometimes window is closed (not quit).
// But streamings are always running.
@ -978,6 +963,13 @@ ipcMain.on('stop-tag-streaming', () => {
}
})
ipcMain.handle(
'publish-notification',
async (event: IpcMainInvokeEvent, notification: { notification: Entity.Notification; id: string }) => {
await publishNotification(notification.notification, event, notification.id)
}
)
// sounds
ipcMain.on('fav-rt-action-sound', () => {
const preferences = new Preferences(preferencesDBPath)
@ -1538,6 +1530,24 @@ async function reopenWindow() {
}
}
const publishNotification = async (notification: Entity.Notification, event: IpcMainEvent | IpcMainInvokeEvent, id: string) => {
const preferences = new Preferences(preferencesDBPath)
const conf = await preferences.load()
const options = createNotification(notification, conf.notification.notify)
if (options !== null) {
const notify = new Notification(options)
notify.on('click', _ => {
if (!event.sender.isDestroyed()) {
event.sender.send('open-notification-tab', id)
}
})
notify.show()
}
if (process.platform === 'darwin') {
app.dock.setBadge('•')
}
}
const createNotification = (notification: Entity.Notification, notifyConfig: Notify): NotificationConstructorOptions | null => {
switch (notification.type) {
case NotificationType.Favourite:

View File

@ -142,9 +142,17 @@ const actions: ActionTree<NotificationsState, RootState> = {
const res = await client.getNotifications({ limit: 30, max_id: localMarker.last_read_id })
// Make sure whether new notifications exist or not
const nextResponse = await client.getNotifications({ limit: 1, min_id: lastReadNotification.id })
const nextResponse = await client.getNotifications({ min_id: lastReadNotification.id })
if (nextResponse.data.length > 0) {
notifications = ([card] as Array<Entity.Notification | LoadingCard>).concat(notifications).concat(res.data)
// Generate notifications received while the app was not running
commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true })
nextResponse.data.forEach(n => {
win.ipcRenderer.invoke('publish-notification', {
notification: n,
id: rootState.TimelineSpace.account._id
})
})
} else {
notifications = notifications.concat(res.data)
}