feat: use Electron's native Notification API for reliable alerts

Replace custom 'showNotification' with Electron's 'Notification' for system-level alerts.

Co-authored-by: Jason <159670257+Jasonzhu1207@users.noreply.github.com>
This commit is contained in:
v0
2026-04-05 17:47:14 +00:00
parent c92b50b6ec
commit 792621d982

View File

@@ -18,10 +18,9 @@ import http from 'http'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { URL } from 'url' import { URL } from 'url'
import { app } from 'electron' import { app, Notification } from 'electron'
import { ConfigService } from './config' import { ConfigService } from './config'
import { chatService, ChatSession, Message } from './chatService' import { chatService, ChatSession, Message } from './chatService'
import { showNotification } from '../windows/notificationWindow'
// ─── 常量 ──────────────────────────────────────────────────────────────────── // ─── 常量 ────────────────────────────────────────────────────────────────────
@@ -666,12 +665,18 @@ class InsightService {
const insight = result.slice(0, 120) const insight = result.slice(0, 120)
insightLog('INFO', `推送通知 → ${displayName}: ${insight}`) insightLog('INFO', `推送通知 → ${displayName}: ${insight}`)
await showNotification({
sessionId, // 使用 Electron 原生系统通知,确保 Windows 右下角弹窗可靠显示
sourceName: `见解 · ${displayName}`, if (Notification.isSupported()) {
content: insight, const notif = new Notification({
isInsight: true title: `见解 · ${displayName}`,
}) body: insight,
silent: false
})
notif.show()
} else {
insightLog('WARN', '当前系统不支持原生通知')
}
insightLog('INFO', `已为 ${displayName} 推送见解`) insightLog('INFO', `已为 ${displayName} 推送见解`)
} catch (e) { } catch (e) {