From e155419219990504c046ee5f0d662b86382baf63 Mon Sep 17 00:00:00 2001 From: vodyanoysh Date: Thu, 16 Apr 2026 20:26:38 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=83=D1=82=D0=B5=D1=87=D0=BA=D0=B0=20I?= =?UTF-8?q?PC-=D1=81=D0=BB=D1=83=D1=88=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=B2=20NotificationContainer=20=E2=80=94=20=D0=B4=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=D0=BD=D1=8B=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NotificationContainer регистрировал on('mail:new') в onMounted без cleanup. MailView (и весь его поддерев AppShell → NotificationContainer) размонтируется при переходе на /settings или /calendar, поэтому каждый возврат на главную добавлял новый слушатель ipcRenderer. Накопленные слушатели давали N OS-уведомлений на одно входящее письмо. Исправление: сохраняем возвращаемую функцию отписки и вызываем её в onUnmounted. Добавлен CLAUDE.md с описанием паттерна очистки IPC-слушателей, архитектурой и схемой потока уведомлений. Co-Authored-By: Claude Sonnet 4.6 --- CLAUDE.md | 85 +++++++++++++++++++ .../notifications/NotificationContainer.vue | 9 +- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..b9e5b7c --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,85 @@ +# Aero Mail — Developer Notes + +## Stack + +Electron 35 + Vue 3 Composition API + Pinia + TypeScript + electron-vite. +IMAP (imapflow) for reading, SMTP (nodemailer) for sending. +No Gmail API / Exchange EWS — IMAP+SMTP only. + +## Architecture + +Three Electron processes: **main** / **preload** (contextBridge `window.api`) / **renderer** (Vue SPA). + +IPC: type-safe `invoke` (Renderer→Main) + push events (Main→Renderer). +Types live in `src/shared/types/ipc.ts`. + +Key files: + +| File | Role | +|------|------| +| `src/main/index.ts` | Electron entry, window management | +| `src/main/services/account-manager.ts` | Provider map, IPC routing, auto-reconnect | +| `src/main/providers/imap.provider.ts` | IMAP+SMTP implementation | +| `src/renderer/src/stores/messages.store.ts` | Message list, LRU body cache, search | +| `src/renderer/src/stores/folders.store.ts` | Folder tree, unread counts | +| `src/shared/types/ipc.ts` | All IPC channels | + +## IPC event listeners — required cleanup pattern + +`window.api.on(channel, callback)` wraps `ipcRenderer.on` and returns an **unsubscribe function**. +If the component that registers a listener can be unmounted (i.e. it lives inside a ``), +the unsubscribe **must** be called in `onUnmounted`, otherwise listeners accumulate on every remount. + +```ts +// CORRECT +let unsub: (() => void) | null = null + +onMounted(() => { + unsub = on('mail:new', handler) +}) + +onUnmounted(() => { + unsub?.() +}) +``` + +```ts +// BUG — listener survives unmount, fires N times after N navigations +onMounted(() => { + on('mail:new', handler) // return value discarded +}) +``` + +Pinia store setup functions run once (singleton) — `on()` calls inside them do not need cleanup. + +Background: `NotificationContainer.vue` had this bug. It is mounted inside `MailView` which unmounts +on every route change (→ Settings, → Calendar). Each remount registered a new `mail:new` listener, +causing duplicate OS push notifications per incoming email. +Fixed in commit on branch `feature/fix-notifications`. + +## New-mail notification flow + +``` +IMAP exists event + → ImapProvider.pollSingleFolder() + └→ pollFolderTree() ← dedup via lastUnseenCount + notifiedUids (5 min TTL) + +App.vue poll timer (autoCheckInterval) + → messages:poll IPC + └→ AccountManager.pollNewMessages() + └→ ImapProvider.pollFolderTree() ← same dedup + +Both paths → newMailCallback → main sends mail:new IPC → renderer + → NotificationContainer: OS Notification + in-app toast + → messages.store: insert envelope, update unread count +``` + +Dedup keys in `ImapProvider`: `"folderPath:uid"`, TTL 5 min. `lastUnseenCount` is updated +**before** acquiring the mailbox lock, so concurrent runs of `pollFolderTree` for the same folder +see the updated count and skip the second notification. + +## Folder mute + +`notifications.store.ts` stores muted folders in `localStorage` (`muted-folders` key). +Mute is per `accountId:folderId`, supports duration (ms) or permanent (`null`). +Mute check walks up the folder parent chain — muting a parent silences all children. diff --git a/src/renderer/src/components/notifications/NotificationContainer.vue b/src/renderer/src/components/notifications/NotificationContainer.vue index 831ddd0..4382ccf 100644 --- a/src/renderer/src/components/notifications/NotificationContainer.vue +++ b/src/renderer/src/components/notifications/NotificationContainer.vue @@ -1,5 +1,5 @@