一、灵动岛
- ①「紧急通知后来了新作业,收起再点开不了新作业」根因有二,都已修:
(a) active 仍是紧急那条,点击只会反复打开它 —— 现在点击胶囊优先打开**最新**那条未处理消息(队列里更晚的);
(b) 上课时段 syncWindow 会把普通通知立刻隐藏(表现为点了没反应)—— 新增 explicitShowId,
"用户主动点开"的那条守卫放行(岛完全隐藏时仍严格不打扰)。
冒烟新增「紧急通知后来了新作业:收起再点击打开的是新作业(联合通知回归)」。
- ② 设置实时预览/保存:补「设置页真实链路」断言(window.desktop.islandSetAppearance → IPC → 主进程 →
渲染进程 CSS 变量 + 窗口尺寸),并断言"岛显示中改尺寸立即生效"(实测均通过)。
- ③ 未读红点移到「通知」图标右上角(此前在文字后面),并加 DOM 几何断言(dx>0 且 dy<0,
没有未读时自动造一条未读通知再断言、断言后删除)。
- 冒烟稳定性:新增 island.setBlurCollapseEnabled()(默认开),测试期间关掉"失焦收起",
避免系统抢焦点导致展开态被收回的随机失败;专门验证失焦的用例仍临时打开。
二、作业看板(学生端)
- ⑥ 只看当天:新增「只看今天」开关(默认开),按 createdAt 的本地日期过滤,昨天的过期作业不再混入。
- ⑧ 完整显示:卡片同时渲染标题 + 作业要求全文(列表模式也加「作业要求」列)。
- ⑨ 铺满不滚动:看板外层高度固定 + overflow hidden,按内容/可用高度算缩放系数用 transform: scale 适配
(工具栏显示当前缩放比例),页面本身不出现滚动条。
- ⑦ 全屏看板标题栏用 #header 插槽:标题左对齐、当天日期时间绝对居中(受「显示时间」开关控制,每分钟刷新)。
三、课表与周数
- ⑤ 学期周数可调:新增 Class.termWeeks(默认 20,迁移 + 维护脚本),班主任在班级管理里改;
GET /api/dashboard/term?classId= 返回该班 maxWeek,课表周次下拉与新建课表的默认 weekEnd 都按它来
(不再固定 30 周)。
- ⑩ 课表管理只保留「导入 ClassIsland 课程表」入口(时间表由课程表 JSON 的 TimeLayouts 一并带入),
「导入时间配置」按钮下线;ui-smoke 第 7.7 段改为断言新弹窗(解析 4 行 + 单双周标签 + 旧入口已下线)。
四、以班级为单位(⑬)与 Web 端
- 个人学生账号登录停用:POST /api/auth/login 对 role=STUDENT 返回 403(改用班级码 + 班级密码);
学生行仍作为个人数据记录键由班级会话代全班读写;e2e 全面切换到班级会话并新增该断言。
- ④ 作业科目过少:新增共享 SUBJECT_CATALOG(16 个常见科目)+ 种子课程扩到全科目;
Web 作业发布弹窗可选「其他科目(新建)」,提交前自动建课(同名复用)。
- ⑪ 通知支持多班批量发布(多选 + 逐班发布 + 汇总结果 + 二次确认覆盖所有选中班);
⑫ 单班只显示已读情况、跨班才显示已读率;⑭ 手机端课表可横向滚动看全 7 天;
⑮ 手机端已连接不再显示孤立绿点(仅未连接时显示文字标签);⑯ 手机端「叫人/发布通知」按钮同宽左对齐;
⑬ Web 学生管理去掉「用户名」列(新建自动生成学号式用户名,导入仍支持显式指定)。
验证:verify:e2e 149/149、verify:web 20/20、verify:desktop 75/75(复跑 68/68,打包便携版 75/75 packaged=true)、
typecheck / lint / format 全绿;服务端与 Web 已重新打包并部署到本机安装目录。
191 lines
6.8 KiB
TypeScript
191 lines
6.8 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { app, safeStorage } from 'electron';
|
|
import { DEFAULT_ISLAND_APPEARANCE, DEFAULT_SERVER_URL, type IslandAppearance } from '@classhelper/shared';
|
|
import type { DesktopStoredConfig, HomeworkBoardSettings } from '../types/desktop.js';
|
|
|
|
/** 作业页展示偏好默认值(看板 + 不显示时间 + 15px) */
|
|
const DEFAULT_HOMEWORK_BOARD: HomeworkBoardSettings = {
|
|
mode: 'board',
|
|
showTime: false,
|
|
fontSize: 15,
|
|
todayOnly: true,
|
|
};
|
|
|
|
interface PersistedConfig {
|
|
serverUrl: string;
|
|
username: string;
|
|
/** 加密后的 token(base64)或明文(当系统不支持加密时) */
|
|
token: string | null;
|
|
tokenEncrypted: boolean;
|
|
/** 个性化设置:灵动岛外观(向后兼容:旧配置文件没有该字段时用默认值补齐) */
|
|
island?: Partial<IslandAppearance>;
|
|
/** 作业页展示偏好(向后兼容:旧配置文件没有该字段时用默认值补齐) */
|
|
homeworkBoard?: Partial<HomeworkBoardSettings>;
|
|
}
|
|
|
|
const DEFAULT_CONFIG: PersistedConfig = {
|
|
serverUrl: DEFAULT_SERVER_URL,
|
|
username: '',
|
|
token: null,
|
|
tokenEncrypted: false,
|
|
island: { ...DEFAULT_ISLAND_APPEARANCE },
|
|
homeworkBoard: { ...DEFAULT_HOMEWORK_BOARD },
|
|
};
|
|
|
|
/** 作业页偏好的合法化(模式白名单、字号夹紧) */
|
|
function normalizeHomeworkBoard(input?: Partial<HomeworkBoardSettings>): HomeworkBoardSettings {
|
|
const mode = input?.mode === 'list' ? 'list' : 'board';
|
|
const rawFont =
|
|
typeof input?.fontSize === 'number' && Number.isFinite(input.fontSize)
|
|
? input.fontSize
|
|
: DEFAULT_HOMEWORK_BOARD.fontSize;
|
|
return {
|
|
mode,
|
|
showTime: input?.showTime === true,
|
|
todayOnly: input?.todayOnly !== false,
|
|
fontSize: Math.min(28, Math.max(11, Math.round(rawFont))),
|
|
};
|
|
}
|
|
|
|
/** 外观字段的合法区间校验(越界值直接夹紧,避免用户配置破坏灵动岛布局) */
|
|
function normalizeIslandAppearance(input?: Partial<IslandAppearance>): IslandAppearance {
|
|
const clamp = (value: unknown, min: number, max: number, fallback: number): number => {
|
|
const numeric = typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
return Math.min(max, Math.max(min, Math.round(numeric * 100) / 100));
|
|
};
|
|
const positions: IslandAppearance['position'][] = [
|
|
'top-center',
|
|
'top-left',
|
|
'top-right',
|
|
'bottom-center',
|
|
'bottom-left',
|
|
'bottom-right',
|
|
];
|
|
const styles: IslandAppearance['style'][] = ['black', 'glass', 'tinted'];
|
|
return {
|
|
height: clamp(input?.height, 36, 72, DEFAULT_ISLAND_APPEARANCE.height),
|
|
width: clamp(input?.width, 220, 420, DEFAULT_ISLAND_APPEARANCE.width),
|
|
radius: clamp(input?.radius, 8, 32, DEFAULT_ISLAND_APPEARANCE.radius),
|
|
opacity: clamp(input?.opacity, 0.4, 1, DEFAULT_ISLAND_APPEARANCE.opacity),
|
|
accent:
|
|
typeof input?.accent === 'string' && /^#[0-9a-fA-F]{6}$/.test(input.accent)
|
|
? input.accent
|
|
: DEFAULT_ISLAND_APPEARANCE.accent,
|
|
fontSize: clamp(input?.fontSize, 11, 20, DEFAULT_ISLAND_APPEARANCE.fontSize),
|
|
animations: input?.animations !== false,
|
|
speed: clamp(input?.speed, 0.5, 2, DEFAULT_ISLAND_APPEARANCE.speed),
|
|
position: positions.includes(input?.position as IslandAppearance['position'])
|
|
? (input?.position as IslandAppearance['position'])
|
|
: DEFAULT_ISLAND_APPEARANCE.position,
|
|
alwaysOnTop: input?.alwaysOnTop !== false,
|
|
style: styles.includes(input?.style as IslandAppearance['style'])
|
|
? (input?.style as IslandAppearance['style'])
|
|
: DEFAULT_ISLAND_APPEARANCE.style,
|
|
idleSliver: input?.idleSliver === true,
|
|
};
|
|
}
|
|
|
|
function configFilePath(): string {
|
|
return path.join(app.getPath('userData'), 'config.json');
|
|
}
|
|
|
|
function encryptToken(token: string | null): { token: string | null; tokenEncrypted: boolean } {
|
|
if (!token) return { token: null, tokenEncrypted: false };
|
|
try {
|
|
if (safeStorage.isEncryptionAvailable()) {
|
|
return { token: safeStorage.encryptString(token).toString('base64'), tokenEncrypted: true };
|
|
}
|
|
} catch {
|
|
// 某些环境下 DPAPI 不可用,降级为明文存储(仅本地开发场景)
|
|
}
|
|
return { token, tokenEncrypted: false };
|
|
}
|
|
|
|
function decryptToken(raw: PersistedConfig): string | null {
|
|
if (!raw.token) return null;
|
|
if (!raw.tokenEncrypted) return raw.token;
|
|
try {
|
|
return safeStorage.decryptString(Buffer.from(raw.token, 'base64'));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function readPersisted(): PersistedConfig {
|
|
try {
|
|
const content = fs.readFileSync(configFilePath(), 'utf8');
|
|
const parsed = JSON.parse(content) as Partial<PersistedConfig>;
|
|
return {
|
|
serverUrl:
|
|
typeof parsed.serverUrl === 'string' && parsed.serverUrl
|
|
? parsed.serverUrl
|
|
: DEFAULT_CONFIG.serverUrl,
|
|
username: typeof parsed.username === 'string' ? parsed.username : '',
|
|
token: typeof parsed.token === 'string' ? parsed.token : null,
|
|
tokenEncrypted: parsed.tokenEncrypted === true,
|
|
island: normalizeIslandAppearance(parsed.island),
|
|
homeworkBoard: normalizeHomeworkBoard(parsed.homeworkBoard),
|
|
};
|
|
} catch {
|
|
return { ...DEFAULT_CONFIG };
|
|
}
|
|
}
|
|
|
|
function writePersisted(config: PersistedConfig): void {
|
|
const target = configFilePath();
|
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
fs.writeFileSync(target, JSON.stringify(config, null, 2), 'utf8');
|
|
}
|
|
|
|
/** 读取配置(token 已解密),供渲染进程使用 */
|
|
export function getConfig(): DesktopStoredConfig {
|
|
const persisted = readPersisted();
|
|
return {
|
|
serverUrl: persisted.serverUrl,
|
|
username: persisted.username,
|
|
token: decryptToken(persisted),
|
|
island: normalizeIslandAppearance(persisted.island),
|
|
homeworkBoard: normalizeHomeworkBoard(persisted.homeworkBoard),
|
|
};
|
|
}
|
|
|
|
/** 局部更新配置:只覆盖传入的字段 */
|
|
export function saveConfig(patch: Partial<DesktopStoredConfig>): DesktopStoredConfig {
|
|
const persisted = readPersisted();
|
|
|
|
if (typeof patch.serverUrl === 'string' && patch.serverUrl.trim()) {
|
|
persisted.serverUrl = patch.serverUrl.trim().replace(/\/+$/, '');
|
|
}
|
|
if (typeof patch.username === 'string') {
|
|
persisted.username = patch.username;
|
|
}
|
|
if (patch.island !== undefined) {
|
|
persisted.island = normalizeIslandAppearance({ ...persisted.island, ...patch.island });
|
|
}
|
|
if (patch.homeworkBoard !== undefined) {
|
|
persisted.homeworkBoard = normalizeHomeworkBoard({
|
|
...persisted.homeworkBoard,
|
|
...patch.homeworkBoard,
|
|
});
|
|
}
|
|
if (patch.token !== undefined) {
|
|
const encrypted = encryptToken(patch.token);
|
|
persisted.token = encrypted.token;
|
|
persisted.tokenEncrypted = encrypted.tokenEncrypted;
|
|
}
|
|
|
|
writePersisted(persisted);
|
|
return getConfig();
|
|
}
|
|
|
|
/** 清空为默认配置(退出登录 / 重置) */
|
|
export function clearConfig(): DesktopStoredConfig {
|
|
writePersisted({ ...DEFAULT_CONFIG });
|
|
return getConfig();
|
|
}
|
|
|
|
export function getConfigPath(): string {
|
|
return configFilePath();
|
|
}
|