feat: 去除构建时版控变量 + 窗口标题动态版控 + 退出登录保留缓存 (0.0.24)

版控体系重构(13 文件):
- 移除 build.mjs --personal/--enterprise 参数和 EDITION 环境变量
- 统一安装包文件名:船长-HeiXiu-{os}-{版本号}-Setup.{ext}
- 简化 package.json 构建脚本,移除 :enterprise 变体
- scripts/*.mjs 不再接受 edition 参数
- 移除 shared/constants/app.ts 的 parseEdition()

窗口标题动态版控:
- 新格式:船长-HeiXiu-{os}-{版本号}(登录前)/ ·{版控} 后缀(登录后)
- 链路:AppProvider(account_type) → useEffect → appRuntime IPC → main process
- 移除 updater.ts 更新检查 API 的 edition 查询参数

本地存储生命周期修正:
- 退出登录不再自动清空缓存(user_id 隔离,重新登录命中缓存)
- clearUserStorage 添加 isOpen() 竞态守卫
- 移除 closeDatabase() 避免退出→重新登录后数据库不可用
- 手动「清理缓存」按钮保留

文档:
- CHANGELOG.md 新增 0.0.24 条目
- TODO.md 新增已完成项
This commit is contained in:
2026-06-22 13:36:42 +08:00
parent e4d66a2ac0
commit 8b697e775d
95 changed files with 1158 additions and 1295 deletions

View File

@@ -10,12 +10,12 @@
import { createContext, useContext, useState, useMemo, useCallback, useEffect, type ReactNode } from 'react';
import type { Platform, Edition } from '@shared/types';
import { getPlatform, isDev } from '@/utils/platform';
import { safeIpcOn, safeIpcOff } from '@/utils/ipc';
import { getPlatform, isDev } from '@/utils/env';
import { safeIpcOn, safeIpcOff } from '@/utils/bus';
import { AuthAPI, type LoginResponseBody } from '@/services/modules/auth';
import { setToken, clearToken, initTokenStore } from '@/services/request';
import { emit, EVENTS } from '@/utils/event-bus';
import { logger } from '@/utils/logger';
import { emit, EVENTS } from '@/utils/bus';
import { logger } from '@/utils/bus';
import { getAutoLoginFlag, clearAutoLoginFlag } from '@/services/auth-persistence';
import {
initAuthRefresh,
@@ -27,7 +27,7 @@ import {
clearProactiveRefresh,
} from '@/services/auth-token';
import {initModelCache} from '@/services/cache/model-cache';
import {initStorage, clearUserStorage} from '@/infrastructure/storage';
import {initStorage} from '@/infrastructure/storage';
// ---------- Context 类型 ----------
@@ -87,6 +87,11 @@ export function AppProvider({ children }: AppProviderProps) {
return user.account_type === 'individual' ? 'personal' : 'enterprise';
}, [user]);
// 登录/登出后同步窗口标题版控后缀到主进程
useEffect(() => {
window.appRuntime?.setWindowEdition(isLoggedIn ? edition : null);
}, [edition, isLoggedIn]);
// ---------- 登录 / 退出 ----------
const login = useCallback(async (auth: LoginResponseBody) => {
@@ -111,8 +116,9 @@ export function AppProvider({ children }: AppProviderProps) {
setUser(null);
setIsLoggedIn(false);
emit(EVENTS.LOGOUT);
// 异步清理本地存储(不阻塞 UI
void clearUserStorage();
// 注意:退出登录不自动清理本地缓存
// —— 数据已按 user_id 隔离,同一用户重新登录后缓存仍可命中
// 用户主动清理请使用设置页面的「清理缓存」按钮
}, []);
// ---------- 启动时初始化 token 存储 + 自动登录 ----------