diff --git a/src/main/ipc/accounts.handler.ts b/src/main/ipc/accounts.handler.ts index 234ef68..99d6ccc 100644 --- a/src/main/ipc/accounts.handler.ts +++ b/src/main/ipc/accounts.handler.ts @@ -21,4 +21,8 @@ export function registerAccountHandlers(manager: AccountManager): void { registerHandler('accounts:connect', async ({ accountId }) => { return manager.connectAccount(accountId) }) + + registerHandler('accounts:update', async (config) => { + return manager.updateAccount(config) + }) } diff --git a/src/main/services/account-manager.ts b/src/main/services/account-manager.ts index ebdebb0..b2741a1 100644 --- a/src/main/services/account-manager.ts +++ b/src/main/services/account-manager.ts @@ -1,6 +1,5 @@ -import { BrowserWindow, Notification, nativeImage } from 'electron' -import { join } from 'node:path' -import type { AccountConfig } from '@shared/types/account' +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' import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData } from '@shared/types/message' @@ -258,33 +257,56 @@ export class AccountManager { } } + async updateAccount(config: AccountConfig): Promise<{ success: boolean; error?: string }> { + try { + // If password is empty string, preserve existing credentials password + const creds = config.credentials as ImapCredentials + let newCredentials = config.credentials + if ('password' in creds && creds.password === '') { + const existingCredRaw = this.credentialStore.get(config.id) + if (existingCredRaw) { + const existing = JSON.parse(existingCredRaw) as ImapCredentials + newCredentials = { ...creds, password: existing.password } + } + } + + const configWithCreds: AccountConfig = { ...config, credentials: newCredentials } + + // Update credentials + await this.credentialStore.save(config.id, JSON.stringify(configWithCreds.credentials)) + + // Update metadata in store + const { credentials: _, ...safeConfig } = configWithCreds + const accounts = this.store.get('accounts', []) + const idx = accounts.findIndex((a) => a.id === config.id) + if (idx === -1) return { success: false, error: 'Account not found' } + accounts[idx] = safeConfig + this.store.set('accounts', accounts) + + // Reconnect if currently connected + const existingProvider = this.providers.get(config.id) + if (existingProvider) { + existingProvider.offNewMail() + try { await existingProvider.disconnect() } catch { /* already disconnected */ } + this.providers.delete(config.id) + + const newProvider = this.createProvider(configWithCreds) + await newProvider.connect() + this.providers.set(config.id, newProvider) + this.setupNewMailListener(config.id, newProvider) + } + + return { success: true } + } catch (error) { + return { success: false, error: (error as Error).message } + } + } + private setupNewMailListener(accountId: string, provider: IEmailProvider): void { provider.onNewMail((folderId, envelope) => { 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 = join(__dirname, '../../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/AppIcon.vue b/src/renderer/src/components/AppIcon.vue index ee01aea..0a8b5d2 100644 --- a/src/renderer/src/components/AppIcon.vue +++ b/src/renderer/src/components/AppIcon.vue @@ -23,6 +23,7 @@ export type IconName = | 'send' | 'pdf' | 'image' + | 'bell-off' const props = defineProps<{ name: IconName @@ -133,6 +134,13 @@ const paths: Record = { `, + 'bell-off': ` + + + + + + `, } diff --git a/src/renderer/src/components/accounts/EditAccountDialog.vue b/src/renderer/src/components/accounts/EditAccountDialog.vue new file mode 100644 index 0000000..aa14d2d --- /dev/null +++ b/src/renderer/src/components/accounts/EditAccountDialog.vue @@ -0,0 +1,541 @@ + + + + + diff --git a/src/renderer/src/components/notifications/NotificationContainer.vue b/src/renderer/src/components/notifications/NotificationContainer.vue index 15cbc76..4f0f937 100644 --- a/src/renderer/src/components/notifications/NotificationContainer.vue +++ b/src/renderer/src/components/notifications/NotificationContainer.vue @@ -5,6 +5,7 @@ import { useIpc } from '../../composables/useIpc' import { useAccountsStore } from '../../stores/accounts.store' import { useFoldersStore } from '../../stores/folders.store' import { useMessagesStore } from '../../stores/messages.store' +import { useNotificationsStore } from '../../stores/notifications.store' interface ToastItem { id: string @@ -24,6 +25,7 @@ const { on } = useIpc() const accountsStore = useAccountsStore() const foldersStore = useFoldersStore() const messagesStore = useMessagesStore() +const notificationsStore = useNotificationsStore() function addToast(item: Omit): void { const id = `toast-${++counter}` @@ -45,44 +47,14 @@ 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() - } - - // Новые письма из любой папки (через pollNewMessages в main) 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 }) - showOsNotification(from, subject, () => { - accountsStore.setActive(accountId) - foldersStore.setActiveFolder(folderId) - messagesStore.selectMessage(envelope.id) - }) - }) - - on('notification:click', ({ accountId, folderId, messageId }) => { - accountsStore.setActive(accountId) - foldersStore.setActiveFolder(folderId) - messagesStore.selectMessage(messageId) }) }) diff --git a/src/renderer/src/components/sidebar/FolderContextMenu.vue b/src/renderer/src/components/sidebar/FolderContextMenu.vue new file mode 100644 index 0000000..f37ab63 --- /dev/null +++ b/src/renderer/src/components/sidebar/FolderContextMenu.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/src/renderer/src/components/sidebar/FolderTreeItem.vue b/src/renderer/src/components/sidebar/FolderTreeItem.vue index 742dbd3..738e4ce 100644 --- a/src/renderer/src/components/sidebar/FolderTreeItem.vue +++ b/src/renderer/src/components/sidebar/FolderTreeItem.vue @@ -4,8 +4,10 @@ import type { Folder } from '@shared/types/folder' import { SpecialFolderRole } from '@shared/types/folder' import { useFoldersStore } from '../../stores/folders.store' import { useAccountsStore } from '../../stores/accounts.store' +import { useNotificationsStore } from '../../stores/notifications.store' import AppIcon from '../AppIcon.vue' import type { IconName } from '../AppIcon.vue' +import FolderContextMenu from './FolderContextMenu.vue' const props = defineProps<{ folder: Folder @@ -14,7 +16,9 @@ const props = defineProps<{ const foldersStore = useFoldersStore() const accountsStore = useAccountsStore() +const notificationsStore = useNotificationsStore() const expanded = ref(true) +const contextMenu = ref<{ x: number; y: number } | null>(null) const isActive = computed(() => foldersStore.activeFolderId === props.folder.id) const hasChildren = computed(() => props.folder.children.length > 0) @@ -22,6 +26,10 @@ const unreadCount = computed(() => { if (!accountsStore.activeAccountId) return 0 return foldersStore.getFolderUnread(accountsStore.activeAccountId, props.folder.id) }) +const isMuted = computed(() => { + if (!accountsStore.activeAccountId) return false + return notificationsStore.isMuted(accountsStore.activeAccountId, props.folder.id) +}) const folderIcon = computed((): IconName => { switch (props.folder.role) { @@ -43,6 +51,29 @@ function toggleExpand(event: Event): void { event.stopPropagation() expanded.value = !expanded.value } + +function handleContextMenu(event: MouseEvent): void { + event.preventDefault() + contextMenu.value = { x: event.clientX, y: event.clientY } +} + +function closeContextMenu(): void { + contextMenu.value = null +} + +function handleMute(durationMs: number | null): void { + if (accountsStore.activeAccountId) { + notificationsStore.muteFolder(accountsStore.activeAccountId, props.folder.id, durationMs) + } + contextMenu.value = null +} + +function handleUnmute(): void { + if (accountsStore.activeAccountId) { + notificationsStore.unmuteFolder(accountsStore.activeAccountId, props.folder.id) + } + contextMenu.value = null +}