diff --git a/CHANGELOG.md b/CHANGELOG.md index d7121eac..271965ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to DreamCoder will be documented in this file. ### Changed +- **New app icon.** The app, Dock, taskbar and tray icons and the logo inside the app are redrawn: a warm-white crescent prompt and an amber star on an ink-blue tile. On macOS the menu bar icon is now a template image, so it follows the light or dark menu bar. The interface colors are unchanged. (#292) - Thinking text in a streaming reply is batched like the reply text, so a long thinking block updates the conversation once per 50 ms instead of on every chunk (#258). Thanks @iruzen-dono. - **Providers in OpenAI format reuse their prompt cache.** Later turns of a session now hit the cache for about 99% of the input (measured on OpenRouter with GPT-4.1 mini and GLM-4.6), and cache hits that DeepSeek and Moonshot report are counted as cache reads (#262). - Providers in OpenAI format can run several tool calls in one step and get tool definitions without schema fields they do not use, and replies show the model you chose instead of the dated version the provider reports (#262). diff --git a/desktop/electron-builder.json b/desktop/electron-builder.json index 4884361e..476c8e1c 100644 --- a/desktop/electron-builder.json +++ b/desktop/electron-builder.json @@ -30,8 +30,11 @@ "to": "web-clone" }, { - "from": "electron/build/icons/tray.png", - "to": "icons/tray.png" + "from": "electron/build/icons", + "to": "icons", + "filter": [ + "tray*.png" + ] }, { "from": "../THIRD_PARTY_NOTICES.md", diff --git a/desktop/electron/build/app-icon-macos.svg b/desktop/electron/build/app-icon-macos.svg deleted file mode 100644 index 05a6e427..00000000 --- a/desktop/electron/build/app-icon-macos.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/desktop/electron/build/app-icon-small.svg b/desktop/electron/build/app-icon-small.svg new file mode 100644 index 00000000..9e3896e5 --- /dev/null +++ b/desktop/electron/build/app-icon-small.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/desktop/electron/build/app-icon-tile.svg b/desktop/electron/build/app-icon-tile.svg new file mode 100644 index 00000000..b4c087cf --- /dev/null +++ b/desktop/electron/build/app-icon-tile.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/desktop/electron/build/app-icon.png b/desktop/electron/build/app-icon.png index 6a6440a3..eb257fad 100644 Binary files a/desktop/electron/build/app-icon.png and b/desktop/electron/build/app-icon.png differ diff --git a/desktop/electron/build/app-icon.svg b/desktop/electron/build/app-icon.svg index ceb86acf..0e891b34 100644 --- a/desktop/electron/build/app-icon.svg +++ b/desktop/electron/build/app-icon.svg @@ -1,10 +1,51 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/desktop/electron/build/icons/icon.icns b/desktop/electron/build/icons/icon.icns index 77138af6..db1f6603 100644 Binary files a/desktop/electron/build/icons/icon.icns and b/desktop/electron/build/icons/icon.icns differ diff --git a/desktop/electron/build/icons/icon.ico b/desktop/electron/build/icons/icon.ico index 2bef74bf..326d4012 100644 Binary files a/desktop/electron/build/icons/icon.ico and b/desktop/electron/build/icons/icon.ico differ diff --git a/desktop/electron/build/icons/tray.png b/desktop/electron/build/icons/tray.png index 0ec85ba8..6757c5c7 100644 Binary files a/desktop/electron/build/icons/tray.png and b/desktop/electron/build/icons/tray.png differ diff --git a/desktop/electron/build/icons/tray@2x.png b/desktop/electron/build/icons/tray@2x.png new file mode 100644 index 00000000..5baecc34 Binary files /dev/null and b/desktop/electron/build/icons/tray@2x.png differ diff --git a/desktop/electron/build/icons/trayTemplate.png b/desktop/electron/build/icons/trayTemplate.png new file mode 100644 index 00000000..ea9d9c43 Binary files /dev/null and b/desktop/electron/build/icons/trayTemplate.png differ diff --git a/desktop/electron/build/icons/trayTemplate@2x.png b/desktop/electron/build/icons/trayTemplate@2x.png new file mode 100644 index 00000000..4ddcb068 Binary files /dev/null and b/desktop/electron/build/icons/trayTemplate@2x.png differ diff --git a/desktop/electron/build/tray-icon.svg b/desktop/electron/build/tray-icon.svg new file mode 100644 index 00000000..9a0a4622 --- /dev/null +++ b/desktop/electron/build/tray-icon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts index 30dea8b0..1e306c7e 100644 --- a/desktop/electron/main.ts +++ b/desktop/electron/main.ts @@ -86,6 +86,7 @@ const CONTENT_SECURITY_POLICY = [ const WINDOW_STATE_SAVE_DELAY_MS = 300 const IS_MAC = process.platform === 'darwin' const IS_WINDOWS = process.platform === 'win32' +const TRAY_ICON = IS_MAC ? 'trayTemplate.png' : 'tray.png' protocol.registerSchemesAsPrivileged([ { scheme: APP_SCHEME, privileges: { standard: true, secure: true, supportFetchAPI: true, corsEnabled: true } }, @@ -136,7 +137,7 @@ function resolvePaths(): AppPaths { h5DistDir: dist, webDist: dist, artifactShellDir: path.join(dist, ARTIFACT_SHELL_DIRNAME), - trayIcon: path.join(process.resourcesPath, 'icons', 'tray.png'), + trayIcon: path.join(process.resourcesPath, 'icons', TRAY_ICON), } } const desktopRoot = path.resolve(app.getAppPath(), '..') @@ -146,7 +147,7 @@ function resolvePaths(): AppPaths { h5DistDir: dist, webDist: dist, artifactShellDir: path.join(desktopRoot, 'public', ARTIFACT_SHELL_DIRNAME), - trayIcon: path.join(desktopRoot, 'electron', 'build', 'icons', 'tray.png'), + trayIcon: path.join(desktopRoot, 'electron', 'build', 'icons', TRAY_ICON), } } @@ -574,7 +575,7 @@ function installTray(iconPath: string) { console.error(`[electron] tray icon not found at ${iconPath}`) return } - tray = new Tray(image.resize({ width: IS_MAC ? 18 : 16, height: IS_MAC ? 18 : 16 })) + tray = new Tray(image) tray.setToolTip('DreamCoder') const menu = Menu.buildFromTemplate([ { label: 'Show DreamCoder', click: showMainWindow }, diff --git a/desktop/package.json b/desktop/package.json index 87447891..586377a4 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -22,6 +22,7 @@ "build:showai-reader": "bun ../vendor/showai/build-reader.ts dist/showai-reader", "build:sidecars": "bun run ./scripts/build-sidecars.ts", "build:electron": "bun run ./scripts/build-electron.ts", + "build:icons": "bun run ./scripts/generate-icons.ts", "electron:install": "node node_modules/electron/install.js", "electron:dev": "bun run ./scripts/electron-dev.ts", "electron:start": "bun run build:electron && electron electron-dist", diff --git a/desktop/public/app-icon.png b/desktop/public/app-icon.png index 6a6440a3..eb257fad 100644 Binary files a/desktop/public/app-icon.png and b/desktop/public/app-icon.png differ diff --git a/desktop/public/app-icon.svg b/desktop/public/app-icon.svg deleted file mode 100644 index ceb86acf..00000000 --- a/desktop/public/app-icon.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/desktop/scripts/generate-icons.test.ts b/desktop/scripts/generate-icons.test.ts new file mode 100644 index 00000000..f30cae56 --- /dev/null +++ b/desktop/scripts/generate-icons.test.ts @@ -0,0 +1,76 @@ +import { existsSync, readFileSync } from 'node:fs' +import path from 'node:path' + +import { Resvg } from '@resvg/resvg-js' +import { describe, expect, it } from 'vitest' + +import { onMacGrid, packIco, pixelTile, render, tileOnly } from './generate-icons' + +const buildDir = path.resolve(import.meta.dirname, '..', 'electron', 'build') +const master = (name: string) => readFileSync(path.join(buildDir, name), 'utf8') + +function pngSize(png: Uint8Array) { + const view = new DataView(png.buffer, png.byteOffset, png.byteLength) + return [view.getUint32(16), view.getUint32(20)] +} + +function alphaAt(svg: string, size: number, x: number, y: number) { + const pixels = new Uint8Array(new Resvg(svg, { fitTo: { mode: 'width', value: size }, font: { loadSystemFonts: false } }).render().pixels) + return pixels[(y * size + x) * 4 + 3] +} + +describe('generate-icons', () => { + it('packs PNG images into an ICO directory with 256 stored as 0', () => { + const images = [16, 256].map((size) => ({ size, png: render(master('app-icon-small.svg'), size) })) + const ico = packIco(images) + const view = new DataView(ico.buffer) + expect(view.getUint16(2, true)).toBe(1) + expect(view.getUint16(4, true)).toBe(2) + expect(view.getUint8(6)).toBe(16) + expect(view.getUint8(22)).toBe(0) + images.forEach((image, index) => { + const entry = 6 + index * 16 + const length = view.getUint32(entry + 8, true) + const offset = view.getUint32(entry + 12, true) + expect(length).toBe(image.png.length) + expect(ico.slice(offset, offset + length)).toEqual(new Uint8Array(image.png)) + }) + }) + + it('sizes the macOS grid tile to the nearest whole pixels that keep it centred', () => { + expect(pixelTile(16)).toEqual({ tile: 12, offset: 2 }) + expect(pixelTile(32)).toEqual({ tile: 26, offset: 3 }) + expect(pixelTile(64)).toEqual({ tile: 52, offset: 6 }) + }) + + it('places the simplified master inside the macOS icon grid with sharp tile edges', () => { + for (const pixels of [16, 32, 64]) { + const grid = onMacGrid(master('app-icon-small.svg'), pixels) + const { tile, offset } = pixelTile(pixels) + const middle = Math.floor(pixels / 2) + expect(pngSize(render(grid, pixels))).toEqual([pixels, pixels]) + expect(alphaAt(grid, pixels, offset - 1, middle)).toBe(0) + expect(alphaAt(grid, pixels, offset, middle)).toBe(255) + expect(alphaAt(grid, pixels, offset + tile - 1, middle)).toBe(255) + expect(alphaAt(grid, pixels, offset + tile, middle)).toBe(0) + expect(alphaAt(grid, pixels, middle, offset - 1)).toBe(0) + expect(alphaAt(grid, pixels, middle, offset)).toBe(255) + } + }) + + it('crops the finished master to its tile without the drop shadow', () => { + const tile = tileOnly(master('app-icon.svg')) + expect(alphaAt(tile, 103, 51, 51)).toBe(255) + expect(alphaAt(tile, 103, 0, 102)).toBe(0) + }) + + it('keeps the in-app tile in step with the finished master', () => { + expect(master('app-icon-tile.svg')).toBe(`${tileOnly(master('app-icon.svg'))}\n`) + }) + + it('ships every tray image the app loads', () => { + for (const name of ['tray.png', 'tray@2x.png', 'trayTemplate.png', 'trayTemplate@2x.png']) { + expect(existsSync(path.join(buildDir, 'icons', name))).toBe(true) + } + }) +}) diff --git a/desktop/scripts/generate-icons.ts b/desktop/scripts/generate-icons.ts new file mode 100644 index 00000000..02d94bdc --- /dev/null +++ b/desktop/scripts/generate-icons.ts @@ -0,0 +1,134 @@ +import { spawnSync } from 'node:child_process' +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import path from 'node:path' + +import { Resvg } from '@resvg/resvg-js' + +export type IconImage = { size: number; png: Uint8Array } + +const desktopRoot = path.resolve(import.meta.dirname, '..') +const buildDir = path.join(desktopRoot, 'electron', 'build') +const iconsDir = path.join(buildDir, 'icons') + +const MAC_TILE = { offset: 100, size: 824, canvas: 1024, radius: 185 } +const ICO_SIZES = [16, 24, 32, 48, 64, 128, 256] +const ICO_SMALL_MAX = 32 +const ICONSET: Array<{ name: string; size: number; small: boolean }> = [ + { name: 'icon_16x16', size: 16, small: true }, + { name: 'icon_16x16@2x', size: 32, small: true }, + { name: 'icon_32x32', size: 32, small: true }, + { name: 'icon_32x32@2x', size: 64, small: true }, + { name: 'icon_128x128', size: 128, small: false }, + { name: 'icon_128x128@2x', size: 256, small: false }, + { name: 'icon_256x256', size: 256, small: false }, + { name: 'icon_256x256@2x', size: 512, small: false }, + { name: 'icon_512x512', size: 512, small: false }, + { name: 'icon_512x512@2x', size: 1024, small: false }, +] + +function svgParts(svg: string) { + const match = svg.match(/]*\bviewBox="([^"]+)"[^>]*>([\s\S]*)<\/svg>\s*$/) + if (!match?.[1] || !match[2]) throw new Error('master SVG needs a root with a viewBox') + return { viewBox: match[1], body: match[2] } +} + +export function pixelTile(pixels: number) { + const { size, canvas } = MAC_TILE + const parity = pixels % 2 + const tile = Math.round((pixels * size / canvas - parity) / 2) * 2 + parity + return { tile, offset: (pixels - tile) / 2 } +} + +export function onMacGrid(smallSvg: string, pixels: number) { + const { viewBox, body } = svgParts(smallSvg) + const { tile, offset } = pixelTile(pixels) + return `${body}` +} + +export function tileOnly(appSvg: string) { + const { body } = svgParts(appSvg) + const { offset, size, radius } = MAC_TILE + return `${body}` +} + +export function render(svg: string, size: number): Uint8Array { + return new Resvg(svg, { fitTo: { mode: 'width', value: size }, font: { loadSystemFonts: false } }).render().asPng() +} + +export function packIco(images: IconImage[]): Uint8Array { + const headerSize = 6 + images.length * 16 + const total = headerSize + images.reduce((sum, image) => sum + image.png.length, 0) + const out = new Uint8Array(total) + const view = new DataView(out.buffer) + view.setUint16(2, 1, true) + view.setUint16(4, images.length, true) + let offset = headerSize + images.forEach((image, index) => { + const entry = 6 + index * 16 + view.setUint8(entry, image.size >= 256 ? 0 : image.size) + view.setUint8(entry + 1, image.size >= 256 ? 0 : image.size) + view.setUint16(entry + 4, 1, true) + view.setUint16(entry + 6, 32, true) + view.setUint32(entry + 8, image.png.length, true) + view.setUint32(entry + 12, offset, true) + out.set(image.png, offset) + offset += image.png.length + }) + return out +} + +function readMaster(name: string) { + return readFileSync(path.join(buildDir, name), 'utf8') +} + +function write(file: string, data: Uint8Array) { + writeFileSync(file, data) + console.log(`wrote ${path.relative(desktopRoot, file)}`) +} + +function writeIcns(file: string, imageFor: (size: number, small: boolean) => Uint8Array) { + if (process.platform !== 'darwin') throw new Error('icon.icns is built with iconutil, which only runs on macOS') + const workDir = mkdtempSync(path.join(tmpdir(), 'dreamcoder-icons-')) + try { + const iconset = path.join(workDir, 'icon.iconset') + mkdirSync(iconset) + for (const { name, size, small } of ICONSET) { + writeFileSync(path.join(iconset, `${name}.png`), imageFor(size, small)) + } + const result = spawnSync('iconutil', ['-c', 'icns', iconset, '-o', file], { encoding: 'utf8' }) + if (result.status !== 0) throw new Error(`iconutil failed: ${result.stderr || result.error?.message}`) + console.log(`wrote ${path.relative(desktopRoot, file)}`) + } finally { + rmSync(workDir, { recursive: true, force: true }) + } +} + +function generate() { + const app = readMaster('app-icon.svg') + const small = readMaster('app-icon-small.svg') + const tray = readMaster('tray-icon.svg') + const tile = tileOnly(app) + write(path.join(buildDir, 'app-icon-tile.svg'), new TextEncoder().encode(`${tile}\n`)) + + const appPng = render(app, 1024) + write(path.join(buildDir, 'app-icon.png'), appPng) + write(path.join(desktopRoot, 'public', 'app-icon.png'), appPng) + + writeIcns(path.join(iconsDir, 'icon.icns'), (size, useSmall) => render(useSmall ? onMacGrid(small, size) : app, size)) + + write( + path.join(iconsDir, 'icon.ico'), + packIco(ICO_SIZES.map((size) => ({ + size, + png: render(size <= ICO_SMALL_MAX ? small : tile, size), + }))), + ) + + write(path.join(iconsDir, 'tray.png'), render(small, 16)) + write(path.join(iconsDir, 'tray@2x.png'), render(small, 32)) + write(path.join(iconsDir, 'trayTemplate.png'), render(tray, 18)) + write(path.join(iconsDir, 'trayTemplate@2x.png'), render(tray, 36)) +} + +if (import.meta.main) generate() diff --git a/desktop/src/components/shared/DreamCoderIcon.test.tsx b/desktop/src/components/shared/DreamCoderIcon.test.tsx new file mode 100644 index 00000000..785a6049 --- /dev/null +++ b/desktop/src/components/shared/DreamCoderIcon.test.tsx @@ -0,0 +1,22 @@ +import { render } from '@testing-library/react' +import { describe, expect, it } from 'vitest' +import detailedIcon from '../../../electron/build/app-icon-tile.svg' +import smallIcon from '../../../electron/build/app-icon-small.svg' +import { DreamCoderIcon } from './DreamCoderIcon' + +function iconSource(size: number) { + const { container } = render() + return container.querySelector('img')?.getAttribute('src') ?? '' +} + +describe('DreamCoderIcon', () => { + it('uses the simplified master at 32px and below', () => { + expect(iconSource(16)).toBe(smallIcon) + expect(iconSource(32)).toBe(smallIcon) + }) + + it('uses the detailed master from 40px up', () => { + expect(iconSource(40)).toBe(detailedIcon) + expect(iconSource(56)).toBe(detailedIcon) + }) +}) diff --git a/desktop/src/components/shared/DreamCoderIcon.tsx b/desktop/src/components/shared/DreamCoderIcon.tsx index 87656a2e..f4619ad9 100644 --- a/desktop/src/components/shared/DreamCoderIcon.tsx +++ b/desktop/src/components/shared/DreamCoderIcon.tsx @@ -1,30 +1,18 @@ -/** - * DreamCoder mark: a prompt-shaped crescent moon and a star as the cursor, - * white on a brand-coloured tile. The tile follows the theme's brand colour; - * the same artwork is in desktop/electron/build/app-icon.svg for the app icons. - */ +import detailedIcon from '../../../electron/build/app-icon-tile.svg' +import smallIcon from '../../../electron/build/app-icon-small.svg' + +const DETAIL_MIN = 40 + export function DreamCoderIcon({ size = 32, className }: { size?: number; className?: string }) { return ( - = DETAIL_MIN ? detailedIcon : smallIcon} width={size} height={size} className={className} style={{ flexShrink: 0 }} - aria-hidden="true" - > - - - - - - - - + alt="" + draggable={false} + /> ) } diff --git a/docs/features/ui-refresh/design-log.zh.md b/docs/features/ui-refresh/design-log.zh.md index a9f9aac0..6a9ff2e5 100644 --- a/docs/features/ui-refresh/design-log.zh.md +++ b/docs/features/ui-refresh/design-log.zh.md @@ -429,10 +429,22 @@ - 首次启动点完成后,即使恢复标签较慢,也停在空白新会话页。 - 设置打开时按 Esc,不会顺带退出侧栏的批量选择。 -## 新 logo(2026-10-18) +## 新 logo(2026-10-18,已被 2026-11-20 的墨蓝图标替换) 用户比较了三个方向(月牙提示符、光标星、D 字母组合)后,选择在「光标星」的基础上把 `>` 换成月亮:外侧是提示符的尖角,内侧是月亮的弧线,旁边一颗四角星作光标。按评论调整了星的大小、两者的间距,并按视觉重心居中。 - 应用图标:陶土底(#AC583C)白色标志,按 macOS 图标网格留边(1024 画布中 824 的圆角方块)。源文件 `desktop/src-tauri/app-icon.svg`,`app-icon.png` 由它渲染,各平台图标用 `tauri icon` 从它生成。 - 应用内图标 `DreamCoderIcon`:同一图形,方块颜色跟随主题的品牌色。 - 去掉了旧 logo 的渐变、发光和装饰点。 + +## 新图标:墨蓝方向 C(2026-11-20) + +维护者在三个方向(A 月牙托着光标、B D 字标、C 保留现有元素重新构图)和四种底色里选了 C 配墨蓝,替换上一节的陶土色图标。这次只换图标,界面主色仍是陶土色。 + +- 图形:月牙形的提示符居中偏左,四角星在尖角右上方,星的四角是尖的。提示符暖白,星星琥珀色。 +- 成品处理:墨蓝(#1f2a48)底板从上到下渐变,顶部有一圈高光,底板和图形各有投影,光晕从星星发出,亮度压得比较低。应用内的图标和小尺寸图标也带渐变、高光和光晕,只是没有底板外的投影。 +- 尺寸规则:显示尺寸 40 像素及以上用完整图形,32 像素及以下用加粗的简化版。 +- 母版在 `desktop/electron/build/`:`app-icon.svg` 是 1024 画布的成品版(按 macOS 网格,主体 824、圆角 185);`app-icon-small.svg` 是 32 像素及以下的简化版,提示符加粗,星星比成品版略大并靠右;`tray-icon.svg` 是 macOS 菜单栏的单色版。 +- 导出:`cd desktop && bun run build:icons` 从母版生成 `icon.icns`、`icon.ico`、`app-icon.png`(两份)、`app-icon-tile.svg` 和托盘图。`app-icon-tile.svg` 是成品版裁到底板、不带底板投影的版本,给应用内 40 像素及以上用,不要手改。macOS 的 16、32 点用简化版放进图标网格,底板取最接近 824/1024 且能居中的整数像素(16、32、64 像素分别是 12、26、52),四边不落在半像素上;Windows 的 16 到 32 像素用简化版铺满,48 像素以上用成品版裁到底板、不带投影。macOS 托盘是模板图 `trayTemplate.png`(含 @2x),其他平台用彩色的 `tray.png`(含 @2x)。`icon.icns` 用 macOS 的 `iconutil` 打包,所以这条命令只能在 macOS 上跑。 +- 应用内图标 `DreamCoderIcon` 在 40 像素及以上引用 `app-icon-tile.svg`,以下引用 `app-icon-small.svg`,颜色是图标自己的品牌色,不随主题变。 +- 以后精修只换母版,再跑一次导出。