Files
WechatExplorer/src/main/app-data-bootstrap.ts
T
Wxw-Gu 3f019faa38 feat: 完成 TraceMemo v2.2.0 品牌身份与数据迁移升级
- 将 WechatExplorer 产品身份升级为 TraceMemo
- 更新 appId、Runtime Identity、Reader Skill 和 API 环境变量
- 增加旧用户数据、Knowledge、Token 与 AI Provider 安全迁移
- 保留 Windows WeFlow 和旧版配置兼容
- 完善首次启动迁移测试及 v2.2.0 发布文档
- 移除 macOS Intel x64 构建与发布支持
2026-08-11 17:52:57 +08:00

57 lines
2.4 KiB
TypeScript

import { app } from 'electron'
import path from 'path'
import { getUserDataRoots, LEGACY_USER_DATA_NAME, TRACE_MEMO_RUNTIME_NAME } from './app-data-paths'
export const LEGACY_MIGRATION_HELPER_ENV = 'TRACEMEMO_LEGACY_MIGRATION_HELPER'
export const LEGACY_MIGRATION_SOURCE_ENV = 'TRACEMEMO_LEGACY_MIGRATION_SOURCE'
export const LEGACY_MIGRATION_USER_DATA_ENV = 'TRACEMEMO_LEGACY_MIGRATION_USER_DATA'
export const LEGACY_MIGRATION_RESULT_FD_ENV = 'TRACEMEMO_LEGACY_MIGRATION_RESULT_FD'
// This module must remain the first main-process import. Static imports in
// settings/cache services can otherwise resolve Electron paths before the
// TraceMemo userData is installed before any consumers. macOS uses the old
// safeStorage identity only inside the helper; Windows keeps in both
// processes because WCDB requires that technical runtime name.
const isLegacyMigrationHelper = process.env[LEGACY_MIGRATION_HELPER_ENV] === '1'
const legacyRuntimeName = process.platform === 'win32' ? 'WeFlow' : LEGACY_USER_DATA_NAME
const runtimeName =
process.platform === 'win32'
? 'WeFlow'
: isLegacyMigrationHelper
? legacyRuntimeName
: TRACE_MEMO_RUNTIME_NAME
app.setName(runtimeName)
const isolatedUserData = process.env['WXE_USER_DATA']
const isUserDataIsolated = !isLegacyMigrationHelper && Boolean(isolatedUserData?.trim())
const roots = getUserDataRoots(app.getPath('appData'))
const helperUserData = process.env[LEGACY_MIGRATION_USER_DATA_ENV]
const selectedUserData = isLegacyMigrationHelper
? path.resolve(helperUserData?.trim() || path.join(roots.current, '.legacy-migration-helper'))
: isolatedUserData?.trim()
? path.resolve(isolatedUserData)
: roots.current
app.setPath('userData', selectedUserData)
app.setPath('sessionData', selectedUserData)
// Logs are intentionally independent from userData. New TraceMemo logs go to
// the new visible directory while historical WechatExplorer logs remain in
// place and are never moved or renamed.
if (isLegacyMigrationHelper) {
app.setPath('logs', path.join(selectedUserData, 'logs'))
} else if (process.platform === 'darwin') {
app.setPath('logs', path.join(app.getPath('home'), 'Library', 'Logs', 'TraceMemo'))
} else if (process.platform === 'win32') {
app.setPath('logs', path.join(selectedUserData, 'logs'))
}
export {
isLegacyMigrationHelper,
isUserDataIsolated,
legacyRuntimeName,
runtimeName,
roots,
selectedUserData
}