feat(desktop,island,shared): 灵动岛支持多条通知竖排列表 + 触摸模式 + 收回动画,产物加凭据门禁
灵动岛列表:多条通知时展开为竖排列表,默认显示 3 条,点「展开更多」铺到屏幕容纳 上限,放不下的收进「更多请前往应用内操作」。卡片高度由主进程与渲染进程各算一次 同一个数 —— 度量表 ISLAND_LIST_METRICS 与排序权重 PRIORITY_RANK 放在 shared, 窗口包围盒随之长高(不够高会把底部按钮裁掉)。 触摸模式:触摸屏上手指既不产生 mousemove、也不移动系统光标,原先两条命中链路都会 让窗口永远停在穿透态、手指点不开岛。现按 navigator.maxTouchPoints 上报后,主进程把 窗口贴合岛体并始终接收输入;非触摸屏机器完全不走这条路。 收回动画:main 先发 island:closing,渲染进程形变收敛后回 closing-done 才淡出, 不再靠猜时长(rAF 被节流时会把卡片缩到一半窗口就没了)。 安全门禁:新增 scripts/check-bundle-secrets.mjs 并接进 build:desktop —— dist 产物会被打进 app.asar 发到每台学生机、且可解包,冒烟凭据一律改由环境变量注入, 产物里出现种子口令即构建失败。
This commit is contained in:
1 parent
d27f9a4b9e
commit
3880eee08e
22 files changed
+2482
-175
No files matched your search
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 构建产物凭据自检:`dist` 里不允许出现种子账号 / 口令字面量。
|
||||
*
|
||||
* 为什么单独立一条门禁:`dist/main/index.js` 与 `dist/renderer/assets/*.js` 会被 electron-builder
|
||||
* 打进 `app.asar`,随安装包发到每台学生机,而 **asar 可以直接解包**。
|
||||
* 冒烟/自检代码里写死 `teacher1 / teacher123` 这类字面量,等于把教师账号随安装包一起发出去
|
||||
* (历史上真的发生过:`grep teacher123 dist/main/index.js` 命中 3 次)。
|
||||
*
|
||||
* 凭据一律由 `scripts/smoke.mjs` / `scripts/verify-packaged.mjs` 通过环境变量提供
|
||||
* (`ELECTRON_SMOKE_USER` / `ELECTRON_SMOKE_PASSWORD` / `ELECTRON_SMOKE_CLASS_CODE` / `..._CLASS_PASSWORD`),
|
||||
* 那两个脚本不进安装包。
|
||||
*
|
||||
* 命中即构建失败(exit 1)。
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const distDir = path.join(root, 'dist');
|
||||
|
||||
/** 明确的种子口令:任何情况下都不该出现在产物里 */
|
||||
const FORBIDDEN_STRINGS = ['teacher123', 'admin123', 'student123'];
|
||||
|
||||
/** 组合形态:把种子班级码 / 默认班级密码当凭据使用的写法 */
|
||||
const FORBIDDEN_PATTERNS = [
|
||||
{ label: '种子班级码当凭据', pattern: /["'](?:code|classCode)["']\s*[:=]\s*["']G(?:101|102|203)["']/ },
|
||||
{
|
||||
label: '默认班级密码当凭据',
|
||||
pattern: /["'](?:password|classPassword)["']\s*[:=]\s*["']123456["']/,
|
||||
},
|
||||
];
|
||||
|
||||
/** 递归收集文件(跳过 sourcemap 与二进制) */
|
||||
function collectFiles(dir) {
|
||||
const found = [];
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
found.push(...collectFiles(full));
|
||||
} else if (/\.(?:js|mjs|cjs|html|json|css)$/i.test(entry.name)) {
|
||||
found.push(full);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(distDir)) {
|
||||
console.log('[check-secrets] 未找到 dist(尚未构建),跳过凭据自检');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const hits = [];
|
||||
for (const file of collectFiles(distDir)) {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const relative = path.relative(root, file);
|
||||
for (const needle of FORBIDDEN_STRINGS) {
|
||||
if (content.includes(needle)) hits.push(`${relative}:出现种子口令「${needle}」`);
|
||||
}
|
||||
for (const { label, pattern } of FORBIDDEN_PATTERNS) {
|
||||
if (pattern.test(content)) hits.push(`${relative}:${label}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (hits.length > 0) {
|
||||
console.error('[check-secrets] 构建产物里出现了种子凭据(asar 可被解包,不能随包分发):');
|
||||
for (const hit of hits) console.error(` - ${hit}`);
|
||||
console.error(
|
||||
'\n请把凭据改为从环境变量读取(见 scripts/smoke.mjs 的 ELECTRON_SMOKE_USER 等),不要写进源码。',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`[check-secrets] 通过:${collectFiles(distDir).length} 个产物文件里没有任何种子凭据字面量`);
|
||||
@@ -12,7 +12,7 @@
|
||||
* node scripts/dist-win.mjs # nsis 安装包 + portable 单文件
|
||||
* node scripts/dist-win.mjs --dir # 仅生成免安装目录 release/win-unpacked
|
||||
*/
|
||||
import { spawn } from 'node:child_process';
|
||||
import { execFileSync, spawn } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
@@ -24,8 +24,17 @@ const args = process.argv.slice(2);
|
||||
const dirOnly = args.includes('--dir');
|
||||
const passthrough = args.filter((item) => item !== '--dir');
|
||||
|
||||
// makensis 会在 %TEMP% 所在位置建临时文件:Git Bash 里 TEMP=/tmp 是 MSYS 路径,
|
||||
// 原生程序会把它当成「当前盘根下的 tmp」(D:\tmp,不存在)而报
|
||||
// `!tempfile: Unable to create temporary file!`,NSIS 那一步就失败(磁盘并不紧张)。
|
||||
// 统一指到仓库内的真实目录,避开宿主终端带来的环境差异。
|
||||
const tmpDir = path.join(repoRoot, '.cache', 'tmp');
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
TEMP: tmpDir,
|
||||
TMP: tmpDir,
|
||||
ELECTRON_MIRROR: process.env.ELECTRON_MIRROR ?? 'https://cdn.npmmirror.com/binaries/electron/',
|
||||
ELECTRON_BUILDER_BINARIES_MIRROR:
|
||||
process.env.ELECTRON_BUILDER_BINARIES_MIRROR ??
|
||||
@@ -60,11 +69,56 @@ console.log('[dist] electron-builder', cliArgs.slice(1).join(' '));
|
||||
const runtime = resolveNodeRuntime();
|
||||
console.log(`[dist] Node 运行时:${runtime.path}(${runtime.version})`);
|
||||
|
||||
// 清理上一轮产物:本仓库目录树带沙箱 ACL(含 Everyone 的 DENY(delete child)),
|
||||
// 已存在的产物会被工具(makensis / 7za)判为"Can't open output file / 拒绝访问"而失败,
|
||||
// 手动删掉再打包即可 —— 顺手也保证产物集合确定,不会残留上一轮的旧安装包。
|
||||
const outputDir = path.join(root, 'release');
|
||||
if (fs.existsSync(outputDir)) {
|
||||
for (const name of fs.readdirSync(outputDir)) {
|
||||
if (!/\.(exe|7z|blockmap|yml)$/i.test(name)) continue;
|
||||
try {
|
||||
fs.rmSync(path.join(outputDir, name), { force: true });
|
||||
} catch (error) {
|
||||
console.warn(`[dist] 无法清理旧产物 ${name}:${error.message}`);
|
||||
}
|
||||
}
|
||||
console.log('[dist] 已清理上一轮的安装包 / 归档');
|
||||
}
|
||||
|
||||
const child = spawn(runtime.path, cliArgs, { cwd: root, stdio: 'inherit', env });
|
||||
|
||||
/**
|
||||
* 把交付产物的完整性标签修正为 Medium(Windows)。
|
||||
*
|
||||
* 背景(踩过一次,代价是"客户端装不上、便捷版也双击没反应"):
|
||||
* 本仓库目录树被宿主沙箱打上了 `Low Mandatory Level` 标签(可继承),
|
||||
* 因此在仓库内构建出的 exe 自身也带 Low 标签。Windows 会把这类进程降到 Low 完整性,
|
||||
* 于是 setup.exe 写不进 `%LOCALAPPDATA%`(报"拒绝访问"→ 装不上)、
|
||||
* 便捷版解不出 `%TEMP%`(→ 起不来);即使装上了,Low 标签的应用文件也会让
|
||||
* Chromium 的 AppContainer 子进程读不到(0x80000003 秒崩)。
|
||||
*
|
||||
* 要点:**只有交付物自身的标签要紧**。归档内部的载荷标签不会被还原
|
||||
* (装到正常位置得到的是默认 Medium 文件),所以打包完成后再统一修正即可 ——
|
||||
* 反过来说,不能在打包前把 appOutDir 改成 Medium:那样 7za(自身 Low)
|
||||
* 会因"不能向上读/写"而无法生成归档。
|
||||
*/
|
||||
function normalizeIntegrityLabel(dir) {
|
||||
if (process.platform !== 'win32') return;
|
||||
const run = (args) => execFileSync('icacls', args, { stdio: 'pipe', windowsHide: true });
|
||||
try {
|
||||
run([dir, '/setintegritylevel', 'Medium', '/T', '/C']);
|
||||
// 目录自身恢复为"继承父目录的 Low",保证下次构建时 Low 的 7za 仍能写入归档
|
||||
run([dir, '/setintegritylevel', '(OI)(CI)Low']);
|
||||
console.log('[dist] 已修正交付物完整性标签为 Medium,目录恢复继承:', dir);
|
||||
} catch (error) {
|
||||
console.warn('[dist] 完整性标签修正跳过:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
child.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
const output = path.join(root, 'release');
|
||||
normalizeIntegrityLabel(output);
|
||||
console.log('\n[dist] 打包完成,产物目录:', output);
|
||||
}
|
||||
process.exit(code ?? 1);
|
||||
|
||||
@@ -169,6 +169,10 @@ function launchSmoke(extraEnv) {
|
||||
ELECTRON_SMOKE_PROFILE: profileDir,
|
||||
ELECTRON_SMOKE_CLASS_CODE: classCredentials?.code ?? '',
|
||||
ELECTRON_SMOKE_CLASS_PASSWORD: classCredentials?.password ?? '',
|
||||
// 教师凭据只从这里传入:主进程的冒烟代码从环境变量读,
|
||||
// 因此安装包(app.asar)里不会留下教师口令字面量(本脚本不进安装包)
|
||||
ELECTRON_SMOKE_USER: process.env.ELECTRON_SMOKE_USER ?? 'teacher1',
|
||||
ELECTRON_SMOKE_PASSWORD: process.env.ELECTRON_SMOKE_PASSWORD ?? 'teacher123',
|
||||
...extraEnv,
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user