'use strict' // 应用图标资源完整性守卫(2026-11-26) // // 为什么需要:v3.26.105 换图标时 icon.icns 的**头部总长度**(第 5-8 字节,大端 uint32) // 与实际文件长度不一致(声明 693,114 / 实际 167,838)。sips 不做全量校验照样能解码, // 所以本地"图看着没问题";但 macOS IconServices 按声明长度解析 → 直接失败 → // Dock / 访达 / 关于面板全部显示成空白方块(用户实测截图)。 // // 断言口径(全部只看字节结构,不依赖 macOS 工具,CI 在哪都能跑): // ① icns 头部声明长度 == 文件真实字节数 // ② 各 chunk 长度累加正好走完文件(没有截断的尾块) // ③ 有 1024 主图块(ic10 / ic14 / ic09@2x),否则 Retina Dock 只能放大 512 // ④ 其它图标文件没被顺手写坏(png 尺寸正确、ico 头 6 字节 + 目录项数合理) const fs = require('fs') const path = require('path') const assert = require('assert') const root = path.join(__dirname, '..') const iconsDir = path.join(root, 'src-tauri', 'icons') function readIcns (file) { const d = fs.readFileSync(file) assert.strictEqual(d.slice(0, 4).toString('latin1'), 'icns', file + ' 不是 icns(magic 不对)') const declared = d.readUInt32BE(4) return { d, declared } } // ── ① 头部长度自洽 ──────────────────────────────────────────────── const icnsPath = path.join(iconsDir, 'icon.icns') const { d: icns, declared } = readIcns(icnsPath) assert.strictEqual(declared, icns.length, 'icon.icns 头部声明长度 ' + declared + ' != 文件实际 ' + icns.length + '(IconServices 会整包解析失败 → Dock 图标空白)') // ── ② chunk 链完整 ─────────────────────────────────────────────── const types = [] let off = 8 while (off + 8 <= icns.length) { const type = icns.slice(off, off + 4).toString('latin1') const size = icns.readUInt32BE(off + 4) assert.ok(size >= 8, 'chunk ' + type + ' 长度非法:' + size) assert.ok(off + size <= icns.length, 'chunk ' + type + ' 越界(文件被截断)') types.push(type) off += size } assert.strictEqual(off, icns.length, 'icns chunk 链没有正好走完文件(尾部有残留字节)') // ── ③ 大图块存在 ───────────────────────────────────────────────── const BIG = ['ic10', 'ic14'] // 1024×1024(ic14 = 512@2x) assert.ok(BIG.some((t) => types.includes(t)), 'icns 里没有 1024×1024 图块(现有:' + types.join(',') + ')—— Retina Dock 会拿 512 放大') // ── ④ 其它图标文件 ─────────────────────────────────────────────── function pngSize (file) { const d = fs.readFileSync(file) assert.strictEqual(d.slice(1, 4).toString('latin1'), 'PNG', file + ' 不是 PNG') return { w: d.readUInt32BE(16), h: d.readUInt32BE(20) } } const p512 = pngSize(path.join(iconsDir, 'icon.png')) assert.ok(p512.w >= 512 && p512.w === p512.h, 'icon.png 必须是 >=512 的正方形,实际 ' + p512.w + '×' + p512.h) const p256 = pngSize(path.join(iconsDir, '128x128@2x.png')) assert.strictEqual(p256.w, 256, '128x128@2x.png 必须是 256×256,实际 ' + p256.w) const ico = fs.readFileSync(path.join(iconsDir, 'icon.ico')) assert.strictEqual(ico.readUInt16LE(0), 0, 'icon.ico reserved 必须为 0') assert.strictEqual(ico.readUInt16LE(2), 1, 'icon.ico type 必须为 1(icon)') const icoCount = ico.readUInt16LE(4) assert.ok(icoCount >= 4 && icoCount <= 32, 'icon.ico 目录项数异常:' + icoCount) assert.ok(6 + icoCount * 16 <= ico.length, 'icon.ico 目录表越界') console.log('icon-assets: icns ' + icns.length + ' B / ' + types.length + ' chunks(含 1024 主图);png / ico 结构正常')