diff --git a/src/main/services/account-manager.ts b/src/main/services/account-manager.ts index 0878702..c7509a1 100644 --- a/src/main/services/account-manager.ts +++ b/src/main/services/account-manager.ts @@ -1,4 +1,5 @@ -import { BrowserWindow } from 'electron' +import { BrowserWindow, Notification, nativeImage, app } from 'electron' +import { join } from 'node:path' import type { AccountConfig, ImapCredentials } from '@shared/types/account' import { AccountType } from '@shared/types/account' import type { IEmailProvider, FolderListResult, MessageListResult } from '@shared/types/provider' @@ -391,6 +392,31 @@ export class AccountManager { if (this.mainWindow && !this.mainWindow.isDestroyed()) { this.mainWindow.webContents.send('mail:new', { accountId, folderId, envelope }) } + + if (Notification.isSupported()) { + const from = envelope.from.name || envelope.from.email || 'Новое письмо' + const subject = envelope.subject || '(без темы)' + + const iconPath = app.isPackaged + ? join(process.resourcesPath, 'icon.png') + : join(app.getAppPath(), 'resources/icon.png') + const icon = nativeImage.createFromPath(iconPath) + + const n = new Notification({ + title: from, + body: subject, + icon: icon.isEmpty() ? undefined : icon, + silent: false, + }) + n.on('click', () => { + if (this.mainWindow && !this.mainWindow.isDestroyed()) { + this.mainWindow.show() + this.mainWindow.focus() + this.mainWindow.webContents.send('notification:click', { accountId, folderId, messageId: envelope.id }) + } + }) + n.show() + } }) } } diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index de269c6..a251bee 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -1,12 +1,39 @@