From 595d6c9c6aa3b47535aea0ede61de6d288173044 Mon Sep 17 00:00:00 2001 From: "d.a.kolesov" Date: Wed, 1 Apr 2026 14:13:09 +0700 Subject: [PATCH 1/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0=20HTML-=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B5=D0=BC=20+=20=D0=BF=D0=BE=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MessageBody: постобработка HTML через DOMParser — убирает белый цвет текста когда фон тоже светлый (белый-на-белом), охватывает inline styles и атрибуты color/bgcolor - MessageHeader: адреса «От», «Кому», «Копия» стали кликабельными; по клику открывается liquid glass попап с именем, email и кнопкой копирования Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/preview/MessageBody.vue | 76 ++++- .../src/components/preview/MessageHeader.vue | 300 ++++++++++++++++-- 2 files changed, 339 insertions(+), 37 deletions(-) diff --git a/src/renderer/src/components/preview/MessageBody.vue b/src/renderer/src/components/preview/MessageBody.vue index cfc607c..1c05b03 100644 --- a/src/renderer/src/components/preview/MessageBody.vue +++ b/src/renderer/src/components/preview/MessageBody.vue @@ -8,20 +8,79 @@ const props = defineProps<{ const iframeRef = ref(null) +// ── Исправление цветов HTML-писем ───────────────────────── +// Некоторые письма используют белый текст в секциях с белым фоном. +// Обходим DOM и убираем явный белый цвет текста там, где фон тоже светлый. + +function isNearWhite(s: string): boolean { + s = s.trim().toLowerCase().replace(/\s+/g, '') + if (!s || s === 'transparent' || s === 'rgba(0,0,0,0)') return false + if (s === 'white' || s === '#fff' || s === '#ffffff') return true + const h6 = s.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) + if (h6) return parseInt(h6[1], 16) >= 200 && parseInt(h6[2], 16) >= 200 && parseInt(h6[3], 16) >= 200 + const h3 = s.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/) + if (h3) return parseInt(h3[1] + h3[1], 16) >= 200 && parseInt(h3[2] + h3[2], 16) >= 200 && parseInt(h3[3] + h3[3], 16) >= 200 + const rgb = s.match(/^rgb\((\d+),(\d+),(\d+)\)$/) + if (rgb) return +rgb[1] >= 200 && +rgb[2] >= 200 && +rgb[3] >= 200 + const rgba = s.match(/^rgba\((\d+),(\d+),(\d+),([\d.]+)\)$/) + if (rgba) return +rgba[1] >= 200 && +rgba[2] >= 200 && +rgba[3] >= 200 && +rgba[4] > 0.3 + return false +} + +function getExplicitBg(el: HTMLElement): string { + return el.style.backgroundColor || el.style.background || el.getAttribute('bgcolor') || '' +} + +function findNearestBg(el: HTMLElement): string { + let node: HTMLElement | null = el + while (node) { + const bg = getExplicitBg(node) + if (bg && bg !== 'transparent' && bg !== 'rgba(0, 0, 0, 0)' && bg !== 'rgba(0,0,0,0)') return bg + node = node.parentElement + } + return '' +} + +function postProcessHtml(html: string): string { + try { + const parser = new DOMParser() + const doc = parser.parseFromString(html, 'text/html') + + const candidates = doc.querySelectorAll('[style*="color"], [color], font[color]') + for (const el of candidates) { + const fg = el.style.color || el.getAttribute('color') || '' + if (!fg || !isNearWhite(fg)) continue + + // Белый текст — проверяем фон в контексте элемента + const bg = findNearestBg(el) + // Если фон тоже светлый или не задан (дефолт белый) → убираем белый цвет + if (!bg || isNearWhite(bg)) { + if (el.style.color) el.style.removeProperty('color') + el.removeAttribute('color') + } + } + + return doc.documentElement.outerHTML + } catch { + return html + } +} + +// ── Вычисленный HTML ─────────────────────────────────────── + const processedHtml = computed(() => { if (!props.body.html) return null let html = props.body.html - // Replace CID references with base64 data URLs + // Подставляем inline-изображения for (const img of props.body.inlineImages) { - html = html.replaceAll( - `cid:${img.cid}`, - `data:${img.contentType};base64,${img.data}` - ) + html = html.replaceAll(`cid:${img.cid}`, `data:${img.contentType};base64,${img.data}`) } - // Wrap in a dark-themed document + // Фиксируем белый текст на белом фоне + html = postProcessHtml(html) + return ` @@ -110,7 +169,7 @@ const plainTextHtml = computed(() => { const srcdoc = computed(() => processedHtml.value ?? plainTextHtml.value ?? '') -// ── Ambient glow: извлекаем доминирующий цвет фона письма ── +// ── Ambient glow ─────────────────────────────────────────── function parseRgb(color: string): { r: number; g: number; b: number; a: number } | null { const m = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/) @@ -150,14 +209,12 @@ function onIframeLoad(): void { const view = iframeRef.value?.contentWindow if (!doc?.body || !view) return - // Пробуем body напрямую const bodyColor = parseRgb(view.getComputedStyle(doc.body).backgroundColor) if (bodyColor && bodyColor.a > 0.1 && bodyColor.r + bodyColor.g + bodyColor.b > 60) { setContentGlow(bodyColor.r, bodyColor.g, bodyColor.b, 0.26) return } - // Многие HTML-письма кладут фон в первый или
const firstEl = doc.body.querySelector('table, td, [bgcolor]') if (firstEl) { const raw = firstEl.getAttribute('bgcolor') ?? view.getComputedStyle(firstEl).backgroundColor @@ -172,7 +229,6 @@ function onIframeLoad(): void { clearContentGlow() } -// Сбрасываем свечение при смене письма watch(() => props.body, () => clearContentGlow()) onUnmounted(() => { diff --git a/src/renderer/src/components/preview/MessageHeader.vue b/src/renderer/src/components/preview/MessageHeader.vue index 69808e0..8ce6389 100644 --- a/src/renderer/src/components/preview/MessageHeader.vue +++ b/src/renderer/src/components/preview/MessageHeader.vue @@ -1,6 +1,6 @@ diff --git a/src/renderer/src/stores/settings.store.ts b/src/renderer/src/stores/settings.store.ts index 6d9a7d2..9621fb9 100644 --- a/src/renderer/src/stores/settings.store.ts +++ b/src/renderer/src/stores/settings.store.ts @@ -85,6 +85,7 @@ function load(): { accentColor?: string autoCheckInterval?: number uiScale?: number + downloadFolder?: string } { try { return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}') @@ -101,6 +102,14 @@ export const useSettingsStore = defineStore('settings', () => { const accentColor = ref(saved.accentColor ?? '#a8e600') const autoCheckInterval = ref(saved.autoCheckInterval ?? 5) const uiScale = ref(saved.uiScale ?? 1.0) + const downloadFolder = ref(saved.downloadFolder ?? '') + + // Если папка не сохранена — подтягиваем системный Downloads + if (!downloadFolder.value) { + window.api.invoke('app:getDownloadsFolder').then((path) => { + if (!downloadFolder.value) downloadFolder.value = path + }) + } // Apply on init applyAccentColor(accentColor.value) @@ -116,7 +125,7 @@ export const useSettingsStore = defineStore('settings', () => { persist() }) - watch([swipeLeftAction, swipeRightAction, autoCheckInterval], persist) + watch([swipeLeftAction, swipeRightAction, autoCheckInterval, downloadFolder], persist) function persist(): void { localStorage.setItem(STORAGE_KEY, JSON.stringify({ @@ -125,8 +134,9 @@ export const useSettingsStore = defineStore('settings', () => { accentColor: accentColor.value, autoCheckInterval: autoCheckInterval.value, uiScale: uiScale.value, + downloadFolder: downloadFolder.value, })) } - return { swipeLeftAction, swipeRightAction, accentColor, autoCheckInterval, uiScale } + return { swipeLeftAction, swipeRightAction, accentColor, autoCheckInterval, uiScale, downloadFolder } }) diff --git a/src/renderer/src/views/SettingsView.vue b/src/renderer/src/views/SettingsView.vue index 971fda6..d62d164 100644 --- a/src/renderer/src/views/SettingsView.vue +++ b/src/renderer/src/views/SettingsView.vue @@ -4,6 +4,7 @@ import { useAccountsStore } from '../stores/accounts.store' import { useSettingsStore, SWIPE_ACTION_LABELS, ACCENT_QUICK_PICKS, AUTO_CHECK_INTERVALS, type SwipeAction } from '../stores/settings.store' import CustomSelect from '../components/CustomSelect.vue' import ColorPicker from '../components/ColorPicker.vue' +import AppIcon from '../components/AppIcon.vue' const router = useRouter() const accountsStore = useAccountsStore() @@ -12,6 +13,22 @@ const settingsStore = useSettingsStore() const swipeOptions: { value: SwipeAction; label: string }[] = ( ['delete', 'toggleRead', 'toggleFlag', 'none'] as SwipeAction[] ).map((v) => ({ value: v, label: SWIPE_ACTION_LABELS[v] })) + +async function chooseDownloadFolder(): Promise { + const picked = await window.api.invoke('app:chooseFolder') + if (picked) settingsStore.downloadFolder = picked +} + +async function resetDownloadFolder(): Promise { + settingsStore.downloadFolder = await window.api.invoke('app:getDownloadsFolder') +} + +function folderDisplayName(path: string): string { + if (!path) return '' + // Показываем последние 2 сегмента пути для читаемости + const parts = path.replace(/\\/g, '/').split('/').filter(Boolean) + return parts.length > 2 ? '…/' + parts.slice(-2).join('/') : path +}