From 27775603e2eaee9190f1630486f0f6d7b1884723 Mon Sep 17 00:00:00 2001 From: Aero Mail Dev Date: Thu, 16 Apr 2026 06:06:28 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20Web?= =?UTF-8?q?=20Notification=20API=20=D0=B8=D0=B7=20renderer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Electron Notification из main-процесса молча игнорируется системой в dev-режиме (нет .desktop-регистрации). Исходный код использовал window.Notification из renderer — и он работал. - Убраны Notification/nativeImage/app из account-manager.ts (Electron-нативная нотификация из main-процесса удалена) - В NotificationContainer.vue восстановлена showOsNotification: Web Notification API, отправитель — title, тема — body; клик по уведомлению открывает письмо прямо из обработчика - Разрешение запрашивается при старте приложения превентивно - Удалён неиспользуемый канал notification:click из IpcEventMap Co-Authored-By: Claude Sonnet 4.6 --- src/main/services/account-manager.ts | 28 +------------- .../notifications/NotificationContainer.vue | 38 +++++++++++++++---- src/shared/types/ipc.ts | 1 - 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/main/services/account-manager.ts b/src/main/services/account-manager.ts index c7509a1..0878702 100644 --- a/src/main/services/account-manager.ts +++ b/src/main/services/account-manager.ts @@ -1,5 +1,4 @@ -import { BrowserWindow, Notification, nativeImage, app } from 'electron' -import { join } from 'node:path' +import { BrowserWindow } from 'electron' import type { AccountConfig, ImapCredentials } from '@shared/types/account' import { AccountType } from '@shared/types/account' import type { IEmailProvider, FolderListResult, MessageListResult } from '@shared/types/provider' @@ -392,31 +391,6 @@ 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/components/notifications/NotificationContainer.vue b/src/renderer/src/components/notifications/NotificationContainer.vue index 3756192..831ddd0 100644 --- a/src/renderer/src/components/notifications/NotificationContainer.vue +++ b/src/renderer/src/components/notifications/NotificationContainer.vue @@ -47,20 +47,42 @@ function handleClick(id: string): void { removeToast(id) } +function showOsNotification(from: string, subject: string, onClick: () => void): void { + if (!('Notification' in window)) return + const send = (): void => { + const n = new window.Notification(from, { body: subject, silent: false }) + n.onclick = () => { onClick(); n.close() } + } + if (Notification.permission === 'granted') { + send() + } else if (Notification.permission !== 'denied') { + Notification.requestPermission().then(p => { if (p === 'granted') send() }) + } +} + onMounted(() => { + // Запрашиваем разрешение заранее, чтобы не задерживать первое уведомление + if ('Notification' in window && Notification.permission === 'default') { + Notification.requestPermission() + } + on('mail:new', ({ accountId, folderId, envelope }) => { const account = accountsStore.accounts.find(a => a.id === accountId) if (!account) return if (notificationsStore.isMuted(accountId, folderId)) return - const from = envelope.from.name || envelope.from.email - const subject = envelope.subject || '(без темы)' - addToast({ from, subject, accountEmail: account.email, accountId, folderId, messageId: envelope.id }) - }) - on('notification:click', ({ accountId, folderId, messageId }) => { - accountsStore.setActive(accountId) - foldersStore.setActiveFolder(folderId) - messagesStore.selectMessage(messageId) + const from = envelope.from.name || envelope.from.email || 'Новое письмо' + const subject = envelope.subject || '(без темы)' + + // Системное уведомление — показываем всегда; клик фокусирует окно и открывает письмо + showOsNotification(from, subject, () => { + accountsStore.setActive(accountId) + foldersStore.setActiveFolder(folderId) + messagesStore.selectMessage(envelope.id) + }) + + // In-app тост — дополнительная индикация внутри приложения + addToast({ from, subject, accountEmail: account.email, accountId, folderId, messageId: envelope.id }) }) }) diff --git a/src/shared/types/ipc.ts b/src/shared/types/ipc.ts index 7c84ff2..09a6ad4 100644 --- a/src/shared/types/ipc.ts +++ b/src/shared/types/ipc.ts @@ -64,7 +64,6 @@ export interface IpcEventMap { 'mail:new': { accountId: string; folderId: string; envelope: MessageEnvelope } 'account:status': { accountId: string; connected: boolean; error?: string } 'attachment:progress': { attachmentId: string; stage: 'downloading' | 'saving' | 'done' | 'error'; progress: number; error?: string } - 'notification:click': { accountId: string; folderId: string; messageId: string } } export type IpcChannel = keyof IpcChannelMap