fix: системные уведомления (отправитель + тема) и глобальный таймер опроса
- Восстановлен Electron Notification в setupNewMailListener: title = имя/адрес отправителя, body = тема письма; клик фокусирует окно и навигирует к письму через notification:click IPC - Восстановлен обработчик notification:click в NotificationContainer.vue - Таймер опроса новых писем перенесён из MessageList.vue в App.vue: теперь работает непрерывно при любом активном представлении (Настройки, Календарь) — раньше останавливался при смене вкладки - refresh() в MessageList.vue больше не вызывает messages:poll — это теперь задача глобального таймера в App.vue Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
19f73efde2
commit
aaf701425b
4 changed files with 61 additions and 8 deletions
|
|
@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,39 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useAccountsStore } from './stores/accounts.store'
|
||||
import { useSettingsStore } from './stores/settings.store'
|
||||
import { useIpc } from './composables/useIpc'
|
||||
|
||||
const accountsStore = useAccountsStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
const { invoke } = useIpc()
|
||||
|
||||
onMounted(() => {
|
||||
accountsStore.loadAccounts()
|
||||
})
|
||||
|
||||
// ── Глобальный таймер опроса новых писем ──────────────────
|
||||
// Живёт на уровне App, не останавливается при смене вкладки
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
function pollAllAccounts(): void {
|
||||
for (const acc of accountsStore.accounts) {
|
||||
if (accountsStore.connectionStatus[acc.id]?.connected) {
|
||||
invoke('messages:poll', { accountId: acc.id }).catch(() => {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restartPollTimer(): void {
|
||||
if (pollTimer) { clearInterval(pollTimer); pollTimer = null }
|
||||
if (settingsStore.autoCheckInterval > 0) {
|
||||
pollTimer = setInterval(pollAllAccounts, settingsStore.autoCheckInterval * 60_000)
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => settingsStore.autoCheckInterval, restartPollTimer)
|
||||
onMounted(restartPollTimer)
|
||||
onUnmounted(() => { if (pollTimer) clearInterval(pollTimer) })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -214,12 +214,6 @@ function onExpandAfterLeave(el: Element): void {
|
|||
// ── Refresh ───────────────────────────────────────────────
|
||||
async function refresh(): Promise<void> {
|
||||
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
|
||||
// Проверяем новые письма во всех подключённых аккаунтах (не только активном)
|
||||
for (const acc of accountsStore.accounts) {
|
||||
if (accountsStore.connectionStatus[acc.id]?.connected) {
|
||||
invoke('messages:poll', { accountId: acc.id }).catch(() => {})
|
||||
}
|
||||
}
|
||||
// Последовательно: loadMessages держит mailboxLock, STATUS упадёт если папка залочена параллельно
|
||||
await messagesStore.loadMessages(accountsStore.activeAccountId, foldersStore.activeFolderId, 0)
|
||||
await foldersStore.refreshUnreadCounts(accountsStore.activeAccountId)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,12 @@ onMounted(() => {
|
|||
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)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue