mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-26 15:45:51 +00:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61ef10de9b | ||
|
|
73f36d6b29 | ||
|
|
666a1a3296 | ||
|
|
2e1c0e6c54 | ||
|
|
7759868664 | ||
|
|
e92df66bef | ||
|
|
354f3fd8e2 | ||
|
|
1201ea33db | ||
|
|
f8e99a34c7 | ||
|
|
1cef17174b | ||
|
|
73cabf2acd | ||
|
|
49770f9e8d | ||
|
|
e32261d274 | ||
|
|
3c7a63e616 | ||
|
|
ab7a487e78 | ||
|
|
f01e2efd3f | ||
|
|
3f4a4f7581 | ||
|
|
7f78925bd7 | ||
|
|
d16423818d | ||
|
|
8cbd3b9625 | ||
|
|
9fac12ce3c | ||
|
|
ee050aa5fa | ||
|
|
a179f13031 | ||
|
|
f3fc5760fc | ||
|
|
d4e04a003c | ||
|
|
2604be38f0 | ||
|
|
06a10f77ae | ||
|
|
73f1355011 | ||
|
|
659b9f9680 | ||
|
|
539f854dbf | ||
|
|
45d4e74c98 | ||
|
|
1d0b101352 | ||
|
|
ed96eeccee | ||
|
|
29d49360f5 | ||
|
|
849cac6a40 | ||
|
|
262b3622dd | ||
|
|
2692ac2408 | ||
|
|
c2502a09a9 | ||
|
|
2ea7c72fc6 | ||
|
|
42aafae29b | ||
|
|
61101382d1 | ||
|
|
ba5a791b2d | ||
|
|
ba189aec6f | ||
|
|
4b17d20325 | ||
|
|
b52bdcf4b3 | ||
|
|
8e8c14a51f | ||
|
|
80786c572a | ||
|
|
a331f45f87 | ||
|
|
4c70ebcaf9 | ||
|
|
7760358c02 | ||
|
|
a163ea377c | ||
|
|
3fabf961e5 | ||
|
|
6f3b60ef2c | ||
|
|
816770d407 | ||
|
|
b5a371da87 |
49
.github/workflows/release.yml
vendored
49
.github/workflows/release.yml
vendored
@@ -121,12 +121,49 @@ jobs:
|
||||
run: |
|
||||
npx electron-builder --publish always
|
||||
|
||||
release-windows-arm64:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Check out git repository
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: 24
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Sync version with tag
|
||||
shell: bash
|
||||
run: |
|
||||
VERSION=${GITHUB_REF_NAME#v}
|
||||
echo "Syncing package.json version to $VERSION"
|
||||
npm version $VERSION --no-git-tag-version --allow-same-version
|
||||
|
||||
- name: Build Frontend & Type Check
|
||||
run: |
|
||||
npx tsc
|
||||
npx vite build
|
||||
|
||||
- name: Package and Publish Windows arm64
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
npx electron-builder --win nsis --arm64 --publish always '--config.artifactName=${productName}-${version}-arm64-Setup.${ext}'
|
||||
|
||||
update-release-notes:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- release-mac-arm64
|
||||
- release-linux
|
||||
- release
|
||||
- release-windows-arm64
|
||||
|
||||
steps:
|
||||
- name: Generate release notes with platform download links
|
||||
@@ -147,10 +184,12 @@ jobs:
|
||||
echo "$ASSETS_JSON" | jq -r --arg p "$pattern" '[.assets[].name | select(test($p))][0] // ""'
|
||||
}
|
||||
|
||||
WINDOWS_ASSET="$(pick_asset "\\.exe$")"
|
||||
WINDOWS_ASSET="$(echo "$ASSETS_JSON" | jq -r '[.assets[].name | select(test("\\.exe$")) | select(test("arm64") | not)][0] // ""')"
|
||||
WINDOWS_ARM64_ASSET="$(echo "$ASSETS_JSON" | jq -r '[.assets[].name | select(test("arm64.*\\.exe$"))][0] // ""')"
|
||||
MAC_ASSET="$(pick_asset "\\.dmg$")"
|
||||
LINUX_DEB_ASSET="$(pick_asset "\\.deb$")"
|
||||
LINUX_TAR_ASSET="$(pick_asset "\\.tar\\.gz$")"
|
||||
LINUX_APPIMAGE_ASSET="$(pick_asset "\\.AppImage$")"
|
||||
|
||||
build_link() {
|
||||
local name="$1"
|
||||
@@ -160,9 +199,11 @@ jobs:
|
||||
}
|
||||
|
||||
WINDOWS_URL="$(build_link "$WINDOWS_ASSET")"
|
||||
WINDOWS_ARM64_URL="$(build_link "$WINDOWS_ARM64_ASSET")"
|
||||
MAC_URL="$(build_link "$MAC_ASSET")"
|
||||
LINUX_DEB_URL="$(build_link "$LINUX_DEB_ASSET")"
|
||||
LINUX_TAR_URL="$(build_link "$LINUX_TAR_ASSET")"
|
||||
LINUX_APPIMAGE_URL="$(build_link "$LINUX_APPIMAGE_ASSET")"
|
||||
|
||||
cat > release_notes.md <<EOF
|
||||
## 更新日志
|
||||
@@ -172,10 +213,12 @@ jobs:
|
||||
[点击加入 Telegram 频道](https://t.me/weflow_cc)
|
||||
|
||||
## 下载
|
||||
- Windows (Win10+): ${WINDOWS_URL:-$RELEASE_PAGE}
|
||||
- Windows x64(Win10+): ${WINDOWS_URL:-$RELEASE_PAGE}
|
||||
- Windows arm64: ${WINDOWS_ARM64_URL:-$RELEASE_PAGE}
|
||||
- macOS(M系列芯片): ${MAC_URL:-$RELEASE_PAGE}
|
||||
- Linux (.deb): ${LINUX_DEB_URL:-$RELEASE_PAGE}
|
||||
- Linux (.deb) (即将废弃): ${LINUX_DEB_URL:-$RELEASE_PAGE}
|
||||
- Linux (.tar.gz): ${LINUX_TAR_URL:-$RELEASE_PAGE}
|
||||
- linux (.AppImage): ${LINUX_APPIMAGE_URL:-$RELEASE_PAGE}
|
||||
|
||||
> 如果某个平台链接暂时未生成,可进入完整发布页查看全部资源:$RELEASE_PAGE
|
||||
EOF
|
||||
|
||||
18
README.md
18
README.md
@@ -43,9 +43,19 @@ WeFlow 是一个**完全本地**的微信**实时**聊天记录查看、分析
|
||||
- HTTP API 接口(供开发者集成)
|
||||
- 查看完整能力清单:[详细功能](#详细功能清单)
|
||||
|
||||
## 支持平台与设备
|
||||
|
||||
|
||||
| 平台 | 设备/架构 | 安装包 |
|
||||
|------|----------|--------|
|
||||
| Windows | Windows10+、x64(amd64) | `.exe` |
|
||||
| macOS | Apple Silicon(M 系列,arm64) | `.dmg` |
|
||||
| Linux | x64 设备(amd64) | `.deb`、`.tar.gz` |
|
||||
|
||||
|
||||
## 快速开始
|
||||
|
||||
若你只想使用成品版本,可前往 Release 下载并安装。
|
||||
若你只想使用成品版本,可前往 [Releases](https://github.com/hicccc77/WeFlow/releases) 下载并安装。
|
||||
|
||||
## 详细功能清单
|
||||
|
||||
@@ -94,14 +104,8 @@ npm install
|
||||
# 3. 运行应用(开发模式)
|
||||
npm run dev
|
||||
|
||||
# 4. 打包可执行文件
|
||||
npm run build
|
||||
```
|
||||
|
||||
打包产物在 `release` 目录下。
|
||||
|
||||
|
||||
|
||||
## 致谢
|
||||
|
||||
- [密语 CipherTalk](https://github.com/ILoveBingLu/miyu) 为本项目提供了基础框架
|
||||
|
||||
@@ -122,6 +122,67 @@ let isDownloadInProgress = false
|
||||
let downloadProgressHandler: ((progress: any) => void) | null = null
|
||||
let downloadedHandler: (() => void) | null = null
|
||||
|
||||
const normalizeReleaseNotes = (rawReleaseNotes: unknown): string => {
|
||||
const merged = (() => {
|
||||
if (typeof rawReleaseNotes === 'string') {
|
||||
return rawReleaseNotes
|
||||
}
|
||||
if (Array.isArray(rawReleaseNotes)) {
|
||||
return rawReleaseNotes
|
||||
.map((item) => {
|
||||
if (!item || typeof item !== 'object') return ''
|
||||
const note = (item as { note?: unknown }).note
|
||||
return typeof note === 'string' ? note : ''
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join('\n\n')
|
||||
}
|
||||
return ''
|
||||
})()
|
||||
|
||||
if (!merged.trim()) return ''
|
||||
|
||||
// 兼容 electron-updater 直接返回 HTML 的场景
|
||||
const removeDownloadSectionFromHtml = (input: string): string => {
|
||||
return input.replace(
|
||||
/<h[1-6][^>]*>\s*(?:下载|download)\s*<\/h[1-6]>\s*[\s\S]*?(?=<h[1-6]\b|$)/gi,
|
||||
''
|
||||
)
|
||||
}
|
||||
|
||||
// 兼容 Markdown 场景(Action 最终 release note 模板)
|
||||
const removeDownloadSectionFromMarkdown = (input: string): string => {
|
||||
const lines = input.split(/\r?\n/)
|
||||
const output: string[] = []
|
||||
let skipDownloadSection = false
|
||||
|
||||
for (const line of lines) {
|
||||
const headingMatch = line.match(/^\s*#{1,6}\s*(.+?)\s*$/)
|
||||
if (headingMatch) {
|
||||
const heading = headingMatch[1].trim().toLowerCase()
|
||||
if (heading === '下载' || heading === 'download') {
|
||||
skipDownloadSection = true
|
||||
continue
|
||||
}
|
||||
if (skipDownloadSection) {
|
||||
skipDownloadSection = false
|
||||
}
|
||||
}
|
||||
if (!skipDownloadSection) {
|
||||
output.push(line)
|
||||
}
|
||||
}
|
||||
|
||||
return output.join('\n')
|
||||
}
|
||||
|
||||
const cleaned = removeDownloadSectionFromMarkdown(removeDownloadSectionFromHtml(merged))
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim()
|
||||
|
||||
return cleaned
|
||||
}
|
||||
|
||||
type AnnualReportYearsLoadStrategy = 'cache' | 'native' | 'hybrid'
|
||||
type AnnualReportYearsLoadPhase = 'cache' | 'native' | 'scan' | 'done'
|
||||
|
||||
@@ -1043,6 +1104,13 @@ function registerIpcHandlers() {
|
||||
return app.getVersion()
|
||||
})
|
||||
|
||||
ipcMain.handle('app:checkWayland', async () => {
|
||||
if (process.platform !== 'linux') return false;
|
||||
|
||||
const sessionType = process.env.XDG_SESSION_TYPE?.toLowerCase();
|
||||
return Boolean(process.env.WAYLAND_DISPLAY || sessionType === 'wayland');
|
||||
})
|
||||
|
||||
ipcMain.handle('log:getPath', async () => {
|
||||
return join(app.getPath('userData'), 'logs', 'wcdb.log')
|
||||
})
|
||||
@@ -1114,7 +1182,7 @@ function registerIpcHandlers() {
|
||||
return {
|
||||
hasUpdate: true,
|
||||
version: latestVersion,
|
||||
releaseNotes: result.updateInfo.releaseNotes as string || ''
|
||||
releaseNotes: normalizeReleaseNotes(result.updateInfo.releaseNotes)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2567,7 +2635,7 @@ function checkForUpdatesOnStartup() {
|
||||
// 通知渲染进程有新版本
|
||||
mainWindow.webContents.send('app:updateAvailable', {
|
||||
version: latestVersion,
|
||||
releaseNotes: result.updateInfo.releaseNotes || ''
|
||||
releaseNotes: normalizeReleaseNotes(result.updateInfo.releaseNotes)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
onUpdateAvailable: (callback: (info: { version: string; releaseNotes: string }) => void) => {
|
||||
ipcRenderer.on('app:updateAvailable', (_, info) => callback(info))
|
||||
return () => ipcRenderer.removeAllListeners('app:updateAvailable')
|
||||
}
|
||||
},
|
||||
checkWayland: () => ipcRenderer.invoke('app:checkWayland'),
|
||||
},
|
||||
|
||||
// 日志
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as https from 'https'
|
||||
import * as http from 'http'
|
||||
import * as fzstd from 'fzstd'
|
||||
import * as crypto from 'crypto'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { app, BrowserWindow, dialog } from 'electron'
|
||||
import { ConfigService } from './config'
|
||||
import { wcdbService } from './wcdbService'
|
||||
import { MessageCacheService } from './messageCacheService'
|
||||
@@ -292,6 +292,7 @@ class ChatService {
|
||||
private readonly allGroupSessionIdsCacheTtlMs = 5 * 60 * 1000
|
||||
private groupMyMessageCountCacheScope = ''
|
||||
private groupMyMessageCountMemoryCache = new Map<string, GroupMyMessageCountCacheEntry>()
|
||||
private initFailureDialogShown = false
|
||||
|
||||
constructor() {
|
||||
this.configService = new ConfigService()
|
||||
@@ -338,6 +339,55 @@ class ChatService {
|
||||
return true
|
||||
}
|
||||
|
||||
private extractErrorCode(message?: string): number | null {
|
||||
const text = String(message || '').trim()
|
||||
if (!text) return null
|
||||
const match = text.match(/(?:错误码\s*[::]\s*|\()(-?\d{2,6})(?:\)|\b)/)
|
||||
if (!match) return null
|
||||
const parsed = Number(match[1])
|
||||
return Number.isFinite(parsed) ? parsed : null
|
||||
}
|
||||
|
||||
private toCodeOnlyMessage(rawMessage?: string, fallbackCode = -3999): string {
|
||||
const code = this.extractErrorCode(rawMessage) ?? fallbackCode
|
||||
return `错误码: ${code}`
|
||||
}
|
||||
|
||||
private async maybeShowInitFailureDialog(errorMessage: string): Promise<void> {
|
||||
if (!app.isPackaged) return
|
||||
if (this.initFailureDialogShown) return
|
||||
|
||||
const code = this.extractErrorCode(errorMessage)
|
||||
if (code === null) return
|
||||
const isSecurityCode =
|
||||
code === -101 ||
|
||||
code === -102 ||
|
||||
code === -2299 ||
|
||||
code === -2301 ||
|
||||
code === -2302 ||
|
||||
code === -1006 ||
|
||||
(code <= -2201 && code >= -2212)
|
||||
if (!isSecurityCode) return
|
||||
|
||||
this.initFailureDialogShown = true
|
||||
const detail = [
|
||||
`错误码: ${code}`
|
||||
].join('\n')
|
||||
|
||||
try {
|
||||
await dialog.showMessageBox({
|
||||
type: 'error',
|
||||
title: 'WeFlow 启动失败',
|
||||
message: '启动失败,请反馈错误码。',
|
||||
detail,
|
||||
buttons: ['确定'],
|
||||
noLink: true
|
||||
})
|
||||
} catch {
|
||||
// 弹窗失败不阻断主流程
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接数据库
|
||||
*/
|
||||
@@ -362,7 +412,9 @@ class ChatService {
|
||||
const cleanedWxid = this.cleanAccountDirName(wxid)
|
||||
const openOk = await wcdbService.open(dbPath, decryptKey, cleanedWxid)
|
||||
if (!openOk) {
|
||||
return { success: false, error: 'WCDB 打开失败,请检查路径和密钥' }
|
||||
const detailedError = this.toCodeOnlyMessage(await wcdbService.getLastInitError())
|
||||
await this.maybeShowInitFailureDialog(detailedError)
|
||||
return { success: false, error: detailedError }
|
||||
}
|
||||
|
||||
this.connected = true
|
||||
@@ -376,7 +428,7 @@ class ChatService {
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
console.error('ChatService: 连接数据库失败:', e)
|
||||
return { success: false, error: String(e) }
|
||||
return { success: false, error: this.toCodeOnlyMessage(String(e), -3998) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5003,7 +5055,17 @@ class ChatService {
|
||||
|
||||
const contact = await this.getContact(username)
|
||||
const avatarResult = await wcdbService.getAvatarUrls([username])
|
||||
const avatarUrl = avatarResult.success && avatarResult.map ? avatarResult.map[username] : undefined
|
||||
let avatarUrl = avatarResult.success && avatarResult.map ? avatarResult.map[username] : undefined
|
||||
if (!this.isValidAvatarUrl(avatarUrl)) {
|
||||
avatarUrl = undefined
|
||||
}
|
||||
if (!avatarUrl) {
|
||||
const headImageAvatars = await this.getAvatarsFromHeadImageDb([username])
|
||||
const fallbackAvatarUrl = headImageAvatars[username]
|
||||
if (this.isValidAvatarUrl(fallbackAvatarUrl)) {
|
||||
avatarUrl = fallbackAvatarUrl
|
||||
}
|
||||
}
|
||||
const displayName = contact?.remark || contact?.nickName || contact?.alias || cached?.displayName || username
|
||||
const cacheEntry: ContactCacheEntry = {
|
||||
avatarUrl,
|
||||
@@ -5471,6 +5533,13 @@ class ChatService {
|
||||
avatarUrl = avatarCandidate
|
||||
}
|
||||
}
|
||||
if (!avatarUrl) {
|
||||
const headImageAvatars = await this.getAvatarsFromHeadImageDb([normalizedSessionId])
|
||||
const fallbackAvatarUrl = headImageAvatars[normalizedSessionId]
|
||||
if (this.isValidAvatarUrl(fallbackAvatarUrl)) {
|
||||
avatarUrl = fallbackAvatarUrl
|
||||
}
|
||||
}
|
||||
|
||||
if (!Number.isFinite(messageCount)) {
|
||||
messageCount = messageCountResult.status === 'fulfilled' &&
|
||||
|
||||
@@ -34,6 +34,7 @@ interface ConfigSchema {
|
||||
autoTranscribeVoice: boolean
|
||||
transcribeLanguages: string[]
|
||||
exportDefaultConcurrency: number
|
||||
exportDefaultImageDeepSearchOnMiss: boolean
|
||||
analyticsExcludedUsernames: string[]
|
||||
|
||||
// 安全相关
|
||||
@@ -52,6 +53,7 @@ interface ConfigSchema {
|
||||
notificationFilterList: string[]
|
||||
messagePushEnabled: boolean
|
||||
windowCloseBehavior: 'ask' | 'tray' | 'quit'
|
||||
quoteLayout: 'quote-top' | 'quote-bottom'
|
||||
wordCloudExcludeWords: string[]
|
||||
}
|
||||
|
||||
@@ -106,6 +108,7 @@ export class ConfigService {
|
||||
autoTranscribeVoice: false,
|
||||
transcribeLanguages: ['zh'],
|
||||
exportDefaultConcurrency: 4,
|
||||
exportDefaultImageDeepSearchOnMiss: true,
|
||||
analyticsExcludedUsernames: [],
|
||||
authEnabled: false,
|
||||
authPassword: '',
|
||||
@@ -118,6 +121,7 @@ export class ConfigService {
|
||||
notificationFilterList: [],
|
||||
messagePushEnabled: false,
|
||||
windowCloseBehavior: 'ask',
|
||||
quoteLayout: 'quote-top',
|
||||
wordCloudExcludeWords: []
|
||||
}
|
||||
|
||||
@@ -688,8 +692,16 @@ export class ConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
private getUserDataPath(): string {
|
||||
const workerUserDataPath = String(process.env.WEFLOW_USER_DATA_PATH || process.env.WEFLOW_CONFIG_CWD || '').trim()
|
||||
if (workerUserDataPath) {
|
||||
return workerUserDataPath
|
||||
}
|
||||
return app?.getPath?.('userData') || process.cwd()
|
||||
}
|
||||
|
||||
getCacheBasePath(): string {
|
||||
return join(app.getPath('userData'), 'cache')
|
||||
return join(this.getUserDataPath(), 'cache')
|
||||
}
|
||||
|
||||
getAll(): Partial<ConfigSchema> {
|
||||
|
||||
@@ -186,6 +186,33 @@ body {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.quoted-message {
|
||||
border-left: 3px solid rgba(79, 70, 229, 0.35);
|
||||
background: rgba(79, 70, 229, 0.06);
|
||||
border-radius: 12px;
|
||||
padding: 8px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.message.sent .quoted-message {
|
||||
background: rgba(37, 99, 235, 0.08);
|
||||
border-left-color: rgba(37, 99, 235, 0.35);
|
||||
}
|
||||
|
||||
.quoted-sender {
|
||||
font-size: 12px;
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.quoted-text {
|
||||
font-size: 13px;
|
||||
color: #4b5563;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.message-link-card {
|
||||
color: #2563eb;
|
||||
text-decoration: underline;
|
||||
|
||||
@@ -186,6 +186,33 @@ body {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.quoted-message {
|
||||
border-left: 3px solid rgba(79, 70, 229, 0.35);
|
||||
background: rgba(79, 70, 229, 0.06);
|
||||
border-radius: 12px;
|
||||
padding: 8px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.message.sent .quoted-message {
|
||||
background: rgba(37, 99, 235, 0.08);
|
||||
border-left-color: rgba(37, 99, 235, 0.35);
|
||||
}
|
||||
|
||||
.quoted-sender {
|
||||
font-size: 12px;
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.quoted-text {
|
||||
font-size: 13px;
|
||||
color: #4b5563;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.message-link-card {
|
||||
color: #2563eb;
|
||||
text-decoration: underline;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1226,7 +1226,7 @@ class HttpService {
|
||||
* 映射 Type 49 子类型
|
||||
*/
|
||||
private mapType49(msg: Message): number {
|
||||
const xmlType = msg.xmlType
|
||||
const xmlType = this.resolveType49Subtype(msg)
|
||||
|
||||
switch (xmlType) {
|
||||
case '5': // 链接
|
||||
@@ -1250,10 +1250,97 @@ class HttpService {
|
||||
}
|
||||
}
|
||||
|
||||
private extractType49Subtype(rawContent: string): string {
|
||||
const content = String(rawContent || '')
|
||||
if (!content) return ''
|
||||
|
||||
const appmsgMatch = /<appmsg[\s\S]*?>([\s\S]*?)<\/appmsg>/i.exec(content)
|
||||
if (appmsgMatch) {
|
||||
const appmsgInner = appmsgMatch[1]
|
||||
.replace(/<refermsg[\s\S]*?<\/refermsg>/gi, '')
|
||||
.replace(/<patMsg[\s\S]*?<\/patMsg>/gi, '')
|
||||
const typeMatch = /<type>([\s\S]*?)<\/type>/i.exec(appmsgInner)
|
||||
if (typeMatch) {
|
||||
return typeMatch[1].replace(/<!\[CDATA\[/g, '').replace(/\]\]>/g, '').trim()
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackMatch = /<type>([\s\S]*?)<\/type>/i.exec(content)
|
||||
if (fallbackMatch) {
|
||||
return fallbackMatch[1].replace(/<!\[CDATA\[/g, '').replace(/\]\]>/g, '').trim()
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
private resolveType49Subtype(msg: Message): string {
|
||||
const xmlType = String(msg.xmlType || '').trim()
|
||||
if (xmlType) return xmlType
|
||||
|
||||
const extractedType = this.extractType49Subtype(msg.rawContent)
|
||||
if (extractedType) return extractedType
|
||||
|
||||
switch (msg.appMsgKind) {
|
||||
case 'official-link':
|
||||
case 'link':
|
||||
return '5'
|
||||
case 'file':
|
||||
return '6'
|
||||
case 'chat-record':
|
||||
return '19'
|
||||
case 'miniapp':
|
||||
return '33'
|
||||
case 'quote':
|
||||
return '57'
|
||||
case 'transfer':
|
||||
return '2000'
|
||||
case 'red-packet':
|
||||
return '2001'
|
||||
case 'music':
|
||||
return '3'
|
||||
default:
|
||||
if (msg.linkUrl) return '5'
|
||||
if (msg.fileName) return '6'
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
private getType49Content(msg: Message): string {
|
||||
const subtype = this.resolveType49Subtype(msg)
|
||||
const title = msg.linkTitle || msg.fileName || ''
|
||||
|
||||
switch (subtype) {
|
||||
case '5':
|
||||
case '49':
|
||||
return title ? `[链接] ${title}` : '[链接]'
|
||||
case '6':
|
||||
return title ? `[文件] ${title}` : '[文件]'
|
||||
case '19':
|
||||
return title ? `[聊天记录] ${title}` : '[聊天记录]'
|
||||
case '33':
|
||||
case '36':
|
||||
return title ? `[小程序] ${title}` : '[小程序]'
|
||||
case '57':
|
||||
return msg.parsedContent || title || '[引用消息]'
|
||||
case '2000':
|
||||
return title ? `[转账] ${title}` : '[转账]'
|
||||
case '2001':
|
||||
return title ? `[红包] ${title}` : '[红包]'
|
||||
case '3':
|
||||
return title ? `[音乐] ${title}` : '[音乐]'
|
||||
default:
|
||||
return msg.parsedContent || title || '[消息]'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息内容
|
||||
*/
|
||||
private getMessageContent(msg: Message): string | null {
|
||||
if (msg.localType === 49) {
|
||||
return this.getType49Content(msg)
|
||||
}
|
||||
|
||||
// 优先使用已解析的内容
|
||||
if (msg.parsedContent) {
|
||||
return msg.parsedContent
|
||||
@@ -1276,7 +1363,7 @@ class HttpService {
|
||||
case 48:
|
||||
return '[位置]'
|
||||
case 49:
|
||||
return msg.linkTitle || msg.fileName || '[消息]'
|
||||
return this.getType49Content(msg)
|
||||
default:
|
||||
return msg.rawContent || null
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ type CachedImagePayload = {
|
||||
|
||||
type DecryptImagePayload = CachedImagePayload & {
|
||||
force?: boolean
|
||||
hardlinkOnly?: boolean
|
||||
}
|
||||
|
||||
export class ImageDecryptService {
|
||||
@@ -158,7 +159,9 @@ export class ImageDecryptService {
|
||||
}
|
||||
|
||||
async decryptImage(payload: DecryptImagePayload): Promise<DecryptResult> {
|
||||
await this.ensureCacheIndexed()
|
||||
if (!payload.hardlinkOnly) {
|
||||
await this.ensureCacheIndexed()
|
||||
}
|
||||
const cacheKeys = this.getCacheKeys(payload)
|
||||
const cacheKey = cacheKeys[0]
|
||||
if (!cacheKey) {
|
||||
@@ -180,14 +183,16 @@ export class ImageDecryptService {
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of cacheKeys) {
|
||||
const existingHd = this.findCachedOutput(key, true, payload.sessionId)
|
||||
if (!existingHd || this.isThumbnailPath(existingHd)) continue
|
||||
this.cacheResolvedPaths(cacheKey, payload.imageMd5, payload.imageDatName, existingHd)
|
||||
this.clearUpdateFlags(cacheKey, payload.imageMd5, payload.imageDatName)
|
||||
const localPath = this.resolveLocalPathForPayload(existingHd, payload.preferFilePath)
|
||||
this.emitCacheResolved(payload, cacheKey, this.resolveEmitPath(existingHd, payload.preferFilePath))
|
||||
return { success: true, localPath }
|
||||
if (!payload.hardlinkOnly) {
|
||||
for (const key of cacheKeys) {
|
||||
const existingHd = this.findCachedOutput(key, true, payload.sessionId)
|
||||
if (!existingHd || this.isThumbnailPath(existingHd)) continue
|
||||
this.cacheResolvedPaths(cacheKey, payload.imageMd5, payload.imageDatName, existingHd)
|
||||
this.clearUpdateFlags(cacheKey, payload.imageMd5, payload.imageDatName)
|
||||
const localPath = this.resolveLocalPathForPayload(existingHd, payload.preferFilePath)
|
||||
this.emitCacheResolved(payload, cacheKey, this.resolveEmitPath(existingHd, payload.preferFilePath))
|
||||
return { success: true, localPath }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +260,7 @@ export class ImageDecryptService {
|
||||
payload: DecryptImagePayload,
|
||||
cacheKey: string
|
||||
): Promise<DecryptResult> {
|
||||
this.logInfo('开始解密图片', { md5: payload.imageMd5, datName: payload.imageDatName, force: payload.force })
|
||||
this.logInfo('开始解密图片', { md5: payload.imageMd5, datName: payload.imageDatName, force: payload.force, hardlinkOnly: payload.hardlinkOnly === true })
|
||||
try {
|
||||
const wxid = this.configService.get('myWxid')
|
||||
const dbPath = this.configService.get('dbPath')
|
||||
@@ -275,7 +280,11 @@ export class ImageDecryptService {
|
||||
payload.imageMd5,
|
||||
payload.imageDatName,
|
||||
payload.sessionId,
|
||||
{ allowThumbnail: !payload.force, skipResolvedCache: Boolean(payload.force) }
|
||||
{
|
||||
allowThumbnail: !payload.force,
|
||||
skipResolvedCache: Boolean(payload.force),
|
||||
hardlinkOnly: payload.hardlinkOnly === true
|
||||
}
|
||||
)
|
||||
|
||||
// 如果要求高清图但没找到,直接返回提示
|
||||
@@ -298,18 +307,20 @@ export class ImageDecryptService {
|
||||
return { success: true, localPath, isThumb }
|
||||
}
|
||||
|
||||
// 查找已缓存的解密文件
|
||||
const existing = this.findCachedOutput(cacheKey, payload.force, payload.sessionId)
|
||||
if (existing) {
|
||||
this.logInfo('找到已解密文件', { existing, isHd: this.isHdPath(existing) })
|
||||
const isHd = this.isHdPath(existing)
|
||||
// 如果要求高清但找到的是缩略图,继续解密高清图
|
||||
if (!(payload.force && !isHd)) {
|
||||
this.cacheResolvedPaths(cacheKey, payload.imageMd5, payload.imageDatName, existing)
|
||||
const localPath = this.resolveLocalPathForPayload(existing, payload.preferFilePath)
|
||||
const isThumb = this.isThumbnailPath(existing)
|
||||
this.emitCacheResolved(payload, cacheKey, this.resolveEmitPath(existing, payload.preferFilePath))
|
||||
return { success: true, localPath, isThumb }
|
||||
// 查找已缓存的解密文件(hardlink-only 模式下跳过全缓存目录扫描)
|
||||
if (!payload.hardlinkOnly) {
|
||||
const existing = this.findCachedOutput(cacheKey, payload.force, payload.sessionId)
|
||||
if (existing) {
|
||||
this.logInfo('找到已解密文件', { existing, isHd: this.isHdPath(existing) })
|
||||
const isHd = this.isHdPath(existing)
|
||||
// 如果要求高清但找到的是缩略图,继续解密高清图
|
||||
if (!(payload.force && !isHd)) {
|
||||
this.cacheResolvedPaths(cacheKey, payload.imageMd5, payload.imageDatName, existing)
|
||||
const localPath = this.resolveLocalPathForPayload(existing, payload.preferFilePath)
|
||||
const isThumb = this.isThumbnailPath(existing)
|
||||
this.emitCacheResolved(payload, cacheKey, this.resolveEmitPath(existing, payload.preferFilePath))
|
||||
return { success: true, localPath, isThumb }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,15 +478,17 @@ export class ImageDecryptService {
|
||||
imageMd5?: string,
|
||||
imageDatName?: string,
|
||||
sessionId?: string,
|
||||
options?: { allowThumbnail?: boolean; skipResolvedCache?: boolean }
|
||||
options?: { allowThumbnail?: boolean; skipResolvedCache?: boolean; hardlinkOnly?: boolean }
|
||||
): Promise<string | null> {
|
||||
const allowThumbnail = options?.allowThumbnail ?? true
|
||||
const skipResolvedCache = options?.skipResolvedCache ?? false
|
||||
const hardlinkOnly = options?.hardlinkOnly ?? false
|
||||
this.logInfo('[ImageDecrypt] resolveDatPath', {
|
||||
imageMd5,
|
||||
imageDatName,
|
||||
allowThumbnail,
|
||||
skipResolvedCache
|
||||
skipResolvedCache,
|
||||
hardlinkOnly
|
||||
})
|
||||
|
||||
if (!skipResolvedCache) {
|
||||
@@ -500,7 +513,7 @@ export class ImageDecryptService {
|
||||
}
|
||||
|
||||
// 1. 通过 MD5 快速定位 (MsgAttach 目录)
|
||||
if (imageMd5) {
|
||||
if (!hardlinkOnly && allowThumbnail && imageMd5) {
|
||||
const res = await this.fastProbabilisticSearch(join(accountDir, 'msg', 'attach'), imageMd5, allowThumbnail)
|
||||
if (res) return res
|
||||
if (imageDatName && imageDatName !== imageMd5 && this.looksLikeMd5(imageDatName)) {
|
||||
@@ -510,7 +523,7 @@ export class ImageDecryptService {
|
||||
}
|
||||
|
||||
// 2. 如果 imageDatName 看起来像 MD5,也尝试快速定位
|
||||
if (!imageMd5 && imageDatName && this.looksLikeMd5(imageDatName)) {
|
||||
if (!hardlinkOnly && allowThumbnail && !imageMd5 && imageDatName && this.looksLikeMd5(imageDatName)) {
|
||||
const res = await this.fastProbabilisticSearch(join(accountDir, 'msg', 'attach'), imageDatName, allowThumbnail)
|
||||
if (res) return res
|
||||
}
|
||||
@@ -587,6 +600,11 @@ export class ImageDecryptService {
|
||||
this.logInfo('[ImageDecrypt] hardlink miss (datName)', { imageDatName })
|
||||
}
|
||||
|
||||
if (hardlinkOnly) {
|
||||
this.logInfo('[ImageDecrypt] resolveDatPath miss (hardlink-only)', { imageMd5, imageDatName })
|
||||
return null
|
||||
}
|
||||
|
||||
// 如果要求高清图但 hardlink 没找到,也不要搜索了(搜索太慢)
|
||||
if (!allowThumbnail) {
|
||||
return null
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { app } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { existsSync, readdirSync, statSync, readFileSync } from 'fs'
|
||||
import { execFile, exec } from 'child_process'
|
||||
import { execFile, exec, spawn } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
@@ -45,33 +45,104 @@ export class KeyServiceLinux {
|
||||
onStatus?: (message: string, level: number) => void
|
||||
): Promise<DbKeyResult> {
|
||||
try {
|
||||
// 1. 构造一个包含常用系统命令路径的环境变量,防止打包后找不到命令
|
||||
const envWithPath = {
|
||||
...process.env,
|
||||
PATH: `${process.env.PATH || ''}:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin`
|
||||
};
|
||||
|
||||
onStatus?.('正在尝试结束当前微信进程...', 0)
|
||||
await execAsync('killall -9 wechat wechat-bin xwechat').catch(() => {})
|
||||
console.log('[Debug] 开始执行进程清理逻辑...');
|
||||
|
||||
try {
|
||||
const { stdout, stderr } = await execAsync('killall -9 wechat wechat-bin xwechat', { env: envWithPath });
|
||||
console.log(`[Debug] killall 成功退出. stdout: ${stdout}, stderr: ${stderr}`);
|
||||
} catch (err: any) {
|
||||
// 命令如果没找到进程通常会返回 code 1,这也是正常的,但我们需要记录下来
|
||||
console.log(`[Debug] killall 报错或未找到进程: ${err.message}`);
|
||||
|
||||
// Fallback: 尝试使用 pkill 兜底
|
||||
try {
|
||||
console.log('[Debug] 尝试使用备用命令 pkill...');
|
||||
await execAsync('pkill -9 -x "wechat|wechat-bin|xwechat"', { env: envWithPath });
|
||||
console.log('[Debug] pkill 执行完成');
|
||||
} catch (e: any) {
|
||||
console.log(`[Debug] pkill 报错或未找到进程: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 稍微等待进程完全退出
|
||||
await new Promise(r => setTimeout(r, 1000))
|
||||
|
||||
onStatus?.('正在尝试拉起微信...', 0)
|
||||
const startCmds = [
|
||||
'nohup wechat >/dev/null 2>&1 &',
|
||||
'nohup wechat-bin >/dev/null 2>&1 &',
|
||||
'nohup xwechat >/dev/null 2>&1 &'
|
||||
|
||||
const cleanEnv = { ...process.env };
|
||||
delete cleanEnv.ELECTRON_RUN_AS_NODE;
|
||||
delete cleanEnv.ELECTRON_NO_ATTACH_CONSOLE;
|
||||
delete cleanEnv.APPDIR;
|
||||
delete cleanEnv.APPIMAGE;
|
||||
|
||||
const wechatBins = [
|
||||
'wechat',
|
||||
'wechat-bin',
|
||||
'xwechat',
|
||||
'/opt/wechat/wechat',
|
||||
'/usr/bin/wechat',
|
||||
'/opt/apps/com.tencent.wechat/files/wechat'
|
||||
]
|
||||
for (const cmd of startCmds) execAsync(cmd).catch(() => {})
|
||||
|
||||
for (const binName of wechatBins) {
|
||||
try {
|
||||
const child = spawn(binName, [], {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
env: cleanEnv
|
||||
});
|
||||
|
||||
child.on('error', (err) => {
|
||||
console.log(`[Debug] 拉起 ${binName} 失败:`, err.message);
|
||||
});
|
||||
|
||||
child.unref();
|
||||
console.log(`[Debug] 尝试拉起 ${binName} 完毕`);
|
||||
} catch (e: any) {
|
||||
console.log(`[Debug] 尝试拉起 ${binName} 发生异常:`, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
onStatus?.('等待微信进程出现...', 0)
|
||||
let pid = 0
|
||||
for (let i = 0; i < 15; i++) { // 最多等 15 秒
|
||||
await new Promise(r => setTimeout(r, 1000))
|
||||
const { stdout } = await execAsync('pidof wechat wechat-bin xwechat').catch(() => ({ stdout: '' }))
|
||||
const pids = stdout.trim().split(/\s+/).filter(p => p)
|
||||
if (pids.length > 0) {
|
||||
pid = parseInt(pids[0], 10)
|
||||
break
|
||||
|
||||
try {
|
||||
const { stdout } = await execAsync('pidof wechat wechat-bin xwechat', { env: envWithPath });
|
||||
const pids = stdout.trim().split(/\s+/).filter(p => p);
|
||||
if (pids.length > 0) {
|
||||
pid = parseInt(pids[0], 10);
|
||||
console.log(`[Debug] 第 ${i + 1} 秒,通过 pidof 成功获取 PID: ${pid}`);
|
||||
break;
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.log(`[Debug] 第 ${i + 1} 秒,pidof 失败: ${err.message.split('\n')[0]}`);
|
||||
|
||||
// Fallback: 使用 pgrep 兜底
|
||||
try {
|
||||
const { stdout: pgrepOut } = await execAsync('pgrep -x "wechat|wechat-bin|xwechat"', { env: envWithPath });
|
||||
const pids = pgrepOut.trim().split(/\s+/).filter(p => p);
|
||||
if (pids.length > 0) {
|
||||
pid = parseInt(pids[0], 10);
|
||||
console.log(`[Debug] 第 ${i + 1} 秒,通过 pgrep 成功获取 PID: ${pid}`);
|
||||
break;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log(`[Debug] 第 ${i + 1} 秒,pgrep 也失败: ${e.message.split('\n')[0]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pid) {
|
||||
const err = '未能自动启动微信,请手动启动并登录。'
|
||||
const err = '未能自动启动微信,或获取PID失败,请查看控制台日志或手动启动并登录。'
|
||||
onStatus?.(err, 2)
|
||||
return { success: false, error: err }
|
||||
}
|
||||
@@ -82,6 +153,7 @@ export class KeyServiceLinux {
|
||||
|
||||
return await this.getDbKey(pid, onStatus)
|
||||
} catch (err: any) {
|
||||
console.error('[Debug] 自动获取流程彻底崩溃:', err);
|
||||
const errMsg = '自动获取微信 PID 失败: ' + err.message
|
||||
onStatus?.(errMsg, 2)
|
||||
return { success: false, error: errMsg }
|
||||
|
||||
@@ -262,6 +262,7 @@ export class KeyServiceMac {
|
||||
): Promise<string> {
|
||||
const helperPath = this.getHelperPath()
|
||||
const waitMs = Math.max(timeoutMs, 30_000)
|
||||
const timeoutSec = Math.ceil(waitMs / 1000) + 30
|
||||
const pid = await this.getWeChatPid()
|
||||
onStatus?.(`已找到微信进程 PID=${pid},正在定位目标函数...`, 0)
|
||||
// 最佳努力清理同路径残留 helper(普通权限)
|
||||
@@ -378,12 +379,22 @@ export class KeyServiceMac {
|
||||
): Promise<string> {
|
||||
const helperPath = this.getHelperPath()
|
||||
const waitMs = Math.max(timeoutMs, 30_000)
|
||||
const timeoutSec = Math.ceil(waitMs / 1000) + 30
|
||||
const pid = await this.getWeChatPid()
|
||||
// 用 AppleScript 的 quoted form 组装命令,避免复杂 shell 拼接导致整条失败
|
||||
// 通过 try/on error 回传详细错误,避免只看到 "Command failed"
|
||||
const scriptLines = [
|
||||
`set helperPath to ${JSON.stringify(helperPath)}`,
|
||||
`set cmd to quoted form of helperPath & " ${pid} ${waitMs} 2>&1"`,
|
||||
'do shell script cmd with administrator privileges'
|
||||
`set cmd to quoted form of helperPath & " ${pid} ${waitMs}"`,
|
||||
`set timeoutSec to ${timeoutSec}`,
|
||||
'try',
|
||||
'with timeout of timeoutSec seconds',
|
||||
'set outText to do shell script cmd with administrator privileges',
|
||||
'end timeout',
|
||||
'return "WF_OK::" & outText',
|
||||
'on error errMsg number errNum partial result pr',
|
||||
'return "WF_ERR::" & errNum & "::" & errMsg & "::" & (pr as text)',
|
||||
'end try'
|
||||
]
|
||||
onStatus?.('已准备就绪,现在登录微信或退出登录后重新登录微信', 0)
|
||||
|
||||
@@ -400,6 +411,16 @@ export class KeyServiceMac {
|
||||
|
||||
const lines = String(stdout).split(/\r?\n/).map(x => x.trim()).filter(Boolean)
|
||||
if (!lines.length) throw new Error('elevated helper returned empty output')
|
||||
const joined = lines.join('\n')
|
||||
|
||||
if (joined.startsWith('WF_ERR::')) {
|
||||
const parts = joined.split('::')
|
||||
const errNum = parts[1] || 'unknown'
|
||||
const errMsg = parts[2] || 'unknown'
|
||||
const partial = parts.slice(3).join('::')
|
||||
throw new Error(`elevated helper failed: errNum=${errNum}, errMsg=${errMsg}, partial=${partial || '(empty)'}`)
|
||||
}
|
||||
const normalizedOutput = joined.startsWith('WF_OK::') ? joined.slice('WF_OK::'.length) : joined
|
||||
|
||||
// 从所有行里提取所有 JSON 对象(同一行可能有多个拼接),找含 key/result 的那个
|
||||
const extractJsonObjects = (s: string): any[] => {
|
||||
@@ -411,7 +432,7 @@ export class KeyServiceMac {
|
||||
}
|
||||
return results
|
||||
}
|
||||
const fullOutput = lines.join('\n')
|
||||
const fullOutput = normalizedOutput
|
||||
const allJson = extractJsonObjects(fullOutput)
|
||||
// 优先找 success=true && key 字段
|
||||
const successPayload = allJson.find(p => p?.success === true && typeof p?.key === 'string')
|
||||
|
||||
@@ -27,6 +27,17 @@ export interface SnsMedia {
|
||||
livePhoto?: SnsLivePhoto
|
||||
}
|
||||
|
||||
export interface SnsLocation {
|
||||
latitude?: number
|
||||
longitude?: number
|
||||
city?: string
|
||||
country?: string
|
||||
poiName?: string
|
||||
poiAddress?: string
|
||||
poiAddressName?: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
export interface SnsPost {
|
||||
id: string
|
||||
tid?: string // 数据库主键(雪花 ID),用于精确删除
|
||||
@@ -39,6 +50,7 @@ export interface SnsPost {
|
||||
media: SnsMedia[]
|
||||
likes: string[]
|
||||
comments: { id: string; nickname: string; content: string; refCommentId: string; refNickname?: string; emojis?: { url: string; md5: string; width: number; height: number; encryptUrl?: string; aesKey?: string }[] }[]
|
||||
location?: SnsLocation
|
||||
rawXml?: string
|
||||
linkTitle?: string
|
||||
linkUrl?: string
|
||||
@@ -287,6 +299,17 @@ function parseCommentsFromXml(xml: string): ParsedCommentItem[] {
|
||||
return comments
|
||||
}
|
||||
|
||||
const decodeXmlText = (text: string): string => {
|
||||
if (!text) return ''
|
||||
return text
|
||||
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
||||
.replace(/&/gi, '&')
|
||||
.replace(/</gi, '<')
|
||||
.replace(/>/gi, '>')
|
||||
.replace(/"/gi, '"')
|
||||
.replace(/'/gi, "'")
|
||||
}
|
||||
|
||||
class SnsService {
|
||||
private configService: ConfigService
|
||||
private contactCache: ContactCacheService
|
||||
@@ -647,6 +670,110 @@ class SnsService {
|
||||
return { media, videoKey }
|
||||
}
|
||||
|
||||
private toOptionalNumber(value: unknown): number | undefined {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return value
|
||||
if (typeof value !== 'string') return undefined
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return undefined
|
||||
const parsed = Number.parseFloat(trimmed)
|
||||
return Number.isFinite(parsed) ? parsed : undefined
|
||||
}
|
||||
|
||||
private normalizeLocation(input: unknown): SnsLocation | undefined {
|
||||
if (!input || typeof input !== 'object') return undefined
|
||||
|
||||
const row = input as Record<string, unknown>
|
||||
const normalizeText = (value: unknown): string | undefined => {
|
||||
if (typeof value !== 'string') return undefined
|
||||
return this.toOptionalString(decodeXmlText(value))
|
||||
}
|
||||
|
||||
const location: SnsLocation = {}
|
||||
const latitude = this.toOptionalNumber(row.latitude ?? row.lat ?? row.x)
|
||||
const longitude = this.toOptionalNumber(row.longitude ?? row.lng ?? row.y)
|
||||
const city = normalizeText(row.city)
|
||||
const country = normalizeText(row.country)
|
||||
const poiName = normalizeText(row.poiName ?? row.poiname)
|
||||
const poiAddress = normalizeText(row.poiAddress ?? row.poiaddress)
|
||||
const poiAddressName = normalizeText(row.poiAddressName ?? row.poiaddressname)
|
||||
const label = normalizeText(row.label)
|
||||
|
||||
if (latitude !== undefined) location.latitude = latitude
|
||||
if (longitude !== undefined) location.longitude = longitude
|
||||
if (city) location.city = city
|
||||
if (country) location.country = country
|
||||
if (poiName) location.poiName = poiName
|
||||
if (poiAddress) location.poiAddress = poiAddress
|
||||
if (poiAddressName) location.poiAddressName = poiAddressName
|
||||
if (label) location.label = label
|
||||
|
||||
return Object.keys(location).length > 0 ? location : undefined
|
||||
}
|
||||
|
||||
private parseLocationFromXml(xml: string): SnsLocation | undefined {
|
||||
if (!xml) return undefined
|
||||
|
||||
try {
|
||||
const locationTagMatch = xml.match(/<location\b([^>]*)>/i)
|
||||
const locationAttrs = locationTagMatch?.[1] || ''
|
||||
const readAttr = (name: string): string | undefined => {
|
||||
if (!locationAttrs) return undefined
|
||||
const match = locationAttrs.match(new RegExp(`${name}\\s*=\\s*["']([\\s\\S]*?)["']`, 'i'))
|
||||
if (!match?.[1]) return undefined
|
||||
return this.toOptionalString(decodeXmlText(match[1]))
|
||||
}
|
||||
const readTag = (name: string): string | undefined => {
|
||||
const match = xml.match(new RegExp(`<${name}>([\\s\\S]*?)<\\/${name}>`, 'i'))
|
||||
if (!match?.[1]) return undefined
|
||||
return this.toOptionalString(decodeXmlText(match[1]))
|
||||
}
|
||||
|
||||
const location: SnsLocation = {}
|
||||
const latitude = this.toOptionalNumber(readAttr('latitude') || readAttr('x') || readTag('latitude') || readTag('x'))
|
||||
const longitude = this.toOptionalNumber(readAttr('longitude') || readAttr('y') || readTag('longitude') || readTag('y'))
|
||||
const city = readAttr('city') || readTag('city')
|
||||
const country = readAttr('country') || readTag('country')
|
||||
const poiName = readAttr('poiName') || readAttr('poiname') || readTag('poiName') || readTag('poiname')
|
||||
const poiAddress = readAttr('poiAddress') || readAttr('poiaddress') || readTag('poiAddress') || readTag('poiaddress')
|
||||
const poiAddressName = readAttr('poiAddressName') || readAttr('poiaddressname') || readTag('poiAddressName') || readTag('poiaddressname')
|
||||
const label = readAttr('label') || readTag('label')
|
||||
|
||||
if (latitude !== undefined) location.latitude = latitude
|
||||
if (longitude !== undefined) location.longitude = longitude
|
||||
if (city) location.city = city
|
||||
if (country) location.country = country
|
||||
if (poiName) location.poiName = poiName
|
||||
if (poiAddress) location.poiAddress = poiAddress
|
||||
if (poiAddressName) location.poiAddressName = poiAddressName
|
||||
if (label) location.label = label
|
||||
|
||||
return Object.keys(location).length > 0 ? location : undefined
|
||||
} catch (e) {
|
||||
console.error('[SnsService] 解析位置 XML 失败:', e)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
private mergeLocation(primary?: SnsLocation, fallback?: SnsLocation): SnsLocation | undefined {
|
||||
if (!primary && !fallback) return undefined
|
||||
|
||||
const merged: SnsLocation = {}
|
||||
const setValue = <K extends keyof SnsLocation>(key: K, value: SnsLocation[K] | undefined) => {
|
||||
if (value !== undefined) merged[key] = value
|
||||
}
|
||||
|
||||
setValue('latitude', primary?.latitude ?? fallback?.latitude)
|
||||
setValue('longitude', primary?.longitude ?? fallback?.longitude)
|
||||
setValue('city', primary?.city ?? fallback?.city)
|
||||
setValue('country', primary?.country ?? fallback?.country)
|
||||
setValue('poiName', primary?.poiName ?? fallback?.poiName)
|
||||
setValue('poiAddress', primary?.poiAddress ?? fallback?.poiAddress)
|
||||
setValue('poiAddressName', primary?.poiAddressName ?? fallback?.poiAddressName)
|
||||
setValue('label', primary?.label ?? fallback?.label)
|
||||
|
||||
return Object.keys(merged).length > 0 ? merged : undefined
|
||||
}
|
||||
|
||||
private getSnsCacheDir(): string {
|
||||
const cachePath = this.configService.getCacheBasePath()
|
||||
const snsCacheDir = join(cachePath, 'sns_cache')
|
||||
@@ -948,7 +1075,12 @@ class SnsService {
|
||||
const enrichedTimeline = result.timeline.map((post: any) => {
|
||||
const contact = this.contactCache.get(post.username)
|
||||
const isVideoPost = post.type === 15
|
||||
const videoKey = extractVideoKey(post.rawXml || '')
|
||||
const rawXml = post.rawXml || ''
|
||||
const videoKey = extractVideoKey(rawXml)
|
||||
const location = this.mergeLocation(
|
||||
this.normalizeLocation((post as { location?: unknown }).location),
|
||||
this.parseLocationFromXml(rawXml)
|
||||
)
|
||||
|
||||
const fixedMedia = (post.media || []).map((m: any) => ({
|
||||
url: fixSnsUrl(m.url, m.token, isVideoPost),
|
||||
@@ -971,7 +1103,6 @@ class SnsService {
|
||||
// 如果 DLL 评论缺少表情包信息,回退到从 rawXml 重新解析
|
||||
const dllComments: any[] = post.comments || []
|
||||
const hasEmojisInDll = dllComments.some((c: any) => c.emojis && c.emojis.length > 0)
|
||||
const rawXml = post.rawXml || ''
|
||||
|
||||
let finalComments: any[]
|
||||
if (dllComments.length > 0 && (hasEmojisInDll || !rawXml)) {
|
||||
@@ -990,7 +1121,8 @@ class SnsService {
|
||||
avatarUrl: contact?.avatarUrl,
|
||||
nickname: post.nickname || contact?.displayName || post.username,
|
||||
media: fixedMedia,
|
||||
comments: finalComments
|
||||
comments: finalComments,
|
||||
location
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1346,6 +1478,7 @@ class SnsService {
|
||||
})),
|
||||
likes: p.likes,
|
||||
comments: p.comments,
|
||||
location: p.location,
|
||||
linkTitle: (p as any).linkTitle,
|
||||
linkUrl: (p as any).linkUrl
|
||||
}))
|
||||
@@ -1397,6 +1530,7 @@ class SnsService {
|
||||
})),
|
||||
likes: post.likes,
|
||||
comments: post.comments,
|
||||
location: post.location,
|
||||
likesDetail,
|
||||
commentsDetail,
|
||||
linkTitle: (post as any).linkTitle,
|
||||
@@ -1479,6 +1613,27 @@ class SnsService {
|
||||
const ch = name.charAt(0)
|
||||
return escapeHtml(ch || '?')
|
||||
}
|
||||
const normalizeLocationText = (value?: string): string => (
|
||||
decodeXmlText(String(value || '')).replace(/\s+/g, ' ').trim()
|
||||
)
|
||||
const resolveLocationText = (location?: SnsLocation): string => {
|
||||
if (!location) return ''
|
||||
const primaryCandidates = [
|
||||
normalizeLocationText(location.poiName),
|
||||
normalizeLocationText(location.poiAddressName),
|
||||
normalizeLocationText(location.label),
|
||||
normalizeLocationText(location.poiAddress)
|
||||
].filter(Boolean)
|
||||
const primary = primaryCandidates[0] || ''
|
||||
const region = [
|
||||
normalizeLocationText(location.country),
|
||||
normalizeLocationText(location.city)
|
||||
].filter(Boolean).join(' ')
|
||||
if (primary && region && !primary.includes(region)) {
|
||||
return `${primary} · ${region}`
|
||||
}
|
||||
return primary || region
|
||||
}
|
||||
|
||||
let filterInfo = ''
|
||||
if (filters.keyword) filterInfo += `关键词: "${escapeHtml(filters.keyword)}" `
|
||||
@@ -1502,6 +1657,10 @@ class SnsService {
|
||||
const linkHtml = post.linkTitle && post.linkUrl
|
||||
? `<a class="lk" href="${escapeHtml(post.linkUrl)}" target="_blank"><span class="lk-t">${escapeHtml(post.linkTitle)}</span><span class="lk-a">›</span></a>`
|
||||
: ''
|
||||
const locationText = resolveLocationText(post.location)
|
||||
const locationHtml = locationText
|
||||
? `<div class="loc"><span class="loc-i">📍</span><span class="loc-t">${escapeHtml(locationText)}</span></div>`
|
||||
: ''
|
||||
|
||||
const likesHtml = post.likes.length > 0
|
||||
? `<div class="interactions"><div class="likes">♥ ${post.likes.map(l => `<span>${escapeHtml(l)}</span>`).join('、')}</div></div>`
|
||||
@@ -1524,6 +1683,7 @@ ${avatarHtml}
|
||||
<div class="body">
|
||||
<div class="hd"><span class="nick">${escapeHtml(post.nickname)}</span><span class="tm">${formatTime(post.createTime)}</span></div>
|
||||
${post.contentDesc ? `<div class="txt">${escapeHtml(post.contentDesc)}</div>` : ''}
|
||||
${locationHtml}
|
||||
${mediaHtml ? `<div class="mg ${gridClass}">${mediaHtml}</div>` : ''}
|
||||
${linkHtml}
|
||||
${likesHtml}
|
||||
@@ -1559,6 +1719,9 @@ body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hira
|
||||
.nick{font-size:15px;font-weight:700;color:var(--accent);margin-bottom:2px}
|
||||
.tm{font-size:12px;color:var(--t3)}
|
||||
.txt{font-size:15px;line-height:1.6;white-space:pre-wrap;word-break:break-word;margin-bottom:12px}
|
||||
.loc{display:flex;align-items:flex-start;gap:6px;font-size:13px;color:var(--t2);margin:-4px 0 12px}
|
||||
.loc-i{line-height:1.3}
|
||||
.loc-t{line-height:1.45;word-break:break-word}
|
||||
|
||||
/* 媒体网格 */
|
||||
.mg{display:grid;gap:6px;margin-bottom:12px;max-width:320px}
|
||||
|
||||
@@ -273,8 +273,20 @@ export class VoiceTranscribeService {
|
||||
})
|
||||
|
||||
worker.on('error', (err: Error) => resolve({ success: false, error: String(err) }))
|
||||
worker.on('exit', (code: number) => {
|
||||
if (code !== 0) resolve({ success: false, error: `Worker exited with code ${code}` })
|
||||
worker.on('exit', (code: number | null, signal: string | null) => {
|
||||
if (code === null || signal === 'SIGSEGV') {
|
||||
|
||||
console.error(`[VoiceTranscribe] Worker 异常崩溃,信号: ${signal}。可能是由于底层 C++ 运行库在当前系统上发生段错误。`);
|
||||
resolve({
|
||||
success: false,
|
||||
error: 'SEGFAULT_ERROR'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (code !== 0) {
|
||||
resolve({ success: false, error: `Worker exited with code ${code}` });
|
||||
}
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
|
||||
@@ -68,6 +68,8 @@ export class WcdbCore {
|
||||
private wcdbListMediaDbs: any = null
|
||||
private wcdbGetMessageById: any = null
|
||||
private wcdbGetEmoticonCdnUrl: any = null
|
||||
private wcdbGetEmoticonCaption: any = null
|
||||
private wcdbGetEmoticonCaptionStrict: any = null
|
||||
private wcdbGetDbStatus: any = null
|
||||
private wcdbGetVoiceData: any = null
|
||||
private wcdbGetVoiceDataBatch: any = null
|
||||
@@ -124,6 +126,10 @@ export class WcdbCore {
|
||||
this.writeLog(`[bootstrap] setPaths resourcesPath=${resourcesPath} userDataPath=${userDataPath}`, true)
|
||||
}
|
||||
|
||||
getLastInitError(): string | null {
|
||||
return lastDllInitError
|
||||
}
|
||||
|
||||
setLogEnabled(enabled: boolean): void {
|
||||
this.logEnabled = enabled
|
||||
this.writeLog(`[bootstrap] setLogEnabled=${enabled ? '1' : '0'} env.WCDB_LOG_ENABLED=${process.env.WCDB_LOG_ENABLED || ''}`, true)
|
||||
@@ -264,8 +270,9 @@ export class WcdbCore {
|
||||
private getDllPath(): string {
|
||||
const isMac = process.platform === 'darwin'
|
||||
const isLinux = process.platform === 'linux'
|
||||
const isArm64 = process.arch === 'arm64'
|
||||
const libName = isMac ? 'libwcdb_api.dylib' : isLinux ? 'libwcdb_api.so' : 'wcdb_api.dll'
|
||||
const subDir = isMac ? 'macos' : isLinux ? 'linux' : ''
|
||||
const subDir = isMac ? 'macos' : isLinux ? 'linux' : (isArm64 ? 'arm64' : '')
|
||||
|
||||
const envDllPath = process.env.WCDB_DLL_PATH
|
||||
if (envDllPath && envDllPath.length > 0) {
|
||||
@@ -296,6 +303,10 @@ export class WcdbCore {
|
||||
return candidates[0] || libName
|
||||
}
|
||||
|
||||
private formatInitProtectionError(code: number): string {
|
||||
return `错误码: ${code}`
|
||||
}
|
||||
|
||||
private isLogEnabled(): boolean {
|
||||
// 移除 Worker 线程的日志禁用逻辑,允许在 Worker 中记录日志
|
||||
if (process.env.WCDB_LOG_ENABLED === '1') return true
|
||||
@@ -617,11 +628,13 @@ export class WcdbCore {
|
||||
}
|
||||
}
|
||||
|
||||
this.writeLog(`[bootstrap] koffi.load begin path=${dllPath}`, true)
|
||||
this.lib = this.koffi.load(dllPath)
|
||||
this.writeLog('[bootstrap] koffi.load ok', true)
|
||||
|
||||
// InitProtection (Added for security)
|
||||
try {
|
||||
this.wcdbInitProtection = this.lib.func('bool InitProtection(const char* resourcePath)')
|
||||
this.wcdbInitProtection = this.lib.func('int32 InitProtection(const char* resourcePath)')
|
||||
|
||||
// 尝试多个可能的资源路径
|
||||
const resourcePaths = [
|
||||
@@ -634,26 +647,40 @@ export class WcdbCore {
|
||||
].filter(Boolean)
|
||||
|
||||
let protectionOk = false
|
||||
let protectionCode = -1
|
||||
let bestFailCode: number | null = null
|
||||
const scoreFailCode = (code: number): number => {
|
||||
if (code >= -2212 && code <= -2201) return 0 // manifest/signature/hash failures
|
||||
if (code === -102 || code === -101 || code === -1006) return 1
|
||||
return 2
|
||||
}
|
||||
for (const resPath of resourcePaths) {
|
||||
try {
|
||||
//
|
||||
protectionOk = this.wcdbInitProtection(resPath)
|
||||
if (protectionOk) {
|
||||
//
|
||||
this.writeLog(`[bootstrap] InitProtection call path=${resPath}`, true)
|
||||
protectionCode = Number(this.wcdbInitProtection(resPath))
|
||||
if (protectionCode === 0) {
|
||||
protectionOk = true
|
||||
break
|
||||
}
|
||||
if (bestFailCode === null || scoreFailCode(protectionCode) < scoreFailCode(bestFailCode)) {
|
||||
bestFailCode = protectionCode
|
||||
}
|
||||
this.writeLog(`[bootstrap] InitProtection rc=${protectionCode} path=${resPath}`, true)
|
||||
} catch (e) {
|
||||
// console.warn(`[WCDB] InitProtection 失败 (${resPath}):`, e)
|
||||
this.writeLog(`[bootstrap] InitProtection exception path=${resPath}: ${String(e)}`, true)
|
||||
}
|
||||
}
|
||||
|
||||
if (!protectionOk) {
|
||||
// console.warn('[WCDB] Core security check failed - 继续运行但可能不稳定')
|
||||
// this.writeLog('InitProtection 失败,继续运行')
|
||||
// 不返回 false,允许继续运行
|
||||
const finalCode = bestFailCode ?? protectionCode
|
||||
lastDllInitError = this.formatInitProtectionError(finalCode)
|
||||
this.writeLog(`[bootstrap] InitProtection failed finalCode=${finalCode}`, true)
|
||||
return false
|
||||
}
|
||||
} catch (e) {
|
||||
// console.warn('InitProtection symbol not found:', e)
|
||||
lastDllInitError = this.formatInitProtectionError(-2301)
|
||||
this.writeLog(`[bootstrap] InitProtection symbol load failed: ${String(e)}`, true)
|
||||
return false
|
||||
}
|
||||
|
||||
// 定义类型
|
||||
@@ -852,6 +879,22 @@ export class WcdbCore {
|
||||
// wcdb_status wcdb_get_emoticon_cdn_url(wcdb_handle handle, const char* db_path, const char* md5, char** out_url)
|
||||
this.wcdbGetEmoticonCdnUrl = this.lib.func('int32 wcdb_get_emoticon_cdn_url(int64 handle, const char* dbPath, const char* md5, _Out_ void** outUrl)')
|
||||
|
||||
// wcdb_status wcdb_get_emoticon_caption(wcdb_handle handle, const char* db_path, const char* md5, char** out_caption)
|
||||
try {
|
||||
this.wcdbGetEmoticonCaption = this.lib.func('int32 wcdb_get_emoticon_caption(int64 handle, const char* dbPath, const char* md5, _Out_ void** outCaption)')
|
||||
} catch (e) {
|
||||
this.wcdbGetEmoticonCaption = null
|
||||
this.writeLog(`[diag:emoji] symbol missing wcdb_get_emoticon_caption: ${String(e)}`, true)
|
||||
}
|
||||
|
||||
// wcdb_status wcdb_get_emoticon_caption_strict(wcdb_handle handle, const char* md5, char** out_caption)
|
||||
try {
|
||||
this.wcdbGetEmoticonCaptionStrict = this.lib.func('int32 wcdb_get_emoticon_caption_strict(int64 handle, const char* md5, _Out_ void** outCaption)')
|
||||
} catch (e) {
|
||||
this.wcdbGetEmoticonCaptionStrict = null
|
||||
this.writeLog(`[diag:emoji] symbol missing wcdb_get_emoticon_caption_strict: ${String(e)}`, true)
|
||||
}
|
||||
|
||||
// wcdb_status wcdb_list_message_dbs(wcdb_handle handle, char** out_json)
|
||||
this.wcdbListMessageDbs = this.lib.func('int32 wcdb_list_message_dbs(int64 handle, _Out_ void** outJson)')
|
||||
|
||||
@@ -1055,7 +1098,7 @@ export class WcdbCore {
|
||||
const initResult = this.wcdbInit()
|
||||
if (initResult !== 0) {
|
||||
console.error('WCDB 初始化失败:', initResult)
|
||||
lastDllInitError = `初始化失败(错误码: ${initResult})`
|
||||
lastDllInitError = this.formatInitProtectionError(initResult)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1066,14 +1109,7 @@ export class WcdbCore {
|
||||
const errorMsg = e instanceof Error ? e.message : String(e)
|
||||
console.error('WCDB 初始化异常:', errorMsg)
|
||||
this.writeLog(`WCDB 初始化异常: ${errorMsg}`, true)
|
||||
lastDllInitError = errorMsg
|
||||
// 检查是否是常见的 VC++ 运行时缺失错误
|
||||
if (errorMsg.includes('126') || errorMsg.includes('找不到指定的模块') ||
|
||||
errorMsg.includes('The specified module could not be found')) {
|
||||
lastDllInitError = '可能缺少 Visual C++ 运行时库。请安装 Microsoft Visual C++ Redistributable (x64)。'
|
||||
} else if (errorMsg.includes('193') || errorMsg.includes('不是有效的 Win32 应用程序')) {
|
||||
lastDllInitError = 'DLL 架构不匹配。请确保使用 64 位版本的应用程序。'
|
||||
}
|
||||
lastDllInitError = this.formatInitProtectionError(-2302)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -1100,8 +1136,7 @@ export class WcdbCore {
|
||||
if (!this.initialized) {
|
||||
const initOk = await this.initialize()
|
||||
if (!initOk) {
|
||||
// 返回更详细的错误信息,帮助用户诊断问题
|
||||
const detailedError = lastDllInitError || 'WCDB 初始化失败'
|
||||
const detailedError = lastDllInitError || this.formatInitProtectionError(-2303)
|
||||
return { success: false, error: detailedError }
|
||||
}
|
||||
}
|
||||
@@ -1111,7 +1146,7 @@ export class WcdbCore {
|
||||
this.writeLog(`testConnection dbPath=${dbPath} wxid=${wxid} dbStorage=${dbStoragePath || 'null'}`)
|
||||
|
||||
if (!dbStoragePath || !existsSync(dbStoragePath)) {
|
||||
return { success: false, error: `数据库目录不存在: ${dbPath}` }
|
||||
return { success: false, error: this.formatInitProtectionError(-3001) }
|
||||
}
|
||||
|
||||
// 递归查找 session.db
|
||||
@@ -1119,7 +1154,7 @@ export class WcdbCore {
|
||||
this.writeLog(`testConnection sessionDb=${sessionDbPath || 'null'}`)
|
||||
|
||||
if (!sessionDbPath) {
|
||||
return { success: false, error: `未找到 session.db 文件` }
|
||||
return { success: false, error: this.formatInitProtectionError(-3002) }
|
||||
}
|
||||
|
||||
// 分配输出参数内存
|
||||
@@ -1128,17 +1163,13 @@ export class WcdbCore {
|
||||
|
||||
if (result !== 0) {
|
||||
await this.printLogs()
|
||||
let errorMsg = '数据库打开失败'
|
||||
if (result === -1) errorMsg = '参数错误'
|
||||
else if (result === -2) errorMsg = '密钥错误'
|
||||
else if (result === -3) errorMsg = '数据库打开失败'
|
||||
this.writeLog(`testConnection openAccount failed code=${result}`)
|
||||
return { success: false, error: `${errorMsg} (错误码: ${result})` }
|
||||
return { success: false, error: this.formatInitProtectionError(result) }
|
||||
}
|
||||
|
||||
const tempHandle = handleOut[0]
|
||||
if (tempHandle <= 0) {
|
||||
return { success: false, error: '无效的数据库句柄' }
|
||||
return { success: false, error: this.formatInitProtectionError(-3003) }
|
||||
}
|
||||
|
||||
// 测试成功:使用 shutdown 清理资源(包括测试句柄)
|
||||
@@ -1167,7 +1198,7 @@ export class WcdbCore {
|
||||
} catch (e) {
|
||||
console.error('测试连接异常:', e)
|
||||
this.writeLog(`testConnection exception: ${String(e)}`)
|
||||
return { success: false, error: String(e) }
|
||||
return { success: false, error: this.formatInitProtectionError(-3004) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1359,6 +1390,7 @@ export class WcdbCore {
|
||||
*/
|
||||
async open(dbPath: string, hexKey: string, wxid: string): Promise<boolean> {
|
||||
try {
|
||||
lastDllInitError = null
|
||||
if (!this.initialized) {
|
||||
const initOk = await this.initialize()
|
||||
if (!initOk) return false
|
||||
@@ -1386,6 +1418,7 @@ export class WcdbCore {
|
||||
if (!dbStoragePath || !existsSync(dbStoragePath)) {
|
||||
console.error('数据库目录不存在:', dbPath)
|
||||
this.writeLog(`open failed: dbStorage not found for ${dbPath}`)
|
||||
lastDllInitError = this.formatInitProtectionError(-3001)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1394,6 +1427,7 @@ export class WcdbCore {
|
||||
if (!sessionDbPath) {
|
||||
console.error('未找到 session.db 文件')
|
||||
this.writeLog('open failed: session.db not found')
|
||||
lastDllInitError = this.formatInitProtectionError(-3002)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1404,11 +1438,13 @@ export class WcdbCore {
|
||||
console.error('打开数据库失败:', result)
|
||||
await this.printLogs()
|
||||
this.writeLog(`open failed: openAccount code=${result}`)
|
||||
lastDllInitError = this.formatInitProtectionError(result)
|
||||
return false
|
||||
}
|
||||
|
||||
const handle = handleOut[0]
|
||||
if (handle <= 0) {
|
||||
lastDllInitError = this.formatInitProtectionError(-3003)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1418,6 +1454,7 @@ export class WcdbCore {
|
||||
this.currentWxid = wxid
|
||||
this.currentDbStoragePath = dbStoragePath
|
||||
this.initialized = true
|
||||
lastDllInitError = null
|
||||
if (this.wcdbSetMyWxid && wxid) {
|
||||
try {
|
||||
this.wcdbSetMyWxid(this.handle, wxid)
|
||||
@@ -1435,6 +1472,7 @@ export class WcdbCore {
|
||||
} catch (e) {
|
||||
console.error('打开数据库异常:', e)
|
||||
this.writeLog(`open exception: ${String(e)}`)
|
||||
lastDllInitError = this.formatInitProtectionError(-3004)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -2700,6 +2738,48 @@ export class WcdbCore {
|
||||
}
|
||||
}
|
||||
|
||||
async getEmoticonCaption(dbPath: string, md5: string): Promise<{ success: boolean; caption?: string; error?: string }> {
|
||||
if (!this.ensureReady()) {
|
||||
return { success: false, error: 'WCDB 未连接' }
|
||||
}
|
||||
if (!this.wcdbGetEmoticonCaption) {
|
||||
return { success: false, error: '接口未就绪: wcdb_get_emoticon_caption' }
|
||||
}
|
||||
try {
|
||||
const outPtr = [null as any]
|
||||
const result = this.wcdbGetEmoticonCaption(this.handle, dbPath || '', md5, outPtr)
|
||||
if (result !== 0 || !outPtr[0]) {
|
||||
return { success: false, error: `获取表情释义失败: ${result}` }
|
||||
}
|
||||
const captionStr = this.decodeJsonPtr(outPtr[0])
|
||||
if (captionStr === null) return { success: false, error: '解析表情释义失败' }
|
||||
return { success: true, caption: captionStr || undefined }
|
||||
} catch (e) {
|
||||
return { success: false, error: String(e) }
|
||||
}
|
||||
}
|
||||
|
||||
async getEmoticonCaptionStrict(md5: string): Promise<{ success: boolean; caption?: string; error?: string }> {
|
||||
if (!this.ensureReady()) {
|
||||
return { success: false, error: 'WCDB 未连接' }
|
||||
}
|
||||
if (!this.wcdbGetEmoticonCaptionStrict) {
|
||||
return { success: false, error: '接口未就绪: wcdb_get_emoticon_caption_strict' }
|
||||
}
|
||||
try {
|
||||
const outPtr = [null as any]
|
||||
const result = this.wcdbGetEmoticonCaptionStrict(this.handle, md5, outPtr)
|
||||
if (result !== 0 || !outPtr[0]) {
|
||||
return { success: false, error: `获取表情释义失败(strict): ${result}` }
|
||||
}
|
||||
const captionStr = this.decodeJsonPtr(outPtr[0])
|
||||
if (captionStr === null) return { success: false, error: '解析表情释义失败(strict)' }
|
||||
return { success: true, caption: captionStr || undefined }
|
||||
} catch (e) {
|
||||
return { success: false, error: String(e) }
|
||||
}
|
||||
}
|
||||
|
||||
async listMessageDbs(): Promise<{ success: boolean; data?: string[]; error?: string }> {
|
||||
if (!this.ensureReady()) return { success: false, error: 'WCDB 未连接' }
|
||||
try {
|
||||
|
||||
@@ -164,6 +164,10 @@ export class WcdbService {
|
||||
return this.callWorker('open', { dbPath, hexKey, wxid })
|
||||
}
|
||||
|
||||
async getLastInitError(): Promise<string | null> {
|
||||
return this.callWorker('getLastInitError')
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据库连接
|
||||
*/
|
||||
@@ -455,6 +459,20 @@ export class WcdbService {
|
||||
return this.callWorker('getEmoticonCdnUrl', { dbPath, md5 })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表情包释义
|
||||
*/
|
||||
async getEmoticonCaption(dbPath: string, md5: string): Promise<{ success: boolean; caption?: string; error?: string }> {
|
||||
return this.callWorker('getEmoticonCaption', { dbPath, md5 })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表情包释义(严格 DLL 接口)
|
||||
*/
|
||||
async getEmoticonCaptionStrict(md5: string): Promise<{ success: boolean; caption?: string; error?: string }> {
|
||||
return this.callWorker('getEmoticonCaptionStrict', { md5 })
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出消息数据库
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,9 @@ if (parentPort) {
|
||||
case 'open':
|
||||
result = await core.open(payload.dbPath, payload.hexKey, payload.wxid)
|
||||
break
|
||||
case 'getLastInitError':
|
||||
result = core.getLastInitError()
|
||||
break
|
||||
case 'close':
|
||||
core.close()
|
||||
result = { success: true }
|
||||
@@ -170,6 +173,12 @@ if (parentPort) {
|
||||
case 'getEmoticonCdnUrl':
|
||||
result = await core.getEmoticonCdnUrl(payload.dbPath, payload.md5)
|
||||
break
|
||||
case 'getEmoticonCaption':
|
||||
result = await core.getEmoticonCaption(payload.dbPath, payload.md5)
|
||||
break
|
||||
case 'getEmoticonCaptionStrict':
|
||||
result = await core.getEmoticonCaptionStrict(payload.md5)
|
||||
break
|
||||
case 'listMessageDbs':
|
||||
result = await core.listMessageDbs()
|
||||
break
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
"build": "tsc && vite build && electron-builder",
|
||||
"preview": "vite preview",
|
||||
"electron:dev": "vite --mode electron",
|
||||
"electron:build": "npm run build"
|
||||
"electron:build": "npm run build",
|
||||
"preinstall": "node preinstall.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"echarts": "^5.5.1",
|
||||
@@ -95,6 +96,7 @@
|
||||
"linux": {
|
||||
"icon": "public/icon.png",
|
||||
"target": [
|
||||
"appimage",
|
||||
"deb",
|
||||
"tar.gz"
|
||||
],
|
||||
@@ -172,4 +174,4 @@
|
||||
],
|
||||
"icon": "resources/icon.icns"
|
||||
}
|
||||
}
|
||||
}
|
||||
20
preinstall.js
Normal file
20
preinstall.js
Normal file
File diff suppressed because one or more lines are too long
BIN
public/icon.ico
BIN
public/icon.ico
Binary file not shown.
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 364 KiB |
BIN
public/icon.png
BIN
public/icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 570 KiB |
BIN
public/logo.png
BIN
public/logo.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 570 KiB |
BIN
resources/arm64/WCDB.dll
Normal file
BIN
resources/arm64/WCDB.dll
Normal file
Binary file not shown.
BIN
resources/arm64/wcdb_api.dll
Normal file
BIN
resources/arm64/wcdb_api.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67
src/App.tsx
67
src/App.tsx
@@ -104,6 +104,44 @@ function App() {
|
||||
// 数据收集同意状态
|
||||
const [showAnalyticsConsent, setShowAnalyticsConsent] = useState(false)
|
||||
|
||||
const [showWaylandWarning, setShowWaylandWarning] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const checkWaylandStatus = async () => {
|
||||
try {
|
||||
// 防止在非客户端环境报错,先检查 API 是否存在
|
||||
if (!window.electronAPI?.app?.checkWayland) return
|
||||
|
||||
// 通过 configService 检查是否已经弹过窗
|
||||
const hasWarned = await window.electronAPI.config.get('waylandWarningShown')
|
||||
|
||||
if (!hasWarned) {
|
||||
const isWayland = await window.electronAPI.app.checkWayland()
|
||||
if (isWayland) {
|
||||
setShowWaylandWarning(true)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('检查 Wayland 状态失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 只有在协议同意之后并且已经进入主应用流程才检查
|
||||
if (!isAgreementWindow && !isOnboardingWindow && !agreementLoading) {
|
||||
checkWaylandStatus()
|
||||
}
|
||||
}, [isAgreementWindow, isOnboardingWindow, agreementLoading])
|
||||
|
||||
const handleDismissWaylandWarning = async () => {
|
||||
try {
|
||||
// 记录到本地配置中,下次不再提示
|
||||
await window.electronAPI.config.set('waylandWarningShown', true)
|
||||
} catch (e) {
|
||||
console.error('保存 Wayland 提示状态失败:', e)
|
||||
}
|
||||
setShowWaylandWarning(false)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (location.pathname !== '/settings') {
|
||||
settingsBackgroundRef.current = location
|
||||
@@ -432,6 +470,8 @@ function App() {
|
||||
checkLock()
|
||||
}, [isAgreementWindow, isOnboardingWindow, isVideoPlayerWindow])
|
||||
|
||||
|
||||
|
||||
// 独立协议窗口
|
||||
if (isAgreementWindow) {
|
||||
return <AgreementPage />
|
||||
@@ -614,6 +654,33 @@ function App() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showWaylandWarning && (
|
||||
<div className="agreement-overlay">
|
||||
<div className="agreement-modal">
|
||||
<div className="agreement-header">
|
||||
<Shield size={32} />
|
||||
<h2>环境兼容性提示 (Wayland)</h2>
|
||||
</div>
|
||||
<div className="agreement-content">
|
||||
<div className="agreement-text">
|
||||
<p>检测到您当前正在使用 <strong>Wayland</strong> 显示服务器。</p>
|
||||
<p>在 Wayland 环境下,出于系统级的安全与设计机制,<strong>应用程序无法直接控制新弹出窗口的位置</strong>。</p>
|
||||
<p>这可能导致某些独立窗口(如消息通知、图片查看器等)出现位置随机、或不受控制的情况。这是底层机制导致的,对此我们无能为力。</p>
|
||||
<br />
|
||||
<p>如果您觉得窗口位置异常严重影响了使用体验,建议尝试:</p>
|
||||
<p>1. 在系统登录界面,将会话切换回 <strong>X11 (Xorg)</strong> 模式。</p>
|
||||
<p>2. 修改您的桌面管理器 (WM/DE) 配置,强制指定该应用程序的窗口规则。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="agreement-footer">
|
||||
<div className="agreement-actions">
|
||||
<button className="btn btn-primary" onClick={handleDismissWaylandWarning}>我知道了,不再提示</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 更新提示对话框 */}
|
||||
<UpdateDialog
|
||||
open={showUpdateDialog}
|
||||
|
||||
@@ -13,13 +13,14 @@
|
||||
width: min(480px, calc(100vw - 32px));
|
||||
max-height: calc(100vh - 64px);
|
||||
overflow-y: auto;
|
||||
border-radius: 12px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-secondary-solid, var(--bg-primary));
|
||||
padding: 12px;
|
||||
padding: 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
box-shadow: 0 22px 48px rgba(0, 0, 0, 0.16);
|
||||
}
|
||||
|
||||
.export-date-range-dialog-header {
|
||||
@@ -83,8 +84,8 @@
|
||||
}
|
||||
|
||||
.export-date-range-mode-banner {
|
||||
border-radius: 8px;
|
||||
padding: 6px 8px;
|
||||
border-radius: 10px;
|
||||
padding: 7px 10px;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
border: 1px solid var(--border-color);
|
||||
@@ -98,47 +99,92 @@
|
||||
}
|
||||
}
|
||||
|
||||
.export-date-range-calendar-grid {
|
||||
.export-date-range-boundary-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.export-date-range-boundary-card {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
background: var(--bg-secondary);
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&.active {
|
||||
border-color: var(--primary);
|
||||
background: rgba(var(--primary-rgb), 0.08);
|
||||
box-shadow: 0 0 0 1px rgba(var(--primary-rgb), 0.18);
|
||||
}
|
||||
|
||||
.boundary-label {
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.export-date-range-selection-hint {
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.export-date-range-calendar-panel {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-secondary);
|
||||
padding: 7px;
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(180deg, rgba(var(--primary-rgb), 0.04), transparent 28%), var(--bg-secondary);
|
||||
padding: 10px;
|
||||
|
||||
&.single {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.export-date-range-calendar-panel-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.export-date-range-calendar-date-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
gap: 3px;
|
||||
|
||||
span {
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
strong {
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.export-date-range-date-input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
border-radius: 6px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
height: 24px;
|
||||
padding: 0 7px;
|
||||
font-size: 11px;
|
||||
height: 30px;
|
||||
padding: 0 9px;
|
||||
font-size: 12px;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 0 0 1px rgba(var(--primary-rgb), 0.18);
|
||||
}
|
||||
|
||||
&.invalid {
|
||||
border-color: #e84d4d;
|
||||
@@ -149,28 +195,36 @@
|
||||
.export-date-range-calendar-nav {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--text-primary);
|
||||
|
||||
button {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 5px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.45;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.export-date-range-calendar-weekdays {
|
||||
margin-top: 6px;
|
||||
margin-top: 10px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 2px;
|
||||
gap: 4px;
|
||||
|
||||
span {
|
||||
text-align: center;
|
||||
@@ -180,32 +234,61 @@
|
||||
}
|
||||
|
||||
.export-date-range-calendar-days {
|
||||
margin-top: 4px;
|
||||
margin-top: 6px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 2px;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.export-date-range-calendar-day {
|
||||
border: 1px solid transparent;
|
||||
border-radius: 6px;
|
||||
min-height: 20px;
|
||||
border-radius: 10px;
|
||||
min-height: 34px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-size: 10px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(var(--primary-rgb), 0.28);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:disabled:hover {
|
||||
border-color: transparent;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
&.outside {
|
||||
color: var(--text-quaternary);
|
||||
opacity: 0.75;
|
||||
opacity: 0.72;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: var(--primary);
|
||||
background: rgba(var(--primary-rgb), 0.14);
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.35;
|
||||
transform: none;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
&.in-range {
|
||||
background: rgba(var(--primary-rgb), 0.1);
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
&.range-start,
|
||||
&.range-end {
|
||||
border-color: var(--primary);
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
&.active-boundary {
|
||||
box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.22);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +330,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.export-date-range-calendar-grid {
|
||||
@media (max-width: 640px) {
|
||||
.export-date-range-boundary-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Check, X } from 'lucide-react'
|
||||
import { Check, ChevronLeft, ChevronRight, X } from 'lucide-react'
|
||||
import {
|
||||
EXPORT_DATE_RANGE_PRESETS,
|
||||
WEEKDAY_SHORT_LABELS,
|
||||
@@ -25,29 +25,78 @@ interface ExportDateRangeDialogProps {
|
||||
open: boolean
|
||||
value: ExportDateRangeSelection
|
||||
title?: string
|
||||
minDate?: Date | null
|
||||
maxDate?: Date | null
|
||||
onClose: () => void
|
||||
onConfirm: (value: ExportDateRangeSelection) => void
|
||||
}
|
||||
|
||||
type ActiveBoundary = 'start' | 'end'
|
||||
|
||||
interface ExportDateRangeDialogDraft extends ExportDateRangeSelection {
|
||||
startPanelMonth: Date
|
||||
endPanelMonth: Date
|
||||
panelMonth: Date
|
||||
}
|
||||
|
||||
const buildDialogDraft = (value: ExportDateRangeSelection): ExportDateRangeDialogDraft => ({
|
||||
...cloneExportDateRangeSelection(value),
|
||||
startPanelMonth: toMonthStart(value.dateRange.start),
|
||||
endPanelMonth: toMonthStart(value.dateRange.end)
|
||||
})
|
||||
const resolveBounds = (minDate?: Date | null, maxDate?: Date | null): { minDate: Date; maxDate: Date } | null => {
|
||||
if (!(minDate instanceof Date) || Number.isNaN(minDate.getTime())) return null
|
||||
if (!(maxDate instanceof Date) || Number.isNaN(maxDate.getTime())) return null
|
||||
const normalizedMin = startOfDay(minDate)
|
||||
const normalizedMax = endOfDay(maxDate)
|
||||
if (normalizedMin.getTime() > normalizedMax.getTime()) return null
|
||||
return {
|
||||
minDate: normalizedMin,
|
||||
maxDate: normalizedMax
|
||||
}
|
||||
}
|
||||
|
||||
const clampSelectionToBounds = (
|
||||
value: ExportDateRangeSelection,
|
||||
minDate?: Date | null,
|
||||
maxDate?: Date | null
|
||||
): ExportDateRangeSelection => {
|
||||
const bounds = resolveBounds(minDate, maxDate)
|
||||
if (!bounds) return cloneExportDateRangeSelection(value)
|
||||
|
||||
const rawStart = value.useAllTime ? bounds.minDate : startOfDay(value.dateRange.start)
|
||||
const rawEnd = value.useAllTime ? bounds.maxDate : endOfDay(value.dateRange.end)
|
||||
const nextStart = new Date(Math.min(Math.max(rawStart.getTime(), bounds.minDate.getTime()), bounds.maxDate.getTime()))
|
||||
const nextEndCandidate = new Date(Math.min(Math.max(rawEnd.getTime(), bounds.minDate.getTime()), bounds.maxDate.getTime()))
|
||||
const nextEnd = nextEndCandidate.getTime() < nextStart.getTime() ? endOfDay(nextStart) : nextEndCandidate
|
||||
const changed = nextStart.getTime() !== rawStart.getTime() || nextEnd.getTime() !== rawEnd.getTime()
|
||||
|
||||
return {
|
||||
preset: value.useAllTime ? value.preset : (changed ? 'custom' : value.preset),
|
||||
useAllTime: value.useAllTime,
|
||||
dateRange: {
|
||||
start: nextStart,
|
||||
end: nextEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const buildDialogDraft = (
|
||||
value: ExportDateRangeSelection,
|
||||
minDate?: Date | null,
|
||||
maxDate?: Date | null
|
||||
): ExportDateRangeDialogDraft => {
|
||||
const nextValue = clampSelectionToBounds(value, minDate, maxDate)
|
||||
return {
|
||||
...nextValue,
|
||||
panelMonth: toMonthStart(nextValue.dateRange.start)
|
||||
}
|
||||
}
|
||||
|
||||
export function ExportDateRangeDialog({
|
||||
open,
|
||||
value,
|
||||
title = '时间范围设置',
|
||||
minDate,
|
||||
maxDate,
|
||||
onClose,
|
||||
onConfirm
|
||||
}: ExportDateRangeDialogProps) {
|
||||
const [draft, setDraft] = useState<ExportDateRangeDialogDraft>(() => buildDialogDraft(value))
|
||||
const [draft, setDraft] = useState<ExportDateRangeDialogDraft>(() => buildDialogDraft(value, minDate, maxDate))
|
||||
const [activeBoundary, setActiveBoundary] = useState<ActiveBoundary>('start')
|
||||
const [dateInput, setDateInput] = useState({
|
||||
start: formatDateInputValue(value.dateRange.start),
|
||||
end: formatDateInputValue(value.dateRange.end)
|
||||
@@ -56,14 +105,15 @@ export function ExportDateRangeDialog({
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const nextDraft = buildDialogDraft(value)
|
||||
const nextDraft = buildDialogDraft(value, minDate, maxDate)
|
||||
setDraft(nextDraft)
|
||||
setActiveBoundary('start')
|
||||
setDateInput({
|
||||
start: formatDateInputValue(nextDraft.dateRange.start),
|
||||
end: formatDateInputValue(nextDraft.dateRange.end)
|
||||
})
|
||||
setDateInputError({ start: false, end: false })
|
||||
}, [open, value])
|
||||
}, [maxDate, minDate, open, value])
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
@@ -74,33 +124,24 @@ export function ExportDateRangeDialog({
|
||||
setDateInputError({ start: false, end: false })
|
||||
}, [draft.dateRange.end.getTime(), draft.dateRange.start.getTime(), open])
|
||||
|
||||
const applyPreset = useCallback((preset: Exclude<ExportDateRangePreset, 'custom'>) => {
|
||||
if (preset === 'all') {
|
||||
const previewRange = createDefaultDateRange()
|
||||
setDraft(prev => ({
|
||||
...prev,
|
||||
preset,
|
||||
useAllTime: true,
|
||||
dateRange: previewRange,
|
||||
startPanelMonth: toMonthStart(previewRange.start),
|
||||
endPanelMonth: toMonthStart(previewRange.end)
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
const range = createDateRangeByPreset(preset)
|
||||
setDraft(prev => ({
|
||||
...prev,
|
||||
preset,
|
||||
useAllTime: false,
|
||||
dateRange: range,
|
||||
startPanelMonth: toMonthStart(range.start),
|
||||
endPanelMonth: toMonthStart(range.end)
|
||||
}))
|
||||
}, [])
|
||||
|
||||
const updateDraftStart = useCallback((targetDate: Date) => {
|
||||
const bounds = useMemo(() => resolveBounds(minDate, maxDate), [maxDate, minDate])
|
||||
const clampStartDate = useCallback((targetDate: Date) => {
|
||||
const start = startOfDay(targetDate)
|
||||
if (!bounds) return start
|
||||
if (start.getTime() < bounds.minDate.getTime()) return bounds.minDate
|
||||
if (start.getTime() > bounds.maxDate.getTime()) return startOfDay(bounds.maxDate)
|
||||
return start
|
||||
}, [bounds])
|
||||
const clampEndDate = useCallback((targetDate: Date) => {
|
||||
const end = endOfDay(targetDate)
|
||||
if (!bounds) return end
|
||||
if (end.getTime() < bounds.minDate.getTime()) return endOfDay(bounds.minDate)
|
||||
if (end.getTime() > bounds.maxDate.getTime()) return bounds.maxDate
|
||||
return end
|
||||
}, [bounds])
|
||||
|
||||
const setRangeStart = useCallback((targetDate: Date) => {
|
||||
const start = clampStartDate(targetDate)
|
||||
setDraft(prev => {
|
||||
const nextEnd = prev.dateRange.end < start ? endOfDay(start) : prev.dateRange.end
|
||||
return {
|
||||
@@ -111,16 +152,15 @@ export function ExportDateRangeDialog({
|
||||
start,
|
||||
end: nextEnd
|
||||
},
|
||||
startPanelMonth: toMonthStart(start),
|
||||
endPanelMonth: toMonthStart(nextEnd)
|
||||
panelMonth: toMonthStart(start)
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
}, [clampStartDate])
|
||||
|
||||
const updateDraftEnd = useCallback((targetDate: Date) => {
|
||||
const end = endOfDay(targetDate)
|
||||
const setRangeEnd = useCallback((targetDate: Date) => {
|
||||
const end = clampEndDate(targetDate)
|
||||
setDraft(prev => {
|
||||
const nextStart = prev.useAllTime ? startOfDay(targetDate) : prev.dateRange.start
|
||||
const nextStart = prev.useAllTime ? clampStartDate(targetDate) : prev.dateRange.start
|
||||
const nextEnd = end < nextStart ? endOfDay(nextStart) : end
|
||||
return {
|
||||
...prev,
|
||||
@@ -130,11 +170,41 @@ export function ExportDateRangeDialog({
|
||||
start: nextStart,
|
||||
end: nextEnd
|
||||
},
|
||||
startPanelMonth: toMonthStart(nextStart),
|
||||
endPanelMonth: toMonthStart(nextEnd)
|
||||
panelMonth: toMonthStart(targetDate)
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
}, [clampEndDate, clampStartDate])
|
||||
|
||||
const applyPreset = useCallback((preset: Exclude<ExportDateRangePreset, 'custom'>) => {
|
||||
if (preset === 'all') {
|
||||
const previewRange = bounds
|
||||
? { start: bounds.minDate, end: bounds.maxDate }
|
||||
: createDefaultDateRange()
|
||||
setDraft(prev => ({
|
||||
...prev,
|
||||
preset,
|
||||
useAllTime: true,
|
||||
dateRange: previewRange,
|
||||
panelMonth: toMonthStart(previewRange.start)
|
||||
}))
|
||||
setActiveBoundary('start')
|
||||
return
|
||||
}
|
||||
|
||||
const range = clampSelectionToBounds({
|
||||
preset,
|
||||
useAllTime: false,
|
||||
dateRange: createDateRangeByPreset(preset)
|
||||
}, minDate, maxDate).dateRange
|
||||
setDraft(prev => ({
|
||||
...prev,
|
||||
preset,
|
||||
useAllTime: false,
|
||||
dateRange: range,
|
||||
panelMonth: toMonthStart(range.start)
|
||||
}))
|
||||
setActiveBoundary('start')
|
||||
}, [bounds, maxDate, minDate])
|
||||
|
||||
const commitStartFromInput = useCallback(() => {
|
||||
const parsed = parseDateInputValue(dateInput.start)
|
||||
@@ -143,8 +213,8 @@ export function ExportDateRangeDialog({
|
||||
return
|
||||
}
|
||||
setDateInputError(prev => ({ ...prev, start: false }))
|
||||
updateDraftStart(parsed)
|
||||
}, [dateInput.start, updateDraftStart])
|
||||
setRangeStart(parsed)
|
||||
}, [dateInput.start, setRangeStart])
|
||||
|
||||
const commitEndFromInput = useCallback(() => {
|
||||
const parsed = parseDateInputValue(dateInput.end)
|
||||
@@ -153,29 +223,81 @@ export function ExportDateRangeDialog({
|
||||
return
|
||||
}
|
||||
setDateInputError(prev => ({ ...prev, end: false }))
|
||||
updateDraftEnd(parsed)
|
||||
}, [dateInput.end, updateDraftEnd])
|
||||
setRangeEnd(parsed)
|
||||
}, [dateInput.end, setRangeEnd])
|
||||
|
||||
const shiftPanelMonth = useCallback((panel: 'start' | 'end', delta: number) => {
|
||||
setDraft(prev => (
|
||||
panel === 'start'
|
||||
? { ...prev, startPanelMonth: addMonths(prev.startPanelMonth, delta) }
|
||||
: { ...prev, endPanelMonth: addMonths(prev.endPanelMonth, delta) }
|
||||
))
|
||||
const shiftPanelMonth = useCallback((delta: number) => {
|
||||
setDraft(prev => ({
|
||||
...prev,
|
||||
panelMonth: addMonths(prev.panelMonth, delta)
|
||||
}))
|
||||
}, [])
|
||||
|
||||
const handleCalendarSelect = useCallback((targetDate: Date) => {
|
||||
if (activeBoundary === 'start') {
|
||||
setRangeStart(targetDate)
|
||||
setActiveBoundary('end')
|
||||
return
|
||||
}
|
||||
|
||||
setDraft(prev => {
|
||||
const start = prev.useAllTime ? startOfDay(targetDate) : prev.dateRange.start
|
||||
const pickedStart = startOfDay(targetDate)
|
||||
const nextStart = pickedStart <= start ? pickedStart : start
|
||||
const nextEnd = pickedStart <= start ? endOfDay(start) : endOfDay(targetDate)
|
||||
return {
|
||||
...prev,
|
||||
preset: 'custom',
|
||||
useAllTime: false,
|
||||
dateRange: {
|
||||
start: nextStart,
|
||||
end: nextEnd
|
||||
},
|
||||
panelMonth: toMonthStart(targetDate)
|
||||
}
|
||||
})
|
||||
setActiveBoundary('start')
|
||||
}, [activeBoundary, setRangeEnd, setRangeStart])
|
||||
|
||||
const isRangeModeActive = !draft.useAllTime
|
||||
const modeText = isRangeModeActive
|
||||
? '当前导出模式:按时间范围导出'
|
||||
: '当前导出模式:全部时间导出(选择下方日期将切换为按时间范围导出)'
|
||||
: '当前导出模式:全部时间导出,选择下方日期会切换为自定义时间范围'
|
||||
|
||||
const isPresetActive = useCallback((preset: ExportDateRangePreset): boolean => {
|
||||
if (preset === 'all') return draft.useAllTime
|
||||
return !draft.useAllTime && draft.preset === preset
|
||||
}, [draft])
|
||||
|
||||
const startPanelCells = useMemo(() => buildCalendarCells(draft.startPanelMonth), [draft.startPanelMonth])
|
||||
const endPanelCells = useMemo(() => buildCalendarCells(draft.endPanelMonth), [draft.endPanelMonth])
|
||||
const calendarCells = useMemo(() => buildCalendarCells(draft.panelMonth), [draft.panelMonth])
|
||||
const minPanelMonth = bounds ? toMonthStart(bounds.minDate) : null
|
||||
const maxPanelMonth = bounds ? toMonthStart(bounds.maxDate) : null
|
||||
const canShiftPrev = !minPanelMonth || draft.panelMonth.getTime() > minPanelMonth.getTime()
|
||||
const canShiftNext = !maxPanelMonth || draft.panelMonth.getTime() < maxPanelMonth.getTime()
|
||||
|
||||
const isStartSelected = useCallback((date: Date) => (
|
||||
!draft.useAllTime && isSameDay(date, draft.dateRange.start)
|
||||
), [draft])
|
||||
|
||||
const isEndSelected = useCallback((date: Date) => (
|
||||
!draft.useAllTime && isSameDay(date, draft.dateRange.end)
|
||||
), [draft])
|
||||
|
||||
const isDateInRange = useCallback((date: Date) => (
|
||||
!draft.useAllTime &&
|
||||
startOfDay(date).getTime() >= startOfDay(draft.dateRange.start).getTime() &&
|
||||
startOfDay(date).getTime() <= startOfDay(draft.dateRange.end).getTime()
|
||||
), [draft])
|
||||
|
||||
const isDateSelectable = useCallback((date: Date) => {
|
||||
if (!bounds) return true
|
||||
const target = startOfDay(date).getTime()
|
||||
return target >= startOfDay(bounds.minDate).getTime() && target <= startOfDay(bounds.maxDate).getTime()
|
||||
}, [bounds])
|
||||
|
||||
const hintText = draft.useAllTime
|
||||
? '选择开始或结束日期后,会自动切换为自定义时间范围'
|
||||
: (activeBoundary === 'start' ? '下一次点击将设置开始日期' : '下一次点击将设置结束日期')
|
||||
|
||||
if (!open) return null
|
||||
|
||||
@@ -215,112 +337,115 @@ export function ExportDateRangeDialog({
|
||||
{modeText}
|
||||
</div>
|
||||
|
||||
<div className="export-date-range-calendar-grid">
|
||||
<section className="export-date-range-calendar-panel">
|
||||
<div className="export-date-range-calendar-panel-header">
|
||||
<div className="export-date-range-calendar-date-label">
|
||||
<span>起始日期</span>
|
||||
<input
|
||||
type="text"
|
||||
className={`export-date-range-date-input ${dateInputError.start ? 'invalid' : ''}`}
|
||||
value={dateInput.start}
|
||||
placeholder="YYYY-MM-DD"
|
||||
onChange={(event) => {
|
||||
const nextValue = event.target.value
|
||||
setDateInput(prev => ({ ...prev, start: nextValue }))
|
||||
if (dateInputError.start) {
|
||||
setDateInputError(prev => ({ ...prev, start: false }))
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
commitStartFromInput()
|
||||
}}
|
||||
onBlur={commitStartFromInput}
|
||||
/>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-nav">
|
||||
<button type="button" onClick={() => shiftPanelMonth('start', -1)} aria-label="上个月">‹</button>
|
||||
<span>{formatCalendarMonthTitle(draft.startPanelMonth)}</span>
|
||||
<button type="button" onClick={() => shiftPanelMonth('start', 1)} aria-label="下个月">›</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-weekdays">
|
||||
{WEEKDAY_SHORT_LABELS.map(label => (
|
||||
<span key={`start-weekday-${label}`}>{label}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="export-date-range-calendar-days">
|
||||
{startPanelCells.map((cell) => {
|
||||
const selected = !draft.useAllTime && isSameDay(cell.date, draft.dateRange.start)
|
||||
return (
|
||||
<button
|
||||
key={`start-${cell.date.getTime()}`}
|
||||
type="button"
|
||||
className={`export-date-range-calendar-day ${cell.inCurrentMonth ? '' : 'outside'} ${selected ? 'selected' : ''}`}
|
||||
onClick={() => updateDraftStart(cell.date)}
|
||||
>
|
||||
{cell.date.getDate()}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="export-date-range-calendar-panel">
|
||||
<div className="export-date-range-calendar-panel-header">
|
||||
<div className="export-date-range-calendar-date-label">
|
||||
<span>截止日期</span>
|
||||
<input
|
||||
type="text"
|
||||
className={`export-date-range-date-input ${dateInputError.end ? 'invalid' : ''}`}
|
||||
value={dateInput.end}
|
||||
placeholder="YYYY-MM-DD"
|
||||
onChange={(event) => {
|
||||
const nextValue = event.target.value
|
||||
setDateInput(prev => ({ ...prev, end: nextValue }))
|
||||
if (dateInputError.end) {
|
||||
setDateInputError(prev => ({ ...prev, end: false }))
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
commitEndFromInput()
|
||||
}}
|
||||
onBlur={commitEndFromInput}
|
||||
/>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-nav">
|
||||
<button type="button" onClick={() => shiftPanelMonth('end', -1)} aria-label="上个月">‹</button>
|
||||
<span>{formatCalendarMonthTitle(draft.endPanelMonth)}</span>
|
||||
<button type="button" onClick={() => shiftPanelMonth('end', 1)} aria-label="下个月">›</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-weekdays">
|
||||
{WEEKDAY_SHORT_LABELS.map(label => (
|
||||
<span key={`end-weekday-${label}`}>{label}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="export-date-range-calendar-days">
|
||||
{endPanelCells.map((cell) => {
|
||||
const selected = !draft.useAllTime && isSameDay(cell.date, draft.dateRange.end)
|
||||
return (
|
||||
<button
|
||||
key={`end-${cell.date.getTime()}`}
|
||||
type="button"
|
||||
className={`export-date-range-calendar-day ${cell.inCurrentMonth ? '' : 'outside'} ${selected ? 'selected' : ''}`}
|
||||
onClick={() => updateDraftEnd(cell.date)}
|
||||
>
|
||||
{cell.date.getDate()}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
<div className="export-date-range-boundary-row">
|
||||
<div
|
||||
className={`export-date-range-boundary-card ${activeBoundary === 'start' ? 'active' : ''}`}
|
||||
onClick={() => setActiveBoundary('start')}
|
||||
>
|
||||
<span className="boundary-label">开始</span>
|
||||
<input
|
||||
type="text"
|
||||
className={`export-date-range-date-input ${dateInputError.start ? 'invalid' : ''}`}
|
||||
value={dateInput.start}
|
||||
placeholder="YYYY-MM-DD"
|
||||
onChange={(event) => {
|
||||
const nextValue = event.target.value
|
||||
setDateInput(prev => ({ ...prev, start: nextValue }))
|
||||
if (dateInputError.start) {
|
||||
setDateInputError(prev => ({ ...prev, start: false }))
|
||||
}
|
||||
}}
|
||||
onFocus={() => setActiveBoundary('start')}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
commitStartFromInput()
|
||||
}}
|
||||
onBlur={commitStartFromInput}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className={`export-date-range-boundary-card ${activeBoundary === 'end' ? 'active' : ''}`}
|
||||
onClick={() => setActiveBoundary('end')}
|
||||
>
|
||||
<span className="boundary-label">结束</span>
|
||||
<input
|
||||
type="text"
|
||||
className={`export-date-range-date-input ${dateInputError.end ? 'invalid' : ''}`}
|
||||
value={dateInput.end}
|
||||
placeholder="YYYY-MM-DD"
|
||||
onChange={(event) => {
|
||||
const nextValue = event.target.value
|
||||
setDateInput(prev => ({ ...prev, end: nextValue }))
|
||||
if (dateInputError.end) {
|
||||
setDateInputError(prev => ({ ...prev, end: false }))
|
||||
}
|
||||
}}
|
||||
onFocus={() => setActiveBoundary('end')}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
commitEndFromInput()
|
||||
}}
|
||||
onBlur={commitEndFromInput}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="export-date-range-selection-hint">{hintText}</div>
|
||||
|
||||
<section className="export-date-range-calendar-panel single">
|
||||
<div className="export-date-range-calendar-panel-header">
|
||||
<div className="export-date-range-calendar-date-label">
|
||||
<span>选择日期范围</span>
|
||||
<strong>{formatCalendarMonthTitle(draft.panelMonth)}</strong>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-nav">
|
||||
<button type="button" onClick={() => shiftPanelMonth(-1)} aria-label="上个月" disabled={!canShiftPrev}>
|
||||
<ChevronLeft size={14} />
|
||||
</button>
|
||||
<button type="button" onClick={() => shiftPanelMonth(1)} aria-label="下个月" disabled={!canShiftNext}>
|
||||
<ChevronRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="export-date-range-calendar-weekdays">
|
||||
{WEEKDAY_SHORT_LABELS.map(label => (
|
||||
<span key={`weekday-${label}`}>{label}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="export-date-range-calendar-days">
|
||||
{calendarCells.map((cell) => {
|
||||
const startSelected = isStartSelected(cell.date)
|
||||
const endSelected = isEndSelected(cell.date)
|
||||
const inRange = isDateInRange(cell.date)
|
||||
const selectable = isDateSelectable(cell.date)
|
||||
return (
|
||||
<button
|
||||
key={cell.date.getTime()}
|
||||
type="button"
|
||||
disabled={!selectable}
|
||||
className={[
|
||||
'export-date-range-calendar-day',
|
||||
cell.inCurrentMonth ? '' : 'outside',
|
||||
selectable ? '' : 'disabled',
|
||||
inRange ? 'in-range' : '',
|
||||
startSelected ? 'range-start' : '',
|
||||
endSelected ? 'range-end' : '',
|
||||
activeBoundary === 'start' && startSelected ? 'active-boundary' : '',
|
||||
activeBoundary === 'end' && endSelected ? 'active-boundary' : ''
|
||||
].filter(Boolean).join(' ')}
|
||||
onClick={() => handleCalendarSelect(cell.date)}
|
||||
>
|
||||
{cell.date.getDate()}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="export-date-range-dialog-actions">
|
||||
<button type="button" className="export-date-range-dialog-btn secondary" onClick={onClose}>
|
||||
取消
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useMemo, useEffect } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Heart, ChevronRight, ImageIcon, Code, Trash2 } from 'lucide-react'
|
||||
import { SnsPost, SnsLinkCardData } from '../../types/sns'
|
||||
import { Heart, ChevronRight, ImageIcon, Code, Trash2, MapPin } from 'lucide-react'
|
||||
import { SnsPost, SnsLinkCardData, SnsLocation } from '../../types/sns'
|
||||
import { Avatar } from '../Avatar'
|
||||
import { SnsMediaGrid } from './SnsMediaGrid'
|
||||
import { getEmojiPath } from 'wechat-emojis'
|
||||
@@ -134,6 +134,30 @@ const buildLinkCardData = (post: SnsPost): SnsLinkCardData | null => {
|
||||
}
|
||||
}
|
||||
|
||||
const buildLocationText = (location?: SnsLocation): string => {
|
||||
if (!location) return ''
|
||||
|
||||
const normalize = (value?: string): string => (
|
||||
decodeHtmlEntities(String(value || '')).replace(/\s+/g, ' ').trim()
|
||||
)
|
||||
|
||||
const primary = [
|
||||
normalize(location.poiName),
|
||||
normalize(location.poiAddressName),
|
||||
normalize(location.label),
|
||||
normalize(location.poiAddress)
|
||||
].find(Boolean) || ''
|
||||
|
||||
const region = [normalize(location.country), normalize(location.city)]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
|
||||
if (primary && region && !primary.includes(region)) {
|
||||
return `${primary} · ${region}`
|
||||
}
|
||||
return primary || region
|
||||
}
|
||||
|
||||
const SnsLinkCard = ({ card }: { card: SnsLinkCardData }) => {
|
||||
const [thumbFailed, setThumbFailed] = useState(false)
|
||||
const hostname = useMemo(() => {
|
||||
@@ -254,6 +278,7 @@ export const SnsPostItem: React.FC<SnsPostItemProps> = ({ post, onPreview, onDeb
|
||||
const [deleting, setDeleting] = useState(false)
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||
const linkCard = buildLinkCardData(post)
|
||||
const locationText = useMemo(() => buildLocationText(post.location), [post.location])
|
||||
const hasVideoMedia = post.type === 15 || post.media.some((item) => isSnsVideoUrl(item.url))
|
||||
const showLinkCard = Boolean(linkCard) && post.media.length <= 1 && !hasVideoMedia
|
||||
const showMediaGrid = post.media.length > 0 && !showLinkCard
|
||||
@@ -379,6 +404,13 @@ export const SnsPostItem: React.FC<SnsPostItemProps> = ({ post, onPreview, onDeb
|
||||
<div className="post-text">{renderTextWithEmoji(decodeHtmlEntities(post.contentDesc))}</div>
|
||||
)}
|
||||
|
||||
{locationText && (
|
||||
<div className="post-location" title={locationText}>
|
||||
<MapPin size={14} />
|
||||
<span className="post-location-text">{locationText}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showLinkCard && linkCard && (
|
||||
<SnsLinkCard card={linkCard} />
|
||||
)}
|
||||
|
||||
@@ -2420,7 +2420,6 @@
|
||||
background: rgba(0, 0, 0, 0.04);
|
||||
border-left: 2px solid var(--primary);
|
||||
padding: 6px 10px;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
|
||||
@@ -2482,6 +2481,14 @@
|
||||
|
||||
.bubble-content {
|
||||
-webkit-app-region: no-drag;
|
||||
|
||||
&.quote-layout-top .quoted-message {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
&.quote-layout-bottom .quoted-message {
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
// 时间分隔
|
||||
|
||||
@@ -52,6 +52,8 @@ interface GlobalMsgPrefixCacheEntry {
|
||||
completed: boolean
|
||||
}
|
||||
|
||||
type QuoteLayout = configService.QuoteLayout
|
||||
|
||||
const GLOBAL_MSG_PER_SESSION_LIMIT = 10
|
||||
const GLOBAL_MSG_SEED_LIMIT = 120
|
||||
const GLOBAL_MSG_BACKFILL_CONCURRENCY = 3
|
||||
@@ -585,6 +587,263 @@ interface GroupPanelMember {
|
||||
messageCountStatus: GroupMessageCountStatus
|
||||
}
|
||||
|
||||
const QUOTED_SENDER_CACHE_TTL_MS = 10 * 60 * 1000
|
||||
const quotedSenderDisplayCache = new Map<string, { displayName: string; updatedAt: number }>()
|
||||
const quotedSenderDisplayLoading = new Map<string, Promise<string | undefined>>()
|
||||
const quotedGroupMembersCache = new Map<string, { members: GroupPanelMember[]; updatedAt: number }>()
|
||||
const quotedGroupMembersLoading = new Map<string, Promise<GroupPanelMember[]>>()
|
||||
|
||||
function buildQuotedSenderCacheKey(
|
||||
sessionId: string,
|
||||
senderUsername: string,
|
||||
isGroupChat: boolean
|
||||
): string {
|
||||
const normalizedSessionId = normalizeSearchIdentityText(sessionId) || String(sessionId || '').trim()
|
||||
const normalizedSender = normalizeSearchIdentityText(senderUsername) || String(senderUsername || '').trim()
|
||||
return `${isGroupChat ? 'group' : 'direct'}::${normalizedSessionId}::${normalizedSender}`
|
||||
}
|
||||
|
||||
function isSameQuotedSenderIdentity(left?: string | null, right?: string | null): boolean {
|
||||
const leftCandidates = buildSearchIdentityCandidates(left)
|
||||
const rightCandidates = buildSearchIdentityCandidates(right)
|
||||
if (leftCandidates.length === 0 || rightCandidates.length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (const leftCandidate of leftCandidates) {
|
||||
for (const rightCandidate of rightCandidates) {
|
||||
if (leftCandidate === rightCandidate) return true
|
||||
if (leftCandidate.startsWith(rightCandidate + '_')) return true
|
||||
if (rightCandidate.startsWith(leftCandidate + '_')) return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function normalizeQuotedGroupMember(member: Partial<GroupPanelMember> | null | undefined): GroupPanelMember | null {
|
||||
const username = String(member?.username || '').trim()
|
||||
if (!username) return null
|
||||
|
||||
const displayName = String(member?.displayName || '').trim()
|
||||
const nickname = String(member?.nickname || '').trim()
|
||||
const remark = String(member?.remark || '').trim()
|
||||
const alias = String(member?.alias || '').trim()
|
||||
const groupNickname = String(member?.groupNickname || '').trim()
|
||||
|
||||
return {
|
||||
username,
|
||||
displayName: displayName || groupNickname || remark || nickname || alias || username,
|
||||
avatarUrl: member?.avatarUrl,
|
||||
nickname,
|
||||
alias,
|
||||
remark,
|
||||
groupNickname,
|
||||
isOwner: Boolean(member?.isOwner),
|
||||
isFriend: Boolean(member?.isFriend),
|
||||
messageCount: Number.isFinite(member?.messageCount) ? Math.max(0, Math.floor(member?.messageCount as number)) : 0,
|
||||
messageCountStatus: 'ready'
|
||||
}
|
||||
}
|
||||
|
||||
function resolveQuotedSenderFallbackDisplayName(
|
||||
sessionId: string,
|
||||
senderUsername?: string | null,
|
||||
fallbackDisplayName?: string | null
|
||||
): string | undefined {
|
||||
const resolved = resolveSearchSenderDisplayName(fallbackDisplayName, senderUsername, sessionId)
|
||||
if (resolved) return resolved
|
||||
return resolveSearchSenderUsernameFallback(senderUsername)
|
||||
}
|
||||
|
||||
function resolveQuotedSenderUsername(
|
||||
fromusr?: string | null,
|
||||
chatusr?: string | null
|
||||
): string {
|
||||
const normalizedChatUsr = String(chatusr || '').trim()
|
||||
const normalizedFromUsr = String(fromusr || '').trim()
|
||||
|
||||
if (normalizedChatUsr) {
|
||||
return normalizedChatUsr
|
||||
}
|
||||
|
||||
if (normalizedFromUsr.endsWith('@chatroom')) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return normalizedFromUsr
|
||||
}
|
||||
|
||||
function resolveQuotedGroupMemberDisplayName(member: GroupPanelMember): string | undefined {
|
||||
const remark = normalizeSearchIdentityText(member.remark)
|
||||
if (remark) return remark
|
||||
|
||||
const groupNickname = normalizeSearchIdentityText(member.groupNickname)
|
||||
if (groupNickname) return groupNickname
|
||||
|
||||
const nickname = normalizeSearchIdentityText(member.nickname)
|
||||
if (nickname) return nickname
|
||||
|
||||
const displayName = resolveSearchSenderDisplayName(member.displayName, member.username)
|
||||
if (displayName) return displayName
|
||||
|
||||
const alias = normalizeSearchIdentityText(member.alias)
|
||||
if (alias) return alias
|
||||
|
||||
return resolveSearchSenderUsernameFallback(member.username)
|
||||
}
|
||||
|
||||
function resolveQuotedPrivateDisplayName(contact: any): string | undefined {
|
||||
const remark = normalizeSearchIdentityText(contact?.remark)
|
||||
if (remark) return remark
|
||||
|
||||
const nickname = normalizeSearchIdentityText(
|
||||
contact?.nickName || contact?.nick_name || contact?.nickname
|
||||
)
|
||||
if (nickname) return nickname
|
||||
|
||||
const alias = normalizeSearchIdentityText(contact?.alias)
|
||||
if (alias) return alias
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
async function getQuotedGroupMembers(chatroomId: string): Promise<GroupPanelMember[]> {
|
||||
const normalizedChatroomId = String(chatroomId || '').trim()
|
||||
if (!normalizedChatroomId || !normalizedChatroomId.includes('@chatroom')) {
|
||||
return []
|
||||
}
|
||||
|
||||
const cached = quotedGroupMembersCache.get(normalizedChatroomId)
|
||||
if (cached && Date.now() - cached.updatedAt < QUOTED_SENDER_CACHE_TTL_MS) {
|
||||
return cached.members
|
||||
}
|
||||
|
||||
const pending = quotedGroupMembersLoading.get(normalizedChatroomId)
|
||||
if (pending) return pending
|
||||
|
||||
const request = window.electronAPI.groupAnalytics.getGroupMembersPanelData(
|
||||
normalizedChatroomId,
|
||||
{ forceRefresh: false, includeMessageCounts: false }
|
||||
).then((result) => {
|
||||
const members = Array.isArray(result.data)
|
||||
? result.data
|
||||
.map((member) => normalizeQuotedGroupMember(member as Partial<GroupPanelMember>))
|
||||
.filter((member): member is GroupPanelMember => Boolean(member))
|
||||
: []
|
||||
|
||||
if (members.length > 0) {
|
||||
quotedGroupMembersCache.set(normalizedChatroomId, {
|
||||
members,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
return members
|
||||
}
|
||||
|
||||
return cached?.members || []
|
||||
}).catch(() => cached?.members || []).finally(() => {
|
||||
quotedGroupMembersLoading.delete(normalizedChatroomId)
|
||||
})
|
||||
|
||||
quotedGroupMembersLoading.set(normalizedChatroomId, request)
|
||||
return request
|
||||
}
|
||||
|
||||
async function resolveQuotedSenderDisplayName(options: {
|
||||
sessionId: string
|
||||
senderUsername?: string | null
|
||||
fallbackDisplayName?: string | null
|
||||
isGroupChat?: boolean
|
||||
myWxid?: string | null
|
||||
}): Promise<string | undefined> {
|
||||
const normalizedSessionId = String(options.sessionId || '').trim()
|
||||
const normalizedSender = String(options.senderUsername || '').trim()
|
||||
const fallbackDisplayName = resolveQuotedSenderFallbackDisplayName(
|
||||
normalizedSessionId,
|
||||
normalizedSender,
|
||||
options.fallbackDisplayName
|
||||
)
|
||||
|
||||
if (!normalizedSender) {
|
||||
return fallbackDisplayName
|
||||
}
|
||||
|
||||
const cacheKey = buildQuotedSenderCacheKey(normalizedSessionId, normalizedSender, Boolean(options.isGroupChat))
|
||||
const cached = quotedSenderDisplayCache.get(cacheKey)
|
||||
if (cached && Date.now() - cached.updatedAt < QUOTED_SENDER_CACHE_TTL_MS) {
|
||||
return cached.displayName
|
||||
}
|
||||
|
||||
const pending = quotedSenderDisplayLoading.get(cacheKey)
|
||||
if (pending) return pending
|
||||
|
||||
const request = (async (): Promise<string | undefined> => {
|
||||
if (options.isGroupChat) {
|
||||
const members = await getQuotedGroupMembers(normalizedSessionId)
|
||||
const matchedMember = members.find((member) => isSameQuotedSenderIdentity(member.username, normalizedSender))
|
||||
const groupDisplayName = matchedMember ? resolveQuotedGroupMemberDisplayName(matchedMember) : undefined
|
||||
if (groupDisplayName) {
|
||||
quotedSenderDisplayCache.set(cacheKey, {
|
||||
displayName: groupDisplayName,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
return groupDisplayName
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurrentUserSearchIdentity(normalizedSender, options.myWxid)) {
|
||||
const selfDisplayName = fallbackDisplayName || '我'
|
||||
quotedSenderDisplayCache.set(cacheKey, {
|
||||
displayName: selfDisplayName,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
return selfDisplayName
|
||||
}
|
||||
|
||||
try {
|
||||
const contact = await window.electronAPI.chat.getContact(normalizedSender)
|
||||
const contactDisplayName = resolveQuotedPrivateDisplayName(contact)
|
||||
if (contactDisplayName) {
|
||||
quotedSenderDisplayCache.set(cacheKey, {
|
||||
displayName: contactDisplayName,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
return contactDisplayName
|
||||
}
|
||||
} catch {
|
||||
// ignore contact lookup failures and fall back below
|
||||
}
|
||||
|
||||
try {
|
||||
const profile = await window.electronAPI.chat.getContactAvatar(normalizedSender)
|
||||
const profileDisplayName = normalizeSearchIdentityText(profile?.displayName)
|
||||
if (profileDisplayName && !isWxidLikeSearchIdentity(profileDisplayName)) {
|
||||
quotedSenderDisplayCache.set(cacheKey, {
|
||||
displayName: profileDisplayName,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
return profileDisplayName
|
||||
}
|
||||
} catch {
|
||||
// ignore avatar lookup failures and keep fallback usable
|
||||
}
|
||||
|
||||
if (fallbackDisplayName) {
|
||||
quotedSenderDisplayCache.set(cacheKey, {
|
||||
displayName: fallbackDisplayName,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
}
|
||||
|
||||
return fallbackDisplayName
|
||||
})().finally(() => {
|
||||
quotedSenderDisplayLoading.delete(cacheKey)
|
||||
})
|
||||
|
||||
quotedSenderDisplayLoading.set(cacheKey, request)
|
||||
return request
|
||||
}
|
||||
|
||||
interface SessionListCachePayload {
|
||||
updatedAt: number
|
||||
sessions: ChatSession[]
|
||||
@@ -2394,6 +2653,10 @@ function ChatPage(props: ChatPageProps) {
|
||||
const handleAccountChanged = useCallback(async () => {
|
||||
senderAvatarCache.clear()
|
||||
senderAvatarLoading.clear()
|
||||
quotedSenderDisplayCache.clear()
|
||||
quotedSenderDisplayLoading.clear()
|
||||
quotedGroupMembersCache.clear()
|
||||
quotedGroupMembersLoading.clear()
|
||||
sessionContactProfileCacheRef.current.clear()
|
||||
pendingSessionContactEnrichRef.current.clear()
|
||||
sessionContactEnrichAttemptAtRef.current.clear()
|
||||
@@ -5660,6 +5923,7 @@ function ChatPage(props: ChatPageProps) {
|
||||
session={currentSession!}
|
||||
showTime={!showDateDivider && showTime}
|
||||
myAvatarUrl={myAvatarUrl}
|
||||
myWxid={myWxid}
|
||||
isGroupChat={isCurrentSessionGroup}
|
||||
autoTranscribeVoiceEnabled={autoTranscribeVoiceEnabled}
|
||||
onRequireModelDownload={handleRequireModelDownload}
|
||||
@@ -5678,6 +5942,7 @@ function ChatPage(props: ChatPageProps) {
|
||||
formatDateDivider,
|
||||
currentSession,
|
||||
myAvatarUrl,
|
||||
myWxid,
|
||||
isCurrentSessionGroup,
|
||||
autoTranscribeVoiceEnabled,
|
||||
handleRequireModelDownload,
|
||||
@@ -7258,6 +7523,7 @@ function MessageBubble({
|
||||
session,
|
||||
showTime,
|
||||
myAvatarUrl,
|
||||
myWxid,
|
||||
isGroupChat,
|
||||
autoTranscribeVoiceEnabled,
|
||||
onRequireModelDownload,
|
||||
@@ -7271,6 +7537,7 @@ function MessageBubble({
|
||||
session: ChatSession;
|
||||
showTime?: boolean;
|
||||
myAvatarUrl?: string;
|
||||
myWxid?: string;
|
||||
isGroupChat?: boolean;
|
||||
autoTranscribeVoiceEnabled?: boolean;
|
||||
onRequireModelDownload?: (sessionId: string, messageId: string) => void;
|
||||
@@ -7290,6 +7557,8 @@ function MessageBubble({
|
||||
const isSent = message.isSend === 1
|
||||
const [senderAvatarUrl, setSenderAvatarUrl] = useState<string | undefined>(undefined)
|
||||
const [senderName, setSenderName] = useState<string | undefined>(undefined)
|
||||
const [quotedSenderName, setQuotedSenderName] = useState<string | undefined>(undefined)
|
||||
const [quoteLayout, setQuoteLayout] = useState<QuoteLayout>('quote-top')
|
||||
const senderProfileRequestSeqRef = useRef(0)
|
||||
const [emojiError, setEmojiError] = useState(false)
|
||||
const [emojiLoading, setEmojiLoading] = useState(false)
|
||||
@@ -7345,6 +7614,12 @@ function MessageBubble({
|
||||
const [voiceWaveform, setVoiceWaveform] = useState<number[]>([])
|
||||
const voiceAutoDecryptTriggered = useRef(false)
|
||||
|
||||
|
||||
const [systemAlert, setSystemAlert] = useState<{
|
||||
title: string;
|
||||
message: React.ReactNode;
|
||||
} | null>(null)
|
||||
|
||||
// 转账消息双方名称
|
||||
const [transferPayerName, setTransferPayerName] = useState<string | undefined>(undefined)
|
||||
const [transferReceiverName, setTransferReceiverName] = useState<string | undefined>(undefined)
|
||||
@@ -8024,9 +8299,9 @@ function MessageBubble({
|
||||
}
|
||||
|
||||
const result = await window.electronAPI.chat.getVoiceTranscript(
|
||||
session.username,
|
||||
String(message.localId),
|
||||
message.createTime
|
||||
session.username,
|
||||
String(message.localId),
|
||||
message.createTime
|
||||
)
|
||||
|
||||
if (result.success) {
|
||||
@@ -8034,6 +8309,21 @@ function MessageBubble({
|
||||
voiceTranscriptCache.set(voiceTranscriptCacheKey, transcriptText)
|
||||
setVoiceTranscript(transcriptText)
|
||||
} else {
|
||||
if (result.error === 'SEGFAULT_ERROR') {
|
||||
console.warn('[ChatPage] 捕获到语音引擎底层段错误');
|
||||
|
||||
setSystemAlert({
|
||||
title: '引擎崩溃提示',
|
||||
message: (
|
||||
<>
|
||||
语音识别引擎发生底层崩溃 (Segmentation Fault)。<br /><br />
|
||||
如果您使用的是 Linux 等自定义程度较高的系统,请检查 <code>sherpa-onnx</code> 的相关系统动态链接库 (如 glibc 等) 是否兼容。
|
||||
</>
|
||||
)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
setVoiceTranscriptError(true)
|
||||
voiceTranscriptRequestedRef.current = false
|
||||
}
|
||||
@@ -8214,6 +8504,65 @@ function MessageBubble({
|
||||
appMsgTextCache.set(selector, value)
|
||||
return value
|
||||
}, [appMsgDoc, appMsgTextCache])
|
||||
const quotedSenderUsername = resolveQuotedSenderUsername(
|
||||
queryAppMsgText('refermsg > fromusr'),
|
||||
queryAppMsgText('refermsg > chatusr')
|
||||
)
|
||||
const quotedContent = message.quotedContent || queryAppMsgText('refermsg > content') || ''
|
||||
const quotedSenderFallbackName = useMemo(
|
||||
() => resolveQuotedSenderFallbackDisplayName(
|
||||
session.username,
|
||||
quotedSenderUsername,
|
||||
message.quotedSender || queryAppMsgText('refermsg > displayname') || ''
|
||||
),
|
||||
[message.quotedSender, queryAppMsgText, quotedSenderUsername, session.username]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const nextFallbackName = quotedSenderFallbackName || undefined
|
||||
setQuotedSenderName(nextFallbackName)
|
||||
|
||||
if (!quotedContent || !quotedSenderUsername) {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
void resolveQuotedSenderDisplayName({
|
||||
sessionId: session.username,
|
||||
senderUsername: quotedSenderUsername,
|
||||
fallbackDisplayName: nextFallbackName,
|
||||
isGroupChat,
|
||||
myWxid
|
||||
}).then((resolvedName) => {
|
||||
if (cancelled) return
|
||||
setQuotedSenderName(resolvedName || nextFallbackName)
|
||||
})
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [
|
||||
quotedContent,
|
||||
quotedSenderFallbackName,
|
||||
quotedSenderUsername,
|
||||
session.username,
|
||||
isGroupChat,
|
||||
myWxid
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
void configService.getQuoteLayout().then((layout) => {
|
||||
if (!cancelled) setQuoteLayout(layout)
|
||||
}).catch(() => {
|
||||
if (!cancelled) setQuoteLayout('quote-top')
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
const locationMessageMeta = useMemo(() => {
|
||||
if (message.localType !== 48) return null
|
||||
@@ -8248,7 +8597,33 @@ function MessageBubble({
|
||||
: (isGroupChat ? resolvedSenderAvatarUrl : session.avatarUrl)
|
||||
|
||||
// 是否有引用消息
|
||||
const hasQuote = message.quotedContent && message.quotedContent.length > 0
|
||||
const hasQuote = quotedContent.length > 0
|
||||
const displayQuotedSenderName = quotedSenderName || quotedSenderFallbackName
|
||||
const renderBubbleWithQuote = useCallback((quotedNode: React.ReactNode, messageNode: React.ReactNode) => {
|
||||
const quoteFirst = quoteLayout !== 'quote-bottom'
|
||||
return (
|
||||
<div className={`bubble-content ${quoteFirst ? 'quote-layout-top' : 'quote-layout-bottom'}`}>
|
||||
{quoteFirst ? (
|
||||
<>
|
||||
{quotedNode}
|
||||
{messageNode}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{messageNode}
|
||||
{quotedNode}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}, [quoteLayout])
|
||||
|
||||
const renderQuotedMessageBlock = useCallback((contentNode: React.ReactNode) => (
|
||||
<div className="quoted-message">
|
||||
{displayQuotedSenderName && <span className="quoted-sender">{displayQuotedSenderName}</span>}
|
||||
<span className="quoted-text">{contentNode}</span>
|
||||
</div>
|
||||
), [displayQuotedSenderName])
|
||||
|
||||
const handlePlayVideo = useCallback(async () => {
|
||||
if (!videoInfo?.videoUrl) return
|
||||
@@ -8659,7 +9034,6 @@ function MessageBubble({
|
||||
if (xmlType === '57') {
|
||||
const replyText = q('title') || cleanedParsedContent || ''
|
||||
const referContent = q('refermsg > content') || ''
|
||||
const referSender = q('refermsg > displayname') || ''
|
||||
const referType = q('refermsg > type') || ''
|
||||
|
||||
// 根据被引用消息类型渲染对应内容
|
||||
@@ -8689,13 +9063,10 @@ function MessageBubble({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bubble-content">
|
||||
<div className="quoted-message">
|
||||
{referSender && <span className="quoted-sender">{referSender}</span>}
|
||||
<span className="quoted-text">{renderReferContent()}</span>
|
||||
</div>
|
||||
renderBubbleWithQuote(
|
||||
renderQuotedMessageBlock(renderReferContent()),
|
||||
<div className="message-text">{renderTextWithEmoji(cleanMessageContent(replyText))}</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8787,15 +9158,11 @@ function MessageBubble({
|
||||
// 引用回复消息(appMsgKind='quote',xmlType=57)
|
||||
const replyText = message.linkTitle || q('title') || cleanedParsedContent || ''
|
||||
const referContent = message.quotedContent || q('refermsg > content') || ''
|
||||
const referSender = message.quotedSender || q('refermsg > displayname') || ''
|
||||
return (
|
||||
<div className="bubble-content">
|
||||
<div className="quoted-message">
|
||||
{referSender && <span className="quoted-sender">{referSender}</span>}
|
||||
<span className="quoted-text">{renderTextWithEmoji(cleanMessageContent(referContent))}</span>
|
||||
</div>
|
||||
renderBubbleWithQuote(
|
||||
renderQuotedMessageBlock(renderTextWithEmoji(cleanMessageContent(referContent))),
|
||||
<div className="message-text">{renderTextWithEmoji(cleanMessageContent(replyText))}</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8982,7 +9349,6 @@ function MessageBubble({
|
||||
if (appMsgType === '57') {
|
||||
const replyText = parsedDoc?.querySelector('title')?.textContent?.trim() || cleanedParsedContent || ''
|
||||
const referContent = parsedDoc?.querySelector('refermsg > content')?.textContent?.trim() || ''
|
||||
const referSender = parsedDoc?.querySelector('refermsg > displayname')?.textContent?.trim() || ''
|
||||
const referType = parsedDoc?.querySelector('refermsg > type')?.textContent?.trim() || ''
|
||||
|
||||
const renderReferContent2 = () => {
|
||||
@@ -9006,13 +9372,10 @@ function MessageBubble({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bubble-content">
|
||||
<div className="quoted-message">
|
||||
{referSender && <span className="quoted-sender">{referSender}</span>}
|
||||
<span className="quoted-text">{renderReferContent2()}</span>
|
||||
</div>
|
||||
renderBubbleWithQuote(
|
||||
renderQuotedMessageBlock(renderReferContent2()),
|
||||
<div className="message-text">{renderTextWithEmoji(cleanMessageContent(replyText))}</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9291,14 +9654,9 @@ function MessageBubble({
|
||||
|
||||
// 带引用的消息
|
||||
if (hasQuote) {
|
||||
return (
|
||||
<div className="bubble-content">
|
||||
<div className="quoted-message">
|
||||
{message.quotedSender && <span className="quoted-sender">{message.quotedSender}</span>}
|
||||
<span className="quoted-text">{renderTextWithEmoji(cleanMessageContent(message.quotedContent || ''))}</span>
|
||||
</div>
|
||||
<div className="message-text">{renderTextWithEmoji(cleanedParsedContent)}</div>
|
||||
</div>
|
||||
return renderBubbleWithQuote(
|
||||
renderQuotedMessageBlock(renderTextWithEmoji(cleanMessageContent(quotedContent))),
|
||||
<div className="message-text">{renderTextWithEmoji(cleanedParsedContent)}</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9388,6 +9746,31 @@ function MessageBubble({
|
||||
{isSelected && <Check size={14} strokeWidth={3} />}
|
||||
</div>
|
||||
)}
|
||||
{systemAlert && createPortal(
|
||||
<div className="modal-overlay" onClick={() => setSystemAlert(null)} style={{ zIndex: 99999 }}>
|
||||
<div className="delete-confirm-card" onClick={(e) => e.stopPropagation()} style={{ maxWidth: '400px' }}>
|
||||
<div className="confirm-icon">
|
||||
<AlertCircle size={32} color="var(--danger)" />
|
||||
</div>
|
||||
<div className="confirm-content">
|
||||
<h3>{systemAlert.title}</h3>
|
||||
<p style={{ marginTop: '12px', lineHeight: '1.6', fontSize: '14px', color: 'var(--text-secondary)' }}>
|
||||
{systemAlert.message}
|
||||
</p>
|
||||
</div>
|
||||
<div className="confirm-actions" style={{ justifyContent: 'center', marginTop: '24px' }}>
|
||||
<button
|
||||
className="btn-primary"
|
||||
onClick={() => setSystemAlert(null)}
|
||||
style={{ padding: '8px 32px' }}
|
||||
>
|
||||
确认
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
@@ -9398,6 +9781,7 @@ const MemoMessageBubble = React.memo(MessageBubble, (prevProps, nextProps) => {
|
||||
if (prevProps.messageKey !== nextProps.messageKey) return false
|
||||
if (prevProps.showTime !== nextProps.showTime) return false
|
||||
if (prevProps.myAvatarUrl !== nextProps.myAvatarUrl) return false
|
||||
if (prevProps.myWxid !== nextProps.myWxid) return false
|
||||
if (prevProps.isGroupChat !== nextProps.isGroupChat) return false
|
||||
if (prevProps.autoTranscribeVoiceEnabled !== nextProps.autoTranscribeVoiceEnabled) return false
|
||||
if (prevProps.isSelectionMode !== nextProps.isSelectionMode) return false
|
||||
|
||||
@@ -49,13 +49,17 @@ import { SnsPostItem } from '../components/Sns/SnsPostItem'
|
||||
import { ContactSnsTimelineDialog } from '../components/Sns/ContactSnsTimelineDialog'
|
||||
import { ExportDateRangeDialog } from '../components/Export/ExportDateRangeDialog'
|
||||
import { ExportDefaultsSettingsForm, type ExportDefaultsSettingsPatch } from '../components/Export/ExportDefaultsSettingsForm'
|
||||
import { Avatar } from '../components/Avatar'
|
||||
import type { SnsPost } from '../types/sns'
|
||||
import {
|
||||
cloneExportDateRange,
|
||||
cloneExportDateRangeSelection,
|
||||
createDefaultDateRange,
|
||||
createDefaultExportDateRangeSelection,
|
||||
getExportDateRangeLabel,
|
||||
resolveExportDateRangeConfig,
|
||||
startOfDay,
|
||||
endOfDay,
|
||||
type ExportDateRangeSelection
|
||||
} from '../utils/exportDateRange'
|
||||
import './ExportPage.scss'
|
||||
@@ -89,6 +93,7 @@ interface ExportOptions {
|
||||
txtColumns: string[]
|
||||
displayNamePreference: DisplayNamePreference
|
||||
exportConcurrency: number
|
||||
imageDeepSearchOnMiss: boolean
|
||||
}
|
||||
|
||||
interface SessionRow extends AppChatSession {
|
||||
@@ -534,6 +539,14 @@ const getAvatarLetter = (name: string): string => {
|
||||
return [...name][0] || '?'
|
||||
}
|
||||
|
||||
const normalizeExportAvatarUrl = (value?: string | null): string | undefined => {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) return undefined
|
||||
const lower = normalized.toLowerCase()
|
||||
if (lower === 'null' || lower === 'undefined') return undefined
|
||||
return normalized
|
||||
}
|
||||
|
||||
const toComparableNameSet = (values: Array<string | undefined | null>): Set<string> => {
|
||||
const set = new Set<string>()
|
||||
for (const value of values) {
|
||||
@@ -830,6 +843,13 @@ interface SessionContentMetric {
|
||||
transferMessages?: number
|
||||
redPacketMessages?: number
|
||||
callMessages?: number
|
||||
firstTimestamp?: number
|
||||
lastTimestamp?: number
|
||||
}
|
||||
|
||||
interface TimeRangeBounds {
|
||||
minDate: Date
|
||||
maxDate: Date
|
||||
}
|
||||
|
||||
interface SessionExportCacheMeta {
|
||||
@@ -1016,7 +1036,7 @@ const toSessionRowsWithContacts = (
|
||||
kind: toKindByContact(contact),
|
||||
wechatId: contact.username,
|
||||
displayName: contact.displayName || session?.displayName || contact.username,
|
||||
avatarUrl: contact.avatarUrl || session?.avatarUrl,
|
||||
avatarUrl: session?.avatarUrl || contact.avatarUrl,
|
||||
hasSession: Boolean(session)
|
||||
} as SessionRow
|
||||
})
|
||||
@@ -1036,7 +1056,7 @@ const toSessionRowsWithContacts = (
|
||||
kind: toKindByContactType(session, contact),
|
||||
wechatId: contact?.username || session.username,
|
||||
displayName: contact?.displayName || session.displayName || session.username,
|
||||
avatarUrl: contact?.avatarUrl || session.avatarUrl,
|
||||
avatarUrl: session.avatarUrl || contact?.avatarUrl,
|
||||
hasSession: true
|
||||
} as SessionRow
|
||||
})
|
||||
@@ -1049,27 +1069,74 @@ const normalizeMessageCount = (value: unknown): number | undefined => {
|
||||
return Math.floor(parsed)
|
||||
}
|
||||
|
||||
const normalizeTimestampSeconds = (value: unknown): number | undefined => {
|
||||
const parsed = Number(value)
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) return undefined
|
||||
return Math.floor(parsed)
|
||||
}
|
||||
|
||||
const clampExportSelectionToBounds = (
|
||||
selection: ExportDateRangeSelection,
|
||||
bounds: TimeRangeBounds | null
|
||||
): ExportDateRangeSelection => {
|
||||
if (!bounds) return cloneExportDateRangeSelection(selection)
|
||||
|
||||
const boundedStart = startOfDay(bounds.minDate)
|
||||
const boundedEnd = endOfDay(bounds.maxDate)
|
||||
const originalStart = selection.useAllTime ? boundedStart : startOfDay(selection.dateRange.start)
|
||||
const originalEnd = selection.useAllTime ? boundedEnd : endOfDay(selection.dateRange.end)
|
||||
const nextStart = new Date(Math.min(Math.max(originalStart.getTime(), boundedStart.getTime()), boundedEnd.getTime()))
|
||||
const nextEndCandidate = new Date(Math.min(Math.max(originalEnd.getTime(), boundedStart.getTime()), boundedEnd.getTime()))
|
||||
const nextEnd = nextEndCandidate.getTime() < nextStart.getTime() ? endOfDay(nextStart) : nextEndCandidate
|
||||
const rangeChanged = nextStart.getTime() !== originalStart.getTime() || nextEnd.getTime() !== originalEnd.getTime()
|
||||
|
||||
return {
|
||||
preset: selection.useAllTime ? selection.preset : (rangeChanged ? 'custom' : selection.preset),
|
||||
useAllTime: selection.useAllTime,
|
||||
dateRange: {
|
||||
start: nextStart,
|
||||
end: nextEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const areExportSelectionsEqual = (left: ExportDateRangeSelection, right: ExportDateRangeSelection): boolean => (
|
||||
left.preset === right.preset &&
|
||||
left.useAllTime === right.useAllTime &&
|
||||
left.dateRange.start.getTime() === right.dateRange.start.getTime() &&
|
||||
left.dateRange.end.getTime() === right.dateRange.end.getTime()
|
||||
)
|
||||
|
||||
const pickSessionMediaMetric = (
|
||||
metricRaw: SessionExportMetric | SessionContentMetric | undefined
|
||||
): SessionContentMetric | null => {
|
||||
if (!metricRaw) return null
|
||||
const totalMessages = normalizeMessageCount(metricRaw.totalMessages)
|
||||
const voiceMessages = normalizeMessageCount(metricRaw.voiceMessages)
|
||||
const imageMessages = normalizeMessageCount(metricRaw.imageMessages)
|
||||
const videoMessages = normalizeMessageCount(metricRaw.videoMessages)
|
||||
const emojiMessages = normalizeMessageCount(metricRaw.emojiMessages)
|
||||
const firstTimestamp = normalizeTimestampSeconds(metricRaw.firstTimestamp)
|
||||
const lastTimestamp = normalizeTimestampSeconds(metricRaw.lastTimestamp)
|
||||
if (
|
||||
typeof totalMessages !== 'number' &&
|
||||
typeof voiceMessages !== 'number' &&
|
||||
typeof imageMessages !== 'number' &&
|
||||
typeof videoMessages !== 'number' &&
|
||||
typeof emojiMessages !== 'number'
|
||||
typeof emojiMessages !== 'number' &&
|
||||
typeof firstTimestamp !== 'number' &&
|
||||
typeof lastTimestamp !== 'number'
|
||||
) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
totalMessages,
|
||||
voiceMessages,
|
||||
imageMessages,
|
||||
videoMessages,
|
||||
emojiMessages
|
||||
emojiMessages,
|
||||
firstTimestamp,
|
||||
lastTimestamp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1520,6 +1587,8 @@ function ExportPage() {
|
||||
const [snsExportLivePhotos, setSnsExportLivePhotos] = useState(false)
|
||||
const [snsExportVideos, setSnsExportVideos] = useState(false)
|
||||
const [isTimeRangeDialogOpen, setIsTimeRangeDialogOpen] = useState(false)
|
||||
const [isResolvingTimeRangeBounds, setIsResolvingTimeRangeBounds] = useState(false)
|
||||
const [timeRangeBounds, setTimeRangeBounds] = useState<TimeRangeBounds | null>(null)
|
||||
const [isExportDefaultsModalOpen, setIsExportDefaultsModalOpen] = useState(false)
|
||||
const [timeRangeSelection, setTimeRangeSelection] = useState<ExportDateRangeSelection>(() => createDefaultExportDateRangeSelection())
|
||||
const [exportDefaultFormat, setExportDefaultFormat] = useState<TextExportFormat>('excel')
|
||||
@@ -1534,6 +1603,7 @@ function ExportPage() {
|
||||
const [exportDefaultVoiceAsText, setExportDefaultVoiceAsText] = useState(false)
|
||||
const [exportDefaultExcelCompactColumns, setExportDefaultExcelCompactColumns] = useState(true)
|
||||
const [exportDefaultConcurrency, setExportDefaultConcurrency] = useState(2)
|
||||
const [exportDefaultImageDeepSearchOnMiss, setExportDefaultImageDeepSearchOnMiss] = useState(true)
|
||||
|
||||
const [options, setOptions] = useState<ExportOptions>({
|
||||
format: 'json',
|
||||
@@ -1552,7 +1622,8 @@ function ExportPage() {
|
||||
excelCompactColumns: true,
|
||||
txtColumns: defaultTxtColumns,
|
||||
displayNamePreference: 'remark',
|
||||
exportConcurrency: 2
|
||||
exportConcurrency: 2,
|
||||
imageDeepSearchOnMiss: true
|
||||
})
|
||||
|
||||
const [exportDialog, setExportDialog] = useState<ExportDialogState>({
|
||||
@@ -1651,6 +1722,7 @@ function ExportPage() {
|
||||
startIndex: 0,
|
||||
endIndex: -1
|
||||
})
|
||||
const avatarHydrationRequestedRef = useRef<Set<string>>(new Set())
|
||||
const sessionMutualFriendsMetricsRef = useRef<Record<string, SessionMutualFriendsMetric>>({})
|
||||
const sessionMutualFriendsDirectMetricsRef = useRef<Record<string, SessionMutualFriendsMetric>>({})
|
||||
const sessionMutualFriendsQueueRef = useRef<string[]>([])
|
||||
@@ -1895,6 +1967,7 @@ function ExportPage() {
|
||||
displayName: contact.displayName,
|
||||
remark: contact.remark,
|
||||
nickname: contact.nickname,
|
||||
alias: contact.alias,
|
||||
type: contact.type
|
||||
}))
|
||||
).catch((error) => {
|
||||
@@ -1936,6 +2009,94 @@ function ExportPage() {
|
||||
}
|
||||
}, [ensureExportCacheScope, syncContactTypeCounts])
|
||||
|
||||
const hydrateVisibleContactAvatars = useCallback(async (usernames: string[]) => {
|
||||
const targets = Array.from(new Set(
|
||||
(usernames || [])
|
||||
.map((username) => String(username || '').trim())
|
||||
.filter(Boolean)
|
||||
)).filter((username) => {
|
||||
if (avatarHydrationRequestedRef.current.has(username)) return false
|
||||
const contact = contactsList.find((item) => item.username === username)
|
||||
const session = sessions.find((item) => item.username === username)
|
||||
const existingAvatarUrl = normalizeExportAvatarUrl(contact?.avatarUrl || session?.avatarUrl)
|
||||
return !existingAvatarUrl
|
||||
})
|
||||
|
||||
if (targets.length === 0) return
|
||||
targets.forEach((username) => avatarHydrationRequestedRef.current.add(username))
|
||||
|
||||
const settled = await Promise.allSettled(
|
||||
targets.map(async (username) => {
|
||||
const profile = await window.electronAPI.chat.getContactAvatar(username)
|
||||
return {
|
||||
username,
|
||||
avatarUrl: normalizeExportAvatarUrl(profile?.avatarUrl),
|
||||
displayName: profile?.displayName ? String(profile.displayName).trim() : undefined
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const avatarPatches = new Map<string, { avatarUrl?: string; displayName?: string }>()
|
||||
for (const item of settled) {
|
||||
if (item.status !== 'fulfilled') continue
|
||||
const { username, avatarUrl, displayName } = item.value
|
||||
if (!avatarUrl && !displayName) continue
|
||||
avatarPatches.set(username, { avatarUrl, displayName })
|
||||
}
|
||||
if (avatarPatches.size === 0) return
|
||||
|
||||
const now = Date.now()
|
||||
setContactsList((prev) => prev.map((contact) => {
|
||||
const patch = avatarPatches.get(contact.username)
|
||||
if (!patch) return contact
|
||||
return {
|
||||
...contact,
|
||||
displayName: patch.displayName || contact.displayName,
|
||||
avatarUrl: patch.avatarUrl || contact.avatarUrl
|
||||
}
|
||||
}))
|
||||
setSessions((prev) => prev.map((session) => {
|
||||
const patch = avatarPatches.get(session.username)
|
||||
if (!patch) return session
|
||||
return {
|
||||
...session,
|
||||
displayName: patch.displayName || session.displayName,
|
||||
avatarUrl: patch.avatarUrl || session.avatarUrl
|
||||
}
|
||||
}))
|
||||
setSessionDetail((prev) => {
|
||||
if (!prev) return prev
|
||||
const patch = avatarPatches.get(prev.wxid)
|
||||
if (!patch) return prev
|
||||
return {
|
||||
...prev,
|
||||
displayName: patch.displayName || prev.displayName,
|
||||
avatarUrl: patch.avatarUrl || prev.avatarUrl
|
||||
}
|
||||
})
|
||||
|
||||
let avatarCacheChanged = false
|
||||
for (const [username, patch] of avatarPatches.entries()) {
|
||||
if (!patch.avatarUrl) continue
|
||||
const previous = contactsAvatarCacheRef.current[username]
|
||||
if (previous?.avatarUrl === patch.avatarUrl) continue
|
||||
contactsAvatarCacheRef.current[username] = {
|
||||
avatarUrl: patch.avatarUrl,
|
||||
updatedAt: now,
|
||||
checkedAt: now
|
||||
}
|
||||
avatarCacheChanged = true
|
||||
}
|
||||
if (avatarCacheChanged) {
|
||||
setAvatarCacheUpdatedAt(now)
|
||||
const scopeKey = exportCacheScopeRef.current
|
||||
if (scopeKey) {
|
||||
void configService.setContactsAvatarCache(scopeKey, contactsAvatarCacheRef.current).catch(() => {})
|
||||
}
|
||||
}
|
||||
}, [contactsList, sessions])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!isExportRoute) return
|
||||
let cancelled = false
|
||||
@@ -2079,7 +2240,7 @@ function ExportPage() {
|
||||
setIsBaseConfigLoading(true)
|
||||
let isReady = true
|
||||
try {
|
||||
const [savedPath, savedFormat, savedAvatars, savedMedia, savedVoiceAsText, savedExcelCompactColumns, savedTxtColumns, savedConcurrency, savedSessionMap, savedContentMap, savedSessionRecordMap, savedSnsPostCount, savedWriteLayout, savedSessionNameWithTypePrefix, savedDefaultDateRange, exportCacheScope] = await Promise.all([
|
||||
const [savedPath, savedFormat, savedAvatars, savedMedia, savedVoiceAsText, savedExcelCompactColumns, savedTxtColumns, savedConcurrency, savedImageDeepSearchOnMiss, savedSessionMap, savedContentMap, savedSessionRecordMap, savedSnsPostCount, savedWriteLayout, savedSessionNameWithTypePrefix, savedDefaultDateRange, exportCacheScope] = await Promise.all([
|
||||
configService.getExportPath(),
|
||||
configService.getExportDefaultFormat(),
|
||||
configService.getExportDefaultAvatars(),
|
||||
@@ -2088,6 +2249,7 @@ function ExportPage() {
|
||||
configService.getExportDefaultExcelCompactColumns(),
|
||||
configService.getExportDefaultTxtColumns(),
|
||||
configService.getExportDefaultConcurrency(),
|
||||
configService.getExportDefaultImageDeepSearchOnMiss(),
|
||||
configService.getExportLastSessionRunMap(),
|
||||
configService.getExportLastContentRunMap(),
|
||||
configService.getExportSessionRecordMap(),
|
||||
@@ -2124,6 +2286,7 @@ function ExportPage() {
|
||||
setExportDefaultVoiceAsText(savedVoiceAsText ?? false)
|
||||
setExportDefaultExcelCompactColumns(savedExcelCompactColumns ?? true)
|
||||
setExportDefaultConcurrency(savedConcurrency ?? 2)
|
||||
setExportDefaultImageDeepSearchOnMiss(savedImageDeepSearchOnMiss ?? true)
|
||||
const resolvedDefaultDateRange = resolveExportDateRangeConfig(savedDefaultDateRange)
|
||||
setExportDefaultDateRangeSelection(resolvedDefaultDateRange)
|
||||
setTimeRangeSelection(resolvedDefaultDateRange)
|
||||
@@ -2156,7 +2319,8 @@ function ExportPage() {
|
||||
exportVoiceAsText: savedVoiceAsText ?? prev.exportVoiceAsText,
|
||||
excelCompactColumns: savedExcelCompactColumns ?? prev.excelCompactColumns,
|
||||
txtColumns,
|
||||
exportConcurrency: savedConcurrency ?? prev.exportConcurrency
|
||||
exportConcurrency: savedConcurrency ?? prev.exportConcurrency,
|
||||
imageDeepSearchOnMiss: savedImageDeepSearchOnMiss ?? prev.imageDeepSearchOnMiss
|
||||
}))
|
||||
} catch (error) {
|
||||
isReady = false
|
||||
@@ -2686,7 +2850,9 @@ function ExportPage() {
|
||||
typeof emojiMessages !== 'number' &&
|
||||
typeof transferMessages !== 'number' &&
|
||||
typeof redPacketMessages !== 'number' &&
|
||||
typeof callMessages !== 'number'
|
||||
typeof callMessages !== 'number' &&
|
||||
typeof normalizeTimestampSeconds(metricRaw.firstTimestamp) !== 'number' &&
|
||||
typeof normalizeTimestampSeconds(metricRaw.lastTimestamp) !== 'number'
|
||||
) {
|
||||
continue
|
||||
}
|
||||
@@ -2699,7 +2865,9 @@ function ExportPage() {
|
||||
emojiMessages,
|
||||
transferMessages,
|
||||
redPacketMessages,
|
||||
callMessages
|
||||
callMessages,
|
||||
firstTimestamp: normalizeTimestampSeconds(metricRaw.firstTimestamp),
|
||||
lastTimestamp: normalizeTimestampSeconds(metricRaw.lastTimestamp)
|
||||
}
|
||||
if (typeof totalMessages === 'number') {
|
||||
nextMessageCounts[sessionId] = totalMessages
|
||||
@@ -2733,7 +2901,9 @@ function ExportPage() {
|
||||
emojiMessages: typeof metric.emojiMessages === 'number' ? metric.emojiMessages : previous.emojiMessages,
|
||||
transferMessages: typeof metric.transferMessages === 'number' ? metric.transferMessages : previous.transferMessages,
|
||||
redPacketMessages: typeof metric.redPacketMessages === 'number' ? metric.redPacketMessages : previous.redPacketMessages,
|
||||
callMessages: typeof metric.callMessages === 'number' ? metric.callMessages : previous.callMessages
|
||||
callMessages: typeof metric.callMessages === 'number' ? metric.callMessages : previous.callMessages,
|
||||
firstTimestamp: typeof metric.firstTimestamp === 'number' ? metric.firstTimestamp : previous.firstTimestamp,
|
||||
lastTimestamp: typeof metric.lastTimestamp === 'number' ? metric.lastTimestamp : previous.lastTimestamp
|
||||
}
|
||||
if (
|
||||
previous.totalMessages === nextMetric.totalMessages &&
|
||||
@@ -2743,7 +2913,9 @@ function ExportPage() {
|
||||
previous.emojiMessages === nextMetric.emojiMessages &&
|
||||
previous.transferMessages === nextMetric.transferMessages &&
|
||||
previous.redPacketMessages === nextMetric.redPacketMessages &&
|
||||
previous.callMessages === nextMetric.callMessages
|
||||
previous.callMessages === nextMetric.callMessages &&
|
||||
previous.firstTimestamp === nextMetric.firstTimestamp &&
|
||||
previous.lastTimestamp === nextMetric.lastTimestamp
|
||||
) {
|
||||
continue
|
||||
}
|
||||
@@ -3751,10 +3923,12 @@ function ExportPage() {
|
||||
displayName: contact.displayName || contact.username,
|
||||
remark: contact.remark,
|
||||
nickname: contact.nickname,
|
||||
alias: contact.alias,
|
||||
type: contact.type
|
||||
}))
|
||||
|
||||
const persistAt = Date.now()
|
||||
setContactsList(contactsForPersist)
|
||||
setSessions(nextSessions)
|
||||
sessionsHydratedAtRef.current = persistAt
|
||||
if (hasNetworkContactsSnapshot && contactsCachePayload.length > 0) {
|
||||
@@ -3898,6 +4072,7 @@ function ExportPage() {
|
||||
const openExportDialog = useCallback((payload: Omit<ExportDialogState, 'open'>) => {
|
||||
setExportDialog({ open: true, ...payload })
|
||||
setIsTimeRangeDialogOpen(false)
|
||||
setTimeRangeBounds(null)
|
||||
setTimeRangeSelection(exportDefaultDateRangeSelection)
|
||||
|
||||
setOptions(prev => {
|
||||
@@ -3921,7 +4096,8 @@ function ExportPage() {
|
||||
exportEmojis: exportDefaultMedia.emojis,
|
||||
exportVoiceAsText: exportDefaultVoiceAsText,
|
||||
excelCompactColumns: exportDefaultExcelCompactColumns,
|
||||
exportConcurrency: exportDefaultConcurrency
|
||||
exportConcurrency: exportDefaultConcurrency,
|
||||
imageDeepSearchOnMiss: exportDefaultImageDeepSearchOnMiss
|
||||
}
|
||||
|
||||
if (payload.scope === 'sns') {
|
||||
@@ -3954,17 +4130,150 @@ function ExportPage() {
|
||||
exportDefaultAvatars,
|
||||
exportDefaultMedia,
|
||||
exportDefaultVoiceAsText,
|
||||
exportDefaultConcurrency
|
||||
exportDefaultConcurrency,
|
||||
exportDefaultImageDeepSearchOnMiss
|
||||
])
|
||||
|
||||
const closeExportDialog = useCallback(() => {
|
||||
setExportDialog(prev => ({ ...prev, open: false }))
|
||||
setIsTimeRangeDialogOpen(false)
|
||||
setTimeRangeBounds(null)
|
||||
}, [])
|
||||
|
||||
const resolveChatExportTimeRangeBounds = useCallback(async (sessionIds: string[]): Promise<TimeRangeBounds | null> => {
|
||||
const normalizedSessionIds = Array.from(new Set((sessionIds || []).map(id => String(id || '').trim()).filter(Boolean)))
|
||||
if (normalizedSessionIds.length === 0) return null
|
||||
|
||||
const sessionRowMap = new Map<string, SessionRow>()
|
||||
for (const session of sessions) {
|
||||
sessionRowMap.set(session.username, session)
|
||||
}
|
||||
|
||||
let minTimestamp: number | undefined
|
||||
let maxTimestamp: number | undefined
|
||||
const resolvedSessionBounds = new Map<string, { hasMin: boolean; hasMax: boolean }>()
|
||||
|
||||
const absorbMetric = (sessionId: string, metric?: { firstTimestamp?: number; lastTimestamp?: number } | null) => {
|
||||
if (!metric) return
|
||||
const firstTimestamp = normalizeTimestampSeconds(metric.firstTimestamp)
|
||||
const lastTimestamp = normalizeTimestampSeconds(metric.lastTimestamp)
|
||||
if (typeof firstTimestamp !== 'number' && typeof lastTimestamp !== 'number') return
|
||||
|
||||
const previous = resolvedSessionBounds.get(sessionId) || { hasMin: false, hasMax: false }
|
||||
const nextState = {
|
||||
hasMin: previous.hasMin || typeof firstTimestamp === 'number',
|
||||
hasMax: previous.hasMax || typeof lastTimestamp === 'number'
|
||||
}
|
||||
resolvedSessionBounds.set(sessionId, nextState)
|
||||
|
||||
if (typeof firstTimestamp === 'number' && (minTimestamp === undefined || firstTimestamp < minTimestamp)) {
|
||||
minTimestamp = firstTimestamp
|
||||
}
|
||||
if (typeof lastTimestamp === 'number' && (maxTimestamp === undefined || lastTimestamp > maxTimestamp)) {
|
||||
maxTimestamp = lastTimestamp
|
||||
}
|
||||
}
|
||||
|
||||
for (const sessionId of normalizedSessionIds) {
|
||||
const sessionRow = sessionRowMap.get(sessionId)
|
||||
absorbMetric(sessionId, {
|
||||
firstTimestamp: undefined,
|
||||
lastTimestamp: sessionRow?.sortTimestamp || sessionRow?.lastTimestamp
|
||||
})
|
||||
absorbMetric(sessionId, sessionContentMetrics[sessionId])
|
||||
if (sessionDetail?.wxid === sessionId) {
|
||||
absorbMetric(sessionId, {
|
||||
firstTimestamp: sessionDetail.firstMessageTime,
|
||||
lastTimestamp: sessionDetail.latestMessageTime
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const applyStatsResult = (result?: {
|
||||
success: boolean
|
||||
data?: Record<string, SessionExportMetric>
|
||||
} | null) => {
|
||||
if (!result?.success || !result.data) return
|
||||
applySessionMediaMetricsFromStats(result.data)
|
||||
for (const sessionId of normalizedSessionIds) {
|
||||
absorbMetric(sessionId, result.data[sessionId])
|
||||
}
|
||||
}
|
||||
|
||||
const missingSessionIds = () => normalizedSessionIds.filter(sessionId => {
|
||||
const resolved = resolvedSessionBounds.get(sessionId)
|
||||
return !resolved?.hasMin || !resolved?.hasMax
|
||||
})
|
||||
|
||||
const staleSessionIds = new Set<string>()
|
||||
|
||||
if (missingSessionIds().length > 0) {
|
||||
const cacheResult = await window.electronAPI.chat.getExportSessionStats(
|
||||
missingSessionIds(),
|
||||
{ includeRelations: false, allowStaleCache: true, cacheOnly: true }
|
||||
)
|
||||
applyStatsResult(cacheResult)
|
||||
for (const sessionId of cacheResult?.needsRefresh || []) {
|
||||
staleSessionIds.add(String(sessionId || '').trim())
|
||||
}
|
||||
}
|
||||
|
||||
const sessionsNeedingFreshStats = Array.from(new Set([
|
||||
...missingSessionIds(),
|
||||
...Array.from(staleSessionIds).filter(Boolean)
|
||||
]))
|
||||
|
||||
if (sessionsNeedingFreshStats.length > 0) {
|
||||
applyStatsResult(await window.electronAPI.chat.getExportSessionStats(
|
||||
sessionsNeedingFreshStats,
|
||||
{ includeRelations: false }
|
||||
))
|
||||
}
|
||||
|
||||
if (missingSessionIds().length > 0) {
|
||||
return null
|
||||
}
|
||||
if (typeof minTimestamp !== 'number' || typeof maxTimestamp !== 'number') {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
minDate: new Date(minTimestamp * 1000),
|
||||
maxDate: new Date(maxTimestamp * 1000)
|
||||
}
|
||||
}, [applySessionMediaMetricsFromStats, sessionContentMetrics, sessionDetail, sessions])
|
||||
|
||||
const openTimeRangeDialog = useCallback(() => {
|
||||
setIsTimeRangeDialogOpen(true)
|
||||
}, [])
|
||||
void (async () => {
|
||||
if (isResolvingTimeRangeBounds) return
|
||||
setIsResolvingTimeRangeBounds(true)
|
||||
try {
|
||||
let nextBounds: TimeRangeBounds | null = null
|
||||
if (exportDialog.scope !== 'sns') {
|
||||
nextBounds = await resolveChatExportTimeRangeBounds(exportDialog.sessionIds)
|
||||
}
|
||||
setTimeRangeBounds(nextBounds)
|
||||
if (nextBounds) {
|
||||
const nextSelection = clampExportSelectionToBounds(timeRangeSelection, nextBounds)
|
||||
if (!areExportSelectionsEqual(nextSelection, timeRangeSelection)) {
|
||||
setTimeRangeSelection(nextSelection)
|
||||
setOptions(prev => ({
|
||||
...prev,
|
||||
useAllTime: nextSelection.useAllTime,
|
||||
dateRange: cloneExportDateRange(nextSelection.dateRange)
|
||||
}))
|
||||
}
|
||||
}
|
||||
setIsTimeRangeDialogOpen(true)
|
||||
} catch (error) {
|
||||
console.error('导出页解析时间范围边界失败', error)
|
||||
setTimeRangeBounds(null)
|
||||
setIsTimeRangeDialogOpen(true)
|
||||
} finally {
|
||||
setIsResolvingTimeRangeBounds(false)
|
||||
}
|
||||
})()
|
||||
}, [exportDialog.scope, exportDialog.sessionIds, isResolvingTimeRangeBounds, resolveChatExportTimeRangeBounds, timeRangeSelection])
|
||||
|
||||
const closeTimeRangeDialog = useCallback(() => {
|
||||
setIsTimeRangeDialogOpen(false)
|
||||
@@ -4041,6 +4350,7 @@ function ExportPage() {
|
||||
txtColumns: options.txtColumns,
|
||||
displayNamePreference: options.displayNamePreference,
|
||||
exportConcurrency: options.exportConcurrency,
|
||||
imageDeepSearchOnMiss: options.imageDeepSearchOnMiss,
|
||||
sessionLayout,
|
||||
sessionNameWithTypePrefix,
|
||||
dateRange: options.useAllTime
|
||||
@@ -4633,6 +4943,8 @@ function ExportPage() {
|
||||
await configService.setExportDefaultExcelCompactColumns(options.excelCompactColumns)
|
||||
await configService.setExportDefaultTxtColumns(options.txtColumns)
|
||||
await configService.setExportDefaultConcurrency(options.exportConcurrency)
|
||||
await configService.setExportDefaultImageDeepSearchOnMiss(options.imageDeepSearchOnMiss)
|
||||
setExportDefaultImageDeepSearchOnMiss(options.imageDeepSearchOnMiss)
|
||||
}
|
||||
|
||||
const openSingleExport = useCallback((session: SessionRow) => {
|
||||
@@ -5169,6 +5481,11 @@ function ExportPage() {
|
||||
const endIndex = Number.isFinite(range?.endIndex) ? Math.max(startIndex, Math.floor(range.endIndex)) : startIndex
|
||||
sessionMediaMetricVisibleRangeRef.current = { startIndex, endIndex }
|
||||
sessionMutualFriendsVisibleRangeRef.current = { startIndex, endIndex }
|
||||
void hydrateVisibleContactAvatars(
|
||||
filteredContacts
|
||||
.slice(startIndex, endIndex + 1)
|
||||
.map((contact) => contact.username)
|
||||
)
|
||||
const visibleTargets = collectVisibleSessionMetricTargets(filteredContacts)
|
||||
if (visibleTargets.length === 0) return
|
||||
enqueueSessionMediaMetricRequests(visibleTargets, { front: true })
|
||||
@@ -5184,10 +5501,23 @@ function ExportPage() {
|
||||
enqueueSessionMediaMetricRequests,
|
||||
enqueueSessionMutualFriendsRequests,
|
||||
filteredContacts,
|
||||
hydrateVisibleContactAvatars,
|
||||
scheduleSessionMediaMetricWorker,
|
||||
scheduleSessionMutualFriendsWorker
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (filteredContacts.length === 0) return
|
||||
const bootstrapTargets = filteredContacts.slice(0, 24).map((contact) => contact.username)
|
||||
void hydrateVisibleContactAvatars(bootstrapTargets)
|
||||
}, [filteredContacts, hydrateVisibleContactAvatars])
|
||||
|
||||
useEffect(() => {
|
||||
const sessionId = String(sessionDetail?.wxid || '').trim()
|
||||
if (!sessionId) return
|
||||
void hydrateVisibleContactAvatars([sessionId])
|
||||
}, [hydrateVisibleContactAvatars, sessionDetail?.wxid])
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTaskCount > 0) return
|
||||
if (filteredContacts.length === 0) return
|
||||
@@ -5382,6 +5712,45 @@ function ExportPage() {
|
||||
return map
|
||||
}, [contactsList])
|
||||
|
||||
useEffect(() => {
|
||||
if (!showSessionDetailPanel) return
|
||||
const sessionId = String(sessionDetail?.wxid || '').trim()
|
||||
if (!sessionId) return
|
||||
|
||||
const mappedSession = sessionRowByUsername.get(sessionId)
|
||||
const mappedContact = contactByUsername.get(sessionId)
|
||||
if (!mappedSession && !mappedContact) return
|
||||
|
||||
setSessionDetail((prev) => {
|
||||
if (!prev || prev.wxid !== sessionId) return prev
|
||||
|
||||
const nextDisplayName = mappedSession?.displayName || mappedContact?.displayName || prev.displayName || sessionId
|
||||
const nextRemark = mappedContact?.remark ?? prev.remark
|
||||
const nextNickName = mappedContact?.nickname ?? prev.nickName
|
||||
const nextAlias = mappedContact?.alias ?? prev.alias
|
||||
const nextAvatarUrl = mappedSession?.avatarUrl || mappedContact?.avatarUrl || prev.avatarUrl
|
||||
|
||||
if (
|
||||
nextDisplayName === prev.displayName &&
|
||||
nextRemark === prev.remark &&
|
||||
nextNickName === prev.nickName &&
|
||||
nextAlias === prev.alias &&
|
||||
nextAvatarUrl === prev.avatarUrl
|
||||
) {
|
||||
return prev
|
||||
}
|
||||
|
||||
return {
|
||||
...prev,
|
||||
displayName: nextDisplayName,
|
||||
remark: nextRemark,
|
||||
nickName: nextNickName,
|
||||
alias: nextAlias,
|
||||
avatarUrl: nextAvatarUrl
|
||||
}
|
||||
})
|
||||
}, [contactByUsername, sessionDetail?.wxid, sessionRowByUsername, showSessionDetailPanel])
|
||||
|
||||
const currentSessionExportRecords = useMemo(() => {
|
||||
const sessionId = String(sessionDetail?.wxid || '').trim()
|
||||
if (!sessionId) return [] as configService.ExportSessionRecordEntry[]
|
||||
@@ -5500,7 +5869,7 @@ function ExportPage() {
|
||||
displayName: mappedSession?.displayName || mappedContact?.displayName || prev?.displayName || normalizedSessionId,
|
||||
remark: sameSession ? prev?.remark : mappedContact?.remark,
|
||||
nickName: sameSession ? prev?.nickName : mappedContact?.nickname,
|
||||
alias: sameSession ? prev?.alias : undefined,
|
||||
alias: sameSession ? prev?.alias : mappedContact?.alias,
|
||||
avatarUrl: mappedSession?.avatarUrl || mappedContact?.avatarUrl || (sameSession ? prev?.avatarUrl : undefined),
|
||||
messageCount: initialMessageCount ?? (sameSession ? prev.messageCount : Number.NaN),
|
||||
voiceMessages: metricVoice ?? (sameSession ? prev?.voiceMessages : undefined),
|
||||
@@ -5787,7 +6156,11 @@ function ExportPage() {
|
||||
loadSnsUserPostCounts({ force: true })
|
||||
])
|
||||
|
||||
if (String(sessionDetail?.wxid || '').trim()) {
|
||||
const currentDetailSessionId = showSessionDetailPanel
|
||||
? String(sessionDetail?.wxid || '').trim()
|
||||
: ''
|
||||
if (currentDetailSessionId) {
|
||||
await loadSessionDetail(currentDetailSessionId)
|
||||
void loadSessionRelationStats({ forceRefresh: true })
|
||||
}
|
||||
}, [
|
||||
@@ -5798,11 +6171,13 @@ function ExportPage() {
|
||||
filteredContacts,
|
||||
isSessionCountStageReady,
|
||||
loadContactsList,
|
||||
loadSessionDetail,
|
||||
loadSessionRelationStats,
|
||||
loadSnsStats,
|
||||
loadSnsUserPostCounts,
|
||||
resetSessionMutualFriendsLoader,
|
||||
scheduleSessionMutualFriendsWorker,
|
||||
showSessionDetailPanel,
|
||||
sessionDetail?.wxid
|
||||
])
|
||||
|
||||
@@ -6070,6 +6445,10 @@ function ExportPage() {
|
||||
const useCollapsedSessionFormatSelector = isSessionScopeDialog || isContentTextDialog
|
||||
const shouldShowFormatSection = !isContentScopeDialog || isContentTextDialog
|
||||
const shouldShowMediaSection = !isContentScopeDialog
|
||||
const shouldShowImageDeepSearchToggle = exportDialog.scope !== 'sns' && (
|
||||
(isSessionScopeDialog && options.exportImages) ||
|
||||
(isContentScopeDialog && exportDialog.contentType === 'image')
|
||||
)
|
||||
const avatarExportStatusLabel = options.exportAvatars ? '已开启聊天消息导出带头像' : '已关闭聊天消息导出带头像'
|
||||
const contentTextDialogSummary = '此模式只导出聊天文本,不包含图片语音视频表情包等多媒体文件。'
|
||||
const activeDialogFormatLabel = exportDialog.scope === 'sns'
|
||||
@@ -6367,11 +6746,12 @@ function ExportPage() {
|
||||
</button>
|
||||
</div>
|
||||
<div className="contact-avatar">
|
||||
{contact.avatarUrl ? (
|
||||
<img src={contact.avatarUrl} alt="" loading="lazy" />
|
||||
) : (
|
||||
<span>{getAvatarLetter(contact.displayName)}</span>
|
||||
)}
|
||||
<Avatar
|
||||
src={normalizeExportAvatarUrl(contact.avatarUrl)}
|
||||
name={contact.displayName}
|
||||
size="100%"
|
||||
shape="rounded"
|
||||
/>
|
||||
</div>
|
||||
<div className="contact-info">
|
||||
<div className="contact-name">{contact.displayName}</div>
|
||||
@@ -7254,11 +7634,12 @@ function ExportPage() {
|
||||
<div className="session-mutual-friends-header">
|
||||
<div className="session-mutual-friends-header-main">
|
||||
<div className="session-mutual-friends-avatar">
|
||||
{sessionMutualFriendsDialogTarget.avatarUrl ? (
|
||||
<img src={sessionMutualFriendsDialogTarget.avatarUrl} alt="" />
|
||||
) : (
|
||||
<span>{getAvatarLetter(sessionMutualFriendsDialogTarget.displayName)}</span>
|
||||
)}
|
||||
<Avatar
|
||||
src={normalizeExportAvatarUrl(sessionMutualFriendsDialogTarget.avatarUrl)}
|
||||
name={sessionMutualFriendsDialogTarget.displayName}
|
||||
size="100%"
|
||||
shape="rounded"
|
||||
/>
|
||||
</div>
|
||||
<div className="session-mutual-friends-meta">
|
||||
<h4>{sessionMutualFriendsDialogTarget.displayName} 的共同好友</h4>
|
||||
@@ -7339,11 +7720,12 @@ function ExportPage() {
|
||||
<div className="detail-header">
|
||||
<div className="detail-header-main">
|
||||
<div className="detail-header-avatar">
|
||||
{sessionDetail?.avatarUrl ? (
|
||||
<img src={sessionDetail.avatarUrl} alt="" />
|
||||
) : (
|
||||
<span>{getAvatarLetter(sessionDetail?.displayName || sessionDetail?.wxid || '')}</span>
|
||||
)}
|
||||
<Avatar
|
||||
src={normalizeExportAvatarUrl(sessionDetail?.avatarUrl)}
|
||||
name={sessionDetail?.displayName || sessionDetail?.wxid || ''}
|
||||
size="100%"
|
||||
shape="rounded"
|
||||
/>
|
||||
</div>
|
||||
<div className="detail-header-meta">
|
||||
<h4>{sessionDetail?.displayName || '会话详情'}</h4>
|
||||
@@ -7753,8 +8135,9 @@ function ExportPage() {
|
||||
type="button"
|
||||
className="time-range-trigger"
|
||||
onClick={openTimeRangeDialog}
|
||||
disabled={isResolvingTimeRangeBounds}
|
||||
>
|
||||
<span>{timeRangeSummaryLabel}</span>
|
||||
<span>{isResolvingTimeRangeBounds ? '正在统计可选时间...' : timeRangeSummaryLabel}</span>
|
||||
<span className="time-range-arrow">></span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -7785,6 +8168,26 @@ function ExportPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{shouldShowImageDeepSearchToggle && (
|
||||
<div className="dialog-section">
|
||||
<div className="dialog-switch-row">
|
||||
<div className="dialog-switch-copy">
|
||||
<h4>缺图时深度搜索</h4>
|
||||
<div className="format-note">关闭后仅尝试 hardlink 命中,未命中将直接显示占位符,导出速度更快。</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className={`dialog-switch ${options.imageDeepSearchOnMiss ? 'on' : ''}`}
|
||||
aria-pressed={options.imageDeepSearchOnMiss}
|
||||
aria-label="切换缺图时深度搜索"
|
||||
onClick={() => setOptions(prev => ({ ...prev, imageDeepSearchOnMiss: !prev.imageDeepSearchOnMiss }))}
|
||||
>
|
||||
<span className="dialog-switch-thumb" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isSessionScopeDialog && (
|
||||
<div className="dialog-section">
|
||||
<div className="dialog-switch-row">
|
||||
@@ -7840,6 +8243,8 @@ function ExportPage() {
|
||||
<ExportDateRangeDialog
|
||||
open={isTimeRangeDialogOpen}
|
||||
value={timeRangeSelection}
|
||||
minDate={timeRangeBounds?.minDate}
|
||||
maxDate={timeRangeBounds?.maxDate}
|
||||
onClose={closeTimeRangeDialog}
|
||||
onConfirm={(nextSelection) => {
|
||||
setTimeRangeSelection(nextSelection)
|
||||
|
||||
@@ -1145,6 +1145,134 @@
|
||||
}
|
||||
}
|
||||
|
||||
.quote-layout-picker {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.quote-layout-card {
|
||||
position: relative;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 16px;
|
||||
padding: 14px;
|
||||
background: var(--bg-primary);
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: color-mix(in srgb, var(--primary) 35%, var(--border-color));
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&.active {
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
|
||||
background: color-mix(in srgb, var(--bg-primary) 92%, var(--primary) 8%);
|
||||
}
|
||||
}
|
||||
|
||||
.quote-layout-card-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.quote-layout-card-title-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.quote-layout-card-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.quote-layout-card-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.quote-layout-card-check {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--border-color);
|
||||
color: transparent;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&.active {
|
||||
border-color: var(--primary);
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.quote-layout-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: color-mix(in srgb, var(--bg-secondary) 92%, var(--bg-primary));
|
||||
border: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
|
||||
min-height: 112px;
|
||||
|
||||
&.quote-bottom {
|
||||
.quote-layout-preview-message {
|
||||
order: 1;
|
||||
}
|
||||
|
||||
.quote-layout-preview-quote {
|
||||
order: 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.quote-layout-preview-quote {
|
||||
padding: 8px 10px;
|
||||
border-left: 2px solid var(--primary);
|
||||
border-radius: 8px;
|
||||
background: rgba(0, 0, 0, 0.04);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.quote-layout-preview-sender {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.quote-layout-preview-text {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.quote-layout-preview-message {
|
||||
align-self: flex-start;
|
||||
max-width: 88%;
|
||||
padding: 9px 12px;
|
||||
border-radius: 12px;
|
||||
background: color-mix(in srgb, var(--primary) 14%, var(--bg-primary));
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.theme-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
|
||||
|
||||
@@ -118,6 +118,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
const [notificationFilterMode, setNotificationFilterMode] = useState<'all' | 'whitelist' | 'blacklist'>('all')
|
||||
const [notificationFilterList, setNotificationFilterList] = useState<string[]>([])
|
||||
const [windowCloseBehavior, setWindowCloseBehavior] = useState<configService.WindowCloseBehavior>('ask')
|
||||
const [quoteLayout, setQuoteLayout] = useState<configService.QuoteLayout>('quote-top')
|
||||
const [filterSearchKeyword, setFilterSearchKeyword] = useState('')
|
||||
const [filterModeDropdownOpen, setFilterModeDropdownOpen] = useState(false)
|
||||
const [positionDropdownOpen, setPositionDropdownOpen] = useState(false)
|
||||
@@ -175,6 +176,21 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
|
||||
const isClearingCache = isClearingAnalyticsCache || isClearingImageCache || isClearingAllCache
|
||||
|
||||
const [isWayland, setIsWayland] = useState(false)
|
||||
useEffect(() => {
|
||||
const checkWaylandStatus = async () => {
|
||||
if (window.electronAPI?.app?.checkWayland) {
|
||||
try {
|
||||
const wayland = await window.electronAPI.app.checkWayland()
|
||||
setIsWayland(wayland)
|
||||
} catch (e) {
|
||||
console.error('检查 Wayland 状态失败:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
checkWaylandStatus()
|
||||
}, [])
|
||||
|
||||
// 检查 Hello 可用性
|
||||
useEffect(() => {
|
||||
if (window.PublicKeyCredential) {
|
||||
@@ -299,6 +315,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
const savedNotificationFilterList = await configService.getNotificationFilterList()
|
||||
const savedMessagePushEnabled = await configService.getMessagePushEnabled()
|
||||
const savedWindowCloseBehavior = await configService.getWindowCloseBehavior()
|
||||
const savedQuoteLayout = await configService.getQuoteLayout()
|
||||
|
||||
const savedAuthEnabled = await window.electronAPI.auth.verifyEnabled()
|
||||
const savedAuthUseHello = await configService.getAuthUseHello()
|
||||
@@ -336,6 +353,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
setNotificationFilterList(savedNotificationFilterList)
|
||||
setMessagePushEnabled(savedMessagePushEnabled)
|
||||
setWindowCloseBehavior(savedWindowCloseBehavior)
|
||||
setQuoteLayout(savedQuoteLayout)
|
||||
|
||||
const savedExcludeWords = await configService.getWordCloudExcludeWords()
|
||||
setWordCloudExcludeWords(savedExcludeWords)
|
||||
@@ -1043,6 +1061,77 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>引用样式</label>
|
||||
<span className="form-hint">选择聊天中引用消息与正文的上下顺序,右侧预览会同步展示布局差异。</span>
|
||||
<div className="quote-layout-picker" role="radiogroup" aria-label="引用样式选择">
|
||||
{[
|
||||
{
|
||||
value: 'quote-top' as const,
|
||||
label: '引用在上',
|
||||
description: '更接近当前 WeFlow 风格',
|
||||
successMessage: '已切换为引用在上样式'
|
||||
},
|
||||
{
|
||||
value: 'quote-bottom' as const,
|
||||
label: '正文在上',
|
||||
description: '更接近微信 / 密语风格',
|
||||
successMessage: '已切换为正文在上样式'
|
||||
}
|
||||
].map(option => {
|
||||
const selected = quoteLayout === option.value
|
||||
const quotePreview = (
|
||||
<div className="quote-layout-preview-quote">
|
||||
<span className="quote-layout-preview-sender">张三</span>
|
||||
<span className="quote-layout-preview-text">这是一条被引用的消息</span>
|
||||
</div>
|
||||
)
|
||||
const messagePreview = (
|
||||
<div className="quote-layout-preview-message">这是当前发送的回复内容</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
className={`quote-layout-card ${selected ? 'active' : ''}`}
|
||||
onClick={async () => {
|
||||
if (selected) return
|
||||
setQuoteLayout(option.value)
|
||||
await configService.setQuoteLayout(option.value)
|
||||
showMessage(option.successMessage, true)
|
||||
}}
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
>
|
||||
<div className="quote-layout-card-header">
|
||||
<div className="quote-layout-card-title-group">
|
||||
<span className="quote-layout-card-title">{option.label}</span>
|
||||
<span className="quote-layout-card-desc">{option.description}</span>
|
||||
</div>
|
||||
<span className={`quote-layout-card-check ${selected ? 'active' : ''}`}>
|
||||
<Check size={14} />
|
||||
</span>
|
||||
</div>
|
||||
<div className={`quote-layout-preview ${option.value}`}>
|
||||
{option.value === 'quote-bottom' ? (
|
||||
<>
|
||||
{messagePreview}
|
||||
{quotePreview}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{quotePreview}
|
||||
{messagePreview}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="divider" />
|
||||
|
||||
<div className="form-group">
|
||||
@@ -1169,6 +1258,11 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
<div className="form-group">
|
||||
<label>通知显示位置</label>
|
||||
<span className="form-hint">选择通知弹窗在屏幕上的显示位置</span>
|
||||
{isWayland && (
|
||||
<span className="form-hint" style={{ color: '#ff4d4f', marginTop: '4px', display: 'block' }}>
|
||||
⚠️ 注意:Wayland 环境下该配置可能无效!
|
||||
</span>
|
||||
)}
|
||||
<div className="custom-select">
|
||||
<div
|
||||
className={`custom-select-trigger ${positionDropdownOpen ? 'open' : ''}`}
|
||||
@@ -1652,34 +1746,49 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
)
|
||||
|
||||
const renderCacheTab = () => (
|
||||
<div className="tab-content">
|
||||
<p className="section-desc">管理应用缓存数据</p>
|
||||
<div className="form-group">
|
||||
<label>缓存目录 <span className="optional">(可选)</span></label>
|
||||
<span className="form-hint">留空使用默认目录</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="留空使用默认目录"
|
||||
value={cachePath}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value
|
||||
setCachePath(value)
|
||||
scheduleConfigSave('cachePath', () => configService.setCachePath(value))
|
||||
}}
|
||||
/>
|
||||
<div className="btn-row">
|
||||
<button className="btn btn-secondary" onClick={handleSelectCachePath}><FolderOpen size={16} /> 浏览选择</button>
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
onClick={async () => {
|
||||
setCachePath('')
|
||||
await configService.setCachePath('')
|
||||
}}
|
||||
>
|
||||
<RotateCcw size={16} /> 恢复默认
|
||||
</button>
|
||||
<div className="tab-content">
|
||||
<p className="section-desc">管理应用缓存数据</p>
|
||||
<div className="form-group">
|
||||
<label>缓存目录 <span className="optional">(可选)</span></label>
|
||||
<span className="form-hint">留空使用默认目录</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="留空使用默认目录"
|
||||
value={cachePath}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value
|
||||
setCachePath(value)
|
||||
scheduleConfigSave('cachePath', () => configService.setCachePath(value))
|
||||
}}
|
||||
/>
|
||||
|
||||
<div style={{ marginTop: '8px', fontSize: '13px', color: 'var(--text-secondary)' }}>
|
||||
当前缓存位置:
|
||||
<code style={{
|
||||
background: 'var(--bg-secondary)',
|
||||
padding: '3px 6px',
|
||||
borderRadius: '4px',
|
||||
userSelect: 'all',
|
||||
wordBreak: 'break-all',
|
||||
marginLeft: '4px'
|
||||
}}>
|
||||
{cachePath || (isMac ? '~/Documents/WeFlow' : isLinux ? '~/Documents/WeFlow' : '系统 文档\\WeFlow 目录')}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="btn-row" style={{ marginTop: '12px' }}>
|
||||
<button className="btn btn-secondary" onClick={handleSelectCachePath}><FolderOpen size={16} /> 浏览选择</button>
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
onClick={async () => {
|
||||
setCachePath('')
|
||||
await configService.setCachePath('')
|
||||
}}
|
||||
>
|
||||
<RotateCcw size={16} /> 恢复默认
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="btn-row">
|
||||
<button className="btn btn-secondary" onClick={handleClearAnalyticsCache} disabled={isClearingCache}>
|
||||
|
||||
@@ -759,6 +759,26 @@
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.post-location {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
margin: -4px 0 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
color: var(--text-secondary);
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
}
|
||||
|
||||
.post-location-text {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.post-media-container {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
@@ -176,6 +176,8 @@ export default function SnsPage() {
|
||||
const selectedContactUsernamesRef = useRef<string[]>(selectedContactUsernames)
|
||||
const cacheScopeKeyRef = useRef('')
|
||||
const snsUserPostCountsCacheScopeKeyRef = useRef('')
|
||||
const activeContactsLoadTaskIdRef = useRef<string | null>(null)
|
||||
const activeContactsCountTaskIdRef = useRef<string | null>(null)
|
||||
const scrollAdjustmentRef = useRef<{ scrollHeight: number; scrollTop: number } | null>(null)
|
||||
const pendingResetFeedRef = useRef(false)
|
||||
const contactsLoadTokenRef = useRef(0)
|
||||
@@ -750,6 +752,12 @@ export default function SnsPage() {
|
||||
window.clearTimeout(contactsCountBatchTimerRef.current)
|
||||
contactsCountBatchTimerRef.current = null
|
||||
}
|
||||
if (activeContactsCountTaskIdRef.current) {
|
||||
finishBackgroundTask(activeContactsCountTaskIdRef.current, 'canceled', {
|
||||
detail: '已停止后续联系人朋友圈条数补算'
|
||||
})
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
if (resetProgress) {
|
||||
setContactsCountProgress({
|
||||
resolved: 0,
|
||||
@@ -814,31 +822,56 @@ export default function SnsPage() {
|
||||
cancelable: true
|
||||
})
|
||||
|
||||
activeContactsCountTaskIdRef.current = taskId
|
||||
let normalizedCounts: Record<string, number> = {}
|
||||
try {
|
||||
const result = await window.electronAPI.sns.getUserPostCounts()
|
||||
if (isBackgroundTaskCancelRequested(taskId)) {
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '已停止后续加载,当前计数查询结束后不再继续分批写入'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (runToken !== contactsCountHydrationTokenRef.current) return
|
||||
if (runToken !== contactsCountHydrationTokenRef.current) {
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人朋友圈条数补算已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (result.success && result.counts) {
|
||||
normalizedCounts = Object.fromEntries(
|
||||
Object.entries(result.counts).map(([username, value]) => [username, normalizePostCount(value)])
|
||||
)
|
||||
normalizedCounts = pendingTargets.reduce<Record<string, number>>((acc, username) => {
|
||||
acc[username] = normalizePostCount(result.counts?.[username])
|
||||
return acc
|
||||
}, {})
|
||||
void (async () => {
|
||||
try {
|
||||
const scopeKey = await ensureSnsUserPostCountsCacheScopeKey()
|
||||
await configService.setExportSnsUserPostCountsCache(scopeKey, normalizedCounts)
|
||||
const currentCache = await configService.getExportSnsUserPostCountsCache(scopeKey)
|
||||
await configService.setExportSnsUserPostCountsCache(scopeKey, {
|
||||
...(currentCache?.counts || {}),
|
||||
...normalizedCounts
|
||||
})
|
||||
} catch (cacheError) {
|
||||
console.error('Failed to persist SNS user post counts cache:', cacheError)
|
||||
}
|
||||
})()
|
||||
} else {
|
||||
normalizedCounts = pendingTargets.reduce<Record<string, number>>((acc, username) => {
|
||||
acc[username] = 0
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load contact post counts:', error)
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'failed', {
|
||||
detail: String(error)
|
||||
})
|
||||
@@ -848,8 +881,19 @@ export default function SnsPage() {
|
||||
let resolved = preResolved
|
||||
let cursor = 0
|
||||
const applyBatch = () => {
|
||||
if (runToken !== contactsCountHydrationTokenRef.current) return
|
||||
if (runToken !== contactsCountHydrationTokenRef.current) {
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人朋友圈条数补算已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (isBackgroundTaskCancelRequested(taskId)) {
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: `已停止后续加载,已完成 ${resolved}/${totalTargets}`
|
||||
})
|
||||
@@ -870,6 +914,9 @@ export default function SnsPage() {
|
||||
running: false
|
||||
})
|
||||
contactsCountBatchTimerRef.current = null
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'completed', {
|
||||
detail: '联系人朋友圈条数补算完成',
|
||||
progressText: `${totalTargets}/${totalTargets}`
|
||||
@@ -910,6 +957,18 @@ export default function SnsPage() {
|
||||
contactsCountBatchTimerRef.current = window.setTimeout(applyBatch, CONTACT_COUNT_SORT_DEBOUNCE_MS)
|
||||
} else {
|
||||
contactsCountBatchTimerRef.current = null
|
||||
setContactsCountProgress({
|
||||
resolved: totalTargets,
|
||||
total: totalTargets,
|
||||
running: false
|
||||
})
|
||||
if (activeContactsCountTaskIdRef.current === taskId) {
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'completed', {
|
||||
detail: '鑱旂郴浜烘湅鍙嬪湀鏉℃暟琛ョ畻瀹屾垚',
|
||||
progressText: `${totalTargets}/${totalTargets}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,6 +977,12 @@ export default function SnsPage() {
|
||||
|
||||
// Load Contacts(先按最近会话显示联系人,再异步统计朋友圈条数并增量排序)
|
||||
const loadContacts = useCallback(async () => {
|
||||
if (activeContactsLoadTaskIdRef.current) {
|
||||
finishBackgroundTask(activeContactsLoadTaskIdRef.current, 'canceled', {
|
||||
detail: '新一轮联系人列表加载已开始,旧任务已取消'
|
||||
})
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
const requestToken = ++contactsLoadTokenRef.current
|
||||
const taskId = registerBackgroundTask({
|
||||
sourcePage: 'sns',
|
||||
@@ -926,6 +991,7 @@ export default function SnsPage() {
|
||||
progressText: '初始化',
|
||||
cancelable: true
|
||||
})
|
||||
activeContactsLoadTaskIdRef.current = taskId
|
||||
stopContactsCountHydration(true)
|
||||
setContactsLoading(true)
|
||||
try {
|
||||
@@ -955,7 +1021,15 @@ export default function SnsPage() {
|
||||
}
|
||||
})
|
||||
|
||||
if (requestToken !== contactsLoadTokenRef.current) return
|
||||
if (requestToken !== contactsLoadTokenRef.current) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人列表加载已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (cachedContacts.length > 0) {
|
||||
const cachedContactsSorted = sortContactsForRanking(cachedContacts)
|
||||
setContacts(cachedContactsSorted)
|
||||
@@ -977,6 +1051,9 @@ export default function SnsPage() {
|
||||
window.electronAPI.chat.getSessions()
|
||||
])
|
||||
if (isBackgroundTaskCancelRequested(taskId)) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '已停止后续加载,当前联系人查询结束后未继续补齐'
|
||||
})
|
||||
@@ -1021,7 +1098,15 @@ export default function SnsPage() {
|
||||
}
|
||||
|
||||
let contactsList = sortContactsForRanking(Array.from(contactMap.values()))
|
||||
if (requestToken !== contactsLoadTokenRef.current) return
|
||||
if (requestToken !== contactsLoadTokenRef.current) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人列表加载已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
setContacts(contactsList)
|
||||
const readyUsernames = new Set(
|
||||
contactsList
|
||||
@@ -1043,6 +1128,9 @@ export default function SnsPage() {
|
||||
})
|
||||
const enriched = await window.electronAPI.chat.enrichSessionsContactInfo(allUsernames)
|
||||
if (isBackgroundTaskCancelRequested(taskId)) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '已停止后续加载,联系人补齐未继续写入'
|
||||
})
|
||||
@@ -1058,7 +1146,15 @@ export default function SnsPage() {
|
||||
avatarUrl: extra.avatarUrl || contact.avatarUrl
|
||||
}
|
||||
})
|
||||
if (requestToken !== contactsLoadTokenRef.current) return
|
||||
if (requestToken !== contactsLoadTokenRef.current) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人列表加载已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
setContacts((prev) => {
|
||||
const prevMap = new Map(prev.map((contact) => [contact.username, contact]))
|
||||
const merged = contactsList.map((contact) => {
|
||||
@@ -1074,18 +1170,35 @@ export default function SnsPage() {
|
||||
})
|
||||
}
|
||||
}
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'completed', {
|
||||
detail: `朋友圈联系人列表加载完成,共 ${contactsList.length} 人`,
|
||||
progressText: `${contactsList.length} 人`
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestToken !== contactsLoadTokenRef.current) return
|
||||
if (requestToken !== contactsLoadTokenRef.current) {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'canceled', {
|
||||
detail: '页面状态已刷新,本次联系人列表加载已过期'
|
||||
})
|
||||
return
|
||||
}
|
||||
console.error('Failed to load contacts:', error)
|
||||
stopContactsCountHydration(true)
|
||||
if (activeContactsLoadTaskIdRef.current === taskId) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
finishBackgroundTask(taskId, 'failed', {
|
||||
detail: String(error)
|
||||
})
|
||||
} finally {
|
||||
if (activeContactsLoadTaskIdRef.current === taskId && requestToken !== contactsLoadTokenRef.current) {
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
if (requestToken === contactsLoadTokenRef.current) {
|
||||
setContactsLoading(false)
|
||||
}
|
||||
@@ -1185,6 +1298,18 @@ export default function SnsPage() {
|
||||
window.clearTimeout(contactsCountBatchTimerRef.current)
|
||||
contactsCountBatchTimerRef.current = null
|
||||
}
|
||||
if (activeContactsCountTaskIdRef.current) {
|
||||
finishBackgroundTask(activeContactsCountTaskIdRef.current, 'canceled', {
|
||||
detail: '已离开朋友圈页,联系人朋友圈条数补算已取消'
|
||||
})
|
||||
activeContactsCountTaskIdRef.current = null
|
||||
}
|
||||
if (activeContactsLoadTaskIdRef.current) {
|
||||
finishBackgroundTask(activeContactsLoadTaskIdRef.current, 'canceled', {
|
||||
detail: '已离开朋友圈页,联系人列表加载已取消'
|
||||
})
|
||||
activeContactsLoadTaskIdRef.current = null
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ export const CONFIG_KEYS = {
|
||||
EXPORT_DEFAULT_EXCEL_COMPACT_COLUMNS: 'exportDefaultExcelCompactColumns',
|
||||
EXPORT_DEFAULT_TXT_COLUMNS: 'exportDefaultTxtColumns',
|
||||
EXPORT_DEFAULT_CONCURRENCY: 'exportDefaultConcurrency',
|
||||
EXPORT_DEFAULT_IMAGE_DEEP_SEARCH_ON_MISS: 'exportDefaultImageDeepSearchOnMiss',
|
||||
EXPORT_WRITE_LAYOUT: 'exportWriteLayout',
|
||||
EXPORT_SESSION_NAME_PREFIX_ENABLED: 'exportSessionNamePrefixEnabled',
|
||||
EXPORT_LAST_SESSION_RUN_MAP: 'exportLastSessionRunMap',
|
||||
@@ -65,6 +66,7 @@ export const CONFIG_KEYS = {
|
||||
NOTIFICATION_FILTER_LIST: 'notificationFilterList',
|
||||
MESSAGE_PUSH_ENABLED: 'messagePushEnabled',
|
||||
WINDOW_CLOSE_BEHAVIOR: 'windowCloseBehavior',
|
||||
QUOTE_LAYOUT: 'quoteLayout',
|
||||
|
||||
// 词云
|
||||
WORD_CLOUD_EXCLUDE_WORDS: 'wordCloudExcludeWords',
|
||||
@@ -89,6 +91,7 @@ export interface ExportDefaultMediaConfig {
|
||||
}
|
||||
|
||||
export type WindowCloseBehavior = 'ask' | 'tray' | 'quit'
|
||||
export type QuoteLayout = 'quote-top' | 'quote-bottom'
|
||||
|
||||
const DEFAULT_EXPORT_MEDIA_CONFIG: ExportDefaultMediaConfig = {
|
||||
images: true,
|
||||
@@ -462,6 +465,18 @@ export async function setExportDefaultConcurrency(concurrency: number): Promise<
|
||||
await config.set(CONFIG_KEYS.EXPORT_DEFAULT_CONCURRENCY, concurrency)
|
||||
}
|
||||
|
||||
// 获取缺图时是否深度搜索(默认导出行为)
|
||||
export async function getExportDefaultImageDeepSearchOnMiss(): Promise<boolean | null> {
|
||||
const value = await config.get(CONFIG_KEYS.EXPORT_DEFAULT_IMAGE_DEEP_SEARCH_ON_MISS)
|
||||
if (typeof value === 'boolean') return value
|
||||
return null
|
||||
}
|
||||
|
||||
// 设置缺图时是否深度搜索(默认导出行为)
|
||||
export async function setExportDefaultImageDeepSearchOnMiss(enabled: boolean): Promise<void> {
|
||||
await config.set(CONFIG_KEYS.EXPORT_DEFAULT_IMAGE_DEEP_SEARCH_ON_MISS, enabled)
|
||||
}
|
||||
|
||||
export type ExportWriteLayout = 'A' | 'B' | 'C'
|
||||
|
||||
export async function getExportWriteLayout(): Promise<ExportWriteLayout> {
|
||||
@@ -580,6 +595,8 @@ export interface ExportSessionContentMetricCacheEntry {
|
||||
imageMessages?: number
|
||||
videoMessages?: number
|
||||
emojiMessages?: number
|
||||
firstTimestamp?: number
|
||||
lastTimestamp?: number
|
||||
}
|
||||
|
||||
export interface ExportSessionContentMetricCacheItem {
|
||||
@@ -645,6 +662,7 @@ export interface ContactsListCacheContact {
|
||||
displayName: string
|
||||
remark?: string
|
||||
nickname?: string
|
||||
alias?: string
|
||||
type: 'friend' | 'group' | 'official' | 'former_friend' | 'other'
|
||||
}
|
||||
|
||||
@@ -742,6 +760,12 @@ export async function getExportSessionContentMetricCache(scopeKey: string): Prom
|
||||
if (typeof source.emojiMessages === 'number' && Number.isFinite(source.emojiMessages) && source.emojiMessages >= 0) {
|
||||
metric.emojiMessages = Math.floor(source.emojiMessages)
|
||||
}
|
||||
if (typeof source.firstTimestamp === 'number' && Number.isFinite(source.firstTimestamp) && source.firstTimestamp > 0) {
|
||||
metric.firstTimestamp = Math.floor(source.firstTimestamp)
|
||||
}
|
||||
if (typeof source.lastTimestamp === 'number' && Number.isFinite(source.lastTimestamp) && source.lastTimestamp > 0) {
|
||||
metric.lastTimestamp = Math.floor(source.lastTimestamp)
|
||||
}
|
||||
if (Object.keys(metric).length === 0) continue
|
||||
metrics[sessionId] = metric
|
||||
}
|
||||
@@ -781,6 +805,12 @@ export async function setExportSessionContentMetricCache(
|
||||
if (typeof rawMetric.emojiMessages === 'number' && Number.isFinite(rawMetric.emojiMessages) && rawMetric.emojiMessages >= 0) {
|
||||
metric.emojiMessages = Math.floor(rawMetric.emojiMessages)
|
||||
}
|
||||
if (typeof rawMetric.firstTimestamp === 'number' && Number.isFinite(rawMetric.firstTimestamp) && rawMetric.firstTimestamp > 0) {
|
||||
metric.firstTimestamp = Math.floor(rawMetric.firstTimestamp)
|
||||
}
|
||||
if (typeof rawMetric.lastTimestamp === 'number' && Number.isFinite(rawMetric.lastTimestamp) && rawMetric.lastTimestamp > 0) {
|
||||
metric.lastTimestamp = Math.floor(rawMetric.lastTimestamp)
|
||||
}
|
||||
if (Object.keys(metric).length === 0) continue
|
||||
normalized[sessionId] = metric
|
||||
}
|
||||
@@ -1145,6 +1175,7 @@ export async function getContactsListCache(scopeKey: string): Promise<ContactsLi
|
||||
displayName,
|
||||
remark: typeof item.remark === 'string' ? item.remark : undefined,
|
||||
nickname: typeof item.nickname === 'string' ? item.nickname : undefined,
|
||||
alias: typeof item.alias === 'string' ? item.alias : undefined,
|
||||
type: (type === 'friend' || type === 'group' || type === 'official' || type === 'former_friend' || type === 'other')
|
||||
? type
|
||||
: 'other'
|
||||
@@ -1178,6 +1209,7 @@ export async function setContactsListCache(scopeKey: string, contacts: ContactsL
|
||||
displayName,
|
||||
remark: contact?.remark ? String(contact.remark) : undefined,
|
||||
nickname: contact?.nickname ? String(contact.nickname) : undefined,
|
||||
alias: contact?.alias ? String(contact.alias) : undefined,
|
||||
type
|
||||
})
|
||||
}
|
||||
@@ -1382,6 +1414,16 @@ export async function setWindowCloseBehavior(behavior: WindowCloseBehavior): Pro
|
||||
await config.set(CONFIG_KEYS.WINDOW_CLOSE_BEHAVIOR, behavior)
|
||||
}
|
||||
|
||||
export async function getQuoteLayout(): Promise<QuoteLayout> {
|
||||
const value = await config.get(CONFIG_KEYS.QUOTE_LAYOUT)
|
||||
if (value === 'quote-bottom') return value
|
||||
return 'quote-top'
|
||||
}
|
||||
|
||||
export async function setQuoteLayout(layout: QuoteLayout): Promise<void> {
|
||||
await config.set(CONFIG_KEYS.QUOTE_LAYOUT, layout)
|
||||
}
|
||||
|
||||
// 获取词云排除词列表
|
||||
export async function getWordCloudExcludeWords(): Promise<string[]> {
|
||||
const value = await config.get(CONFIG_KEYS.WORD_CLOUD_EXCLUDE_WORDS)
|
||||
|
||||
12
src/types/electron.d.ts
vendored
12
src/types/electron.d.ts
vendored
@@ -61,6 +61,7 @@ export interface ElectronAPI {
|
||||
ignoreUpdate: (version: string) => Promise<{ success: boolean }>
|
||||
onDownloadProgress: (callback: (progress: number) => void) => () => void
|
||||
onUpdateAvailable: (callback: (info: { version: string; releaseNotes: string }) => void) => () => void
|
||||
checkWayland: () => Promise<boolean>
|
||||
}
|
||||
notification: {
|
||||
show: (data: { title: string; content: string; avatarUrl?: string; sessionId: string }) => Promise<{ success?: boolean; error?: string } | void>
|
||||
@@ -790,6 +791,16 @@ export interface ElectronAPI {
|
||||
}>
|
||||
likes: Array<string>
|
||||
comments: Array<{ id: string; nickname: string; content: string; refCommentId: string; refNickname?: string; emojis?: Array<{ url: string; md5: string; width: number; height: number; encryptUrl?: string; aesKey?: string }> }>
|
||||
location?: {
|
||||
latitude?: number
|
||||
longitude?: number
|
||||
city?: string
|
||||
country?: string
|
||||
poiName?: string
|
||||
poiAddress?: string
|
||||
poiAddressName?: string
|
||||
label?: string
|
||||
}
|
||||
rawXml?: string
|
||||
}>
|
||||
error?: string
|
||||
@@ -852,6 +863,7 @@ export interface ExportOptions {
|
||||
sessionNameWithTypePrefix?: boolean
|
||||
displayNamePreference?: 'group-nickname' | 'remark' | 'nickname'
|
||||
exportConcurrency?: number
|
||||
imageDeepSearchOnMiss?: boolean
|
||||
}
|
||||
|
||||
export interface ExportProgress {
|
||||
|
||||
@@ -34,6 +34,17 @@ export interface SnsComment {
|
||||
emojis?: SnsCommentEmoji[]
|
||||
}
|
||||
|
||||
export interface SnsLocation {
|
||||
latitude?: number
|
||||
longitude?: number
|
||||
city?: string
|
||||
country?: string
|
||||
poiName?: string
|
||||
poiAddress?: string
|
||||
poiAddressName?: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
export interface SnsPost {
|
||||
id: string
|
||||
tid?: string // 数据库主键(雪花 ID),用于精确删除
|
||||
@@ -46,6 +57,7 @@ export interface SnsPost {
|
||||
media: SnsMedia[]
|
||||
likes: string[]
|
||||
comments: SnsComment[]
|
||||
location?: SnsLocation
|
||||
rawXml?: string
|
||||
linkTitle?: string
|
||||
linkUrl?: string
|
||||
|
||||
@@ -4,6 +4,10 @@ import electron from 'vite-plugin-electron'
|
||||
import renderer from 'vite-plugin-electron-renderer'
|
||||
import { resolve } from 'path'
|
||||
|
||||
const handleElectronOnStart = (options: { reload: () => void }) => {
|
||||
options.reload()
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
server: {
|
||||
@@ -23,6 +27,7 @@ export default defineConfig({
|
||||
electron([
|
||||
{
|
||||
entry: 'electron/main.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -43,6 +48,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/annualReportWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -61,6 +67,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/dualReportWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -79,6 +86,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/imageSearchWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -93,6 +101,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/wcdbWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -112,6 +121,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/transcribeWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -129,6 +139,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/exportWorker.ts',
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron',
|
||||
@@ -149,9 +160,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
entry: 'electron/preload.ts',
|
||||
onstart(options) {
|
||||
options.reload()
|
||||
},
|
||||
onstart: handleElectronOnStart,
|
||||
vite: {
|
||||
build: {
|
||||
outDir: 'dist-electron'
|
||||
|
||||
Reference in New Issue
Block a user