Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 修复 Windows 任务栏图标偏小 (#266)

Dash361ac2ca1fe7
diff --git a/apps/desktop/cindy-updater/src-tauri/icons/icon.ico b/apps/desktop/cindy-updater/src-tauri/icons/icon.ico
index 675801f283..ba9c172d99 100644
Binary files a/apps/desktop/cindy-updater/src-tauri/icons/icon.ico and b/apps/desktop/cindy-updater/src-tauri/icons/icon.ico differ
diff --git a/apps/desktop/cindy-updater/src-tauri/icons/icon.png b/apps/desktop/cindy-updater/src-tauri/icons/icon.png
index b2cf5ed4ac..06e713cad0 100644
Binary files a/apps/desktop/cindy-updater/src-tauri/icons/icon.png and b/apps/desktop/cindy-updater/src-tauri/icons/icon.png differ
diff --git a/apps/desktop/resources/icon.ico b/apps/desktop/resources/icon.ico
index 675801f283..ba9c172d99 100644
Binary files a/apps/desktop/resources/icon.ico and b/apps/desktop/resources/icon.ico differ
diff --git a/apps/desktop/resources/icon.png b/apps/desktop/resources/icon.png
index b2cf5ed4ac..06e713cad0 100644
Binary files a/apps/desktop/resources/icon.png and b/apps/desktop/resources/icon.png differ
diff --git a/apps/desktop/scripts/generate-win-ico.mjs b/apps/desktop/scripts/generate-win-ico.mjs
index 4eea36a0a3..d9e61ea802 100644
--- a/apps/desktop/scripts/generate-win-ico.mjs
+++ b/apps/desktop/scripts/generate-win-ico.mjs
@@ -3,8 +3,9 @@
* generate-win-ico.mjs — 从 1024x1024 母版生成带圆角的 Windows icon.ico。
*
* Windows 的 BrowserWindow / 任务栏不会替 PNG/ICO 自动套圆角,圆角必须画进
- * 资源本身。这里复用 macOS Big Sur+ 的图标网格:内容缩放到 824x824,居中
- * 放入 1024x1024 透明画布,并套 185.4px 圆角遮罩。
+ * 资源本身;但 Windows 任务栏已经提供固定图标槽,不应再复用 macOS Big Sur+
+ * 的 100px 安全区。这里让内容占满 1024x1024 画布,只在四角套圆角遮罩,避免
+ * 24px 任务栏档位里的主体被二次缩小。
*
* 条目结构与现行 icon.ico 逐项对齐,**不要改动尺寸档位或顺序**:
* 16 / 24 / 32 / 48 / 64 / 128 / 256,全部 32bpp 未压缩 BMP(XOR 位图 + AND 掩码)。
@@ -35,9 +36,8 @@ const masterPath = process.argv[2] ?? path.join(resourcesDir, 'icon-master-1024.
const outPath = process.argv[3] ?? defaultOutPath;
const CANVAS = 1024;
-const CONTENT = 824;
-const RADIUS = 185.4;
-const MARGIN = (CANVAS - CONTENT) / 2;
+// 保留 macOS 模板的圆角比例(185.4 / 824),但不保留 macOS 外边距。
+const RADIUS = 230.4;
// 与现行 icon.ico 一致的尺寸档位(小 → 大)。
const SIZES = [16, 24, 32, 48, 64, 128, 256];
@@ -86,28 +86,17 @@ function encodeBmpEntry(rgba, size) {
return Buffer.concat([header, xor, and]);
}
-/** 把满幅母版处理成与 macOS 一致的透明圆角图标画布。 */
+/** 把满幅母版处理成 Windows 专用的满画布透明圆角图标。 */
async function createRoundedMaster() {
const roundedMask = Buffer.from(
- `<svg width="${CONTENT}" height="${CONTENT}"><rect width="${CONTENT}" height="${CONTENT}" rx="${RADIUS}" ry="${RADIUS}" fill="#fff"/></svg>`,
+ `<svg width="${CANVAS}" height="${CANVAS}"><rect width="${CANVAS}" height="${CANVAS}" rx="${RADIUS}" ry="${RADIUS}" fill="#fff"/></svg>`,
);
- const content = await sharp(masterPath)
- .resize(CONTENT, CONTENT, { fit: 'cover' })
+ return sharp(masterPath)
+ .resize(CANVAS, CANVAS, { fit: 'cover' })
.ensureAlpha()
.composite([{ input: roundedMask, blend: 'dest-in' }])
.png()
.toBuffer();
-
- return sharp(content)
- .extend({
- top: MARGIN,
- bottom: MARGIN,
- left: MARGIN,
- right: MARGIN,
- background: { r: 0, g: 0, b: 0, alpha: 0 },
- })
- .png()
- .toBuffer();
}
/**
diff --git a/apps/desktop/src/main/__tests__/windowsIconAssets.test.ts b/apps/desktop/src/main/__tests__/windowsIconAssets.test.ts
new file mode 100644
index 0000000000..7b47aaee06
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/windowsIconAssets.test.ts
@@ -0,0 +1,120 @@
+import { execFileSync } from 'node:child_process';
+import * as fs from 'node:fs';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import sharp from 'sharp';
+import { describe, expect, it } from 'vitest';
+
+const desktopRoot = path.resolve(__dirname, '../../..');
+const resourcesDir = path.join(desktopRoot, 'resources');
+const updaterIconsDir = path.join(desktopRoot, 'cindy-updater', 'src-tauri', 'icons');
+
+interface DecodedIcoEntry {
+ size: number;
+ rgba: Buffer;
+}
+
+function decodeIcoEntries(ico: Buffer): DecodedIcoEntry[] {
+ const count = ico.readUInt16LE(4);
+ const entries: DecodedIcoEntry[] = [];
+
+ for (let index = 0; index < count; index++) {
+ const directoryOffset = 6 + index * 16;
+ const width = ico[directoryOffset] || 256;
+ const height = ico[directoryOffset + 1] || 256;
+ const bitmapOffset = ico.readUInt32LE(directoryOffset + 12);
+ const rgba = Buffer.alloc(width * height * 4);
+ const pixelOffset = bitmapOffset + 40;
+
+ for (let y = 0; y < height; y++) {
+ for (let x = 0; x < width; x++) {
+ const source = pixelOffset + ((height - 1 - y) * width + x) * 4;
+ const target = (y * width + x) * 4;
+ rgba[target] = ico[source + 2];
+ rgba[target + 1] = ico[source + 1];
+ rgba[target + 2] = ico[source];
+ rgba[target + 3] = ico[source + 3];
+ }
+ }
+
+ entries.push({ size: width, rgba });
+ }
+
+ return entries;
+}
+
+function alphaBounds(rgba: Buffer, width: number, height: number, threshold = 128) {
+ let minX = width;
+ let minY = height;
+ let maxX = -1;
+ let maxY = -1;
+
+ for (let y = 0; y < height; y++) {
+ for (let x = 0; x < width; x++) {
+ if (rgba[(y * width + x) * 4 + 3] >= threshold) {
+ minX = Math.min(minX, x);
+ minY = Math.min(minY, y);
+ maxX = Math.max(maxX, x);
+ maxY = Math.max(maxY, y);
+ }
+ }
+ }
+
+ return { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 };
+}
+
+function alphaAt(rgba: Buffer, size: number, x: number, y: number) {
+ return rgba[(y * size + x) * 4 + 3];
+}
+
+describe('Windows icon assets', () => {
+ it('fill the taskbar canvas while preserving rounded corners and synchronized updater assets', async () => {
+ const fixtureDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-win-icon-'));
+ const generatedIcoPath = path.join(fixtureDir, 'icon.ico');
+ const mainIcoPath = path.join(resourcesDir, 'icon.ico');
+ const mainPngPath = path.join(resourcesDir, 'icon.png');
+ const updaterIcoPath = path.join(updaterIconsDir, 'icon.ico');
+ const updaterPngPath = path.join(updaterIconsDir, 'icon.png');
+
+ try {
+ execFileSync(process.execPath, [
+ path.join(desktopRoot, 'scripts', 'generate-win-ico.mjs'),
+ path.join(resourcesDir, 'icon-master-1024.png'),
+ generatedIcoPath,
+ ]);
+
+ const mainIco = fs.readFileSync(mainIcoPath);
+ expect(mainIco).toEqual(fs.readFileSync(generatedIcoPath));
+ expect(mainIco).toEqual(fs.readFileSync(updaterIcoPath));
+ expect(fs.readFileSync(mainPngPath)).toEqual(fs.readFileSync(updaterPngPath));
+
+ const entries = decodeIcoEntries(mainIco);
+ expect(entries.map(({ size }) => size)).toEqual([16, 24, 32, 48, 64, 128, 256]);
+
+ const taskbarEntry = entries.find(({ size }) => size === 24);
+ expect(taskbarEntry).toBeDefined();
+ expect(alphaBounds(taskbarEntry!.rgba, 24, 24)).toEqual({
+ x: 0,
+ y: 0,
+ width: 24,
+ height: 24,
+ });
+ expect(alphaAt(taskbarEntry!.rgba, 24, 0, 0)).toBeLessThan(128);
+ expect(alphaAt(taskbarEntry!.rgba, 24, 12, 0)).toBeGreaterThanOrEqual(128);
+
+ const png = await sharp(mainPngPath).ensureAlpha().raw().toBuffer({
+ resolveWithObject: true,
+ });
+ expect(alphaBounds(png.data, png.info.width, png.info.height)).toEqual({
+ x: 0,
+ y: 0,
+ width: 512,
+ height: 512,
+ });
+ expect(alphaAt(png.data, 512, 0, 0)).toBeLessThan(128);
+ expect(alphaAt(png.data, 512, 256, 0)).toBeGreaterThanOrEqual(128);
+ } finally {
+ fs.rmSync(fixtureDir, { recursive: true, force: true });
+ }
+ });
+});