#!/usr/bin/env node /* * Generates every brand icon asset the desktop client needs from the single * source of truth: public/logo.svg. * * Outputs: * build/icon.icns macOS app icon (electron-builder) * build/icon.png Linux app icon + Windows/icns fallback (1024x1024) * build/icon.ico Windows app icon * src/main/brand-icons.ts base64 icons consumed by the main process * (tray + dock + window + Windows overlay) * * Re-run after changing public/logo.svg: * node scripts/generate-brand-icons.cjs * * Requires `rsvg-convert`, `sips` and `iconutil` (preinstalled on macOS via * librsvg + the system toolchain). */ const { execFileSync } = require('node:child_process') const fs = require('node:fs') const os = require('node:os') const path = require('node:path') const APP_DIR = path.resolve(__dirname, '..') const LOGO_PATH = path.join(APP_DIR, 'public', 'logo.svg') const BUILD_DIR = path.join(APP_DIR, 'build') const OUT_TS = path.join(APP_DIR, 'src', 'main', 'brand-icons.ts') // Brand palette — keep in sync with the renderer (#1677ff is Ant Design blue). const BRAND_BLUE = '#1677ff' const DANGER_RED = '#ff4d4f' const LOGO_FILL = '#dfdfdf' // the fill baked into logo.svg const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'brand-icons-')) const cleanup = () => fs.rmSync(tmpDir, { recursive: true, force: true }) function rsvg(args) { return execFileSync('rsvg-convert', args) } /** Extract the inner markup (the elements) and viewBox from logo.svg. */ function readLogo() { const raw = fs.readFileSync(LOGO_PATH, 'utf8') const viewBox = (raw.match(/viewBox="([^"]+)"/) || [])[1] const inner = (raw.match(/]*>([\s\S]*)<\/svg>/) || [])[1] if (!viewBox || !inner) { throw new Error('Could not parse public/logo.svg (missing viewBox or body)') } const [, , vbW, vbH] = viewBox.split(/\s+/).map(Number) return { inner: inner.trim(), width: vbW, height: vbH } } const logo = readLogo() /** A square app icon: logo centered on a rounded-rect (squircle-ish) bg. */ function squareIconSvg(bg) { const CANVAS = 1024 // macOS icon grid: 824x824 art area inside a 1024 canvas (100px margin). const PLATE = 824 const MARGIN = (CANVAS - PLATE) / 2 const targetW = PLATE * 0.62 const scale = targetW / logo.width const drawnW = logo.width * scale const drawnH = logo.height * scale const tx = MARGIN + (PLATE - drawnW) / 2 const ty = MARGIN + (PLATE - drawnH) / 2 return ` ${logo.inner} ` } /** * Tray glyph: the logo centered (with padding) inside a 32px square canvas. * tray.ts loads it with scaleFactor 2, so it shows at ~16pt on retina menu * bars. Padding keeps the wide/landscape mark from touching the canvas edges. */ function trayLogoSvg(fill) { const CANVAS = 32 // tray asset is 32x32 px // Glyph height inside the 32px canvas — the single knob for tray size. // Bump up for a larger glyph, down for a smaller one. const targetH = 20 const scale = targetH / logo.height const drawnW = logo.width * scale const drawnH = logo.height * scale const tx = (CANVAS - drawnW) / 2 const ty = (CANVAS - drawnH) / 2 const inner = fill ? logo.inner.split(LOGO_FILL).join(fill) : logo.inner return ` ${inner} ` } function svgToPng(svg, name, extraArgs = []) { const svgPath = path.join(tmpDir, `${name}.svg`) const pngPath = path.join(tmpDir, `${name}.png`) fs.writeFileSync(svgPath, svg) rsvg([...extraArgs, '-o', pngPath, svgPath]) return pngPath } function b64(pngPath) { return fs.readFileSync(pngPath).toString('base64') } /** * Wrap N square PNG buffers into a multi-image (PNG-payload) .ico container. * Windows picks the closest size when rendering at 16/24/32/48/256 px, so a * single 256px entry forces a blurry downscale in the taskbar/Explorer — and * the old rcedit electron-builder ships with mis-stamps some single-entry ICOs. * Embedding every common size keeps the app icon crisp at all of them. */ function pngsToIco(pngBuffers) { const count = pngBuffers.length const header = Buffer.alloc(6) header.writeUInt16LE(0, 0) // reserved header.writeUInt16LE(1, 2) // type: icon header.writeUInt16LE(count, 4) // image count const dir = Buffer.alloc(16 * count) let offset = 6 + 16 * count pngBuffers.forEach((png, i) => { const w = png.readUInt32BE(16) // PNG IHDR width (byte 16..19) const h = png.readUInt32BE(20) // PNG IHDR height (byte 20..23) const e = i * 16 dir.writeUInt8(w >= 256 ? 0 : w, e + 0) // width (0 => 256) dir.writeUInt8(h >= 256 ? 0 : h, e + 1) // height (0 => 256) dir.writeUInt8(0, e + 2) // palette dir.writeUInt8(0, e + 3) // reserved dir.writeUInt16LE(1, e + 4) // color planes dir.writeUInt16LE(32, e + 6) // bits per pixel dir.writeUInt32LE(png.length, e + 8) // size of image data dir.writeUInt32LE(offset, e + 12) // offset to image data offset += png.length }) return Buffer.concat([header, dir, ...pngBuffers]) } function buildAppIcons() { // 1024 master for the normal app icon. const masterPng = svgToPng(squareIconSvg(BRAND_BLUE), 'app-normal', ['-w', '1024', '-h', '1024']) fs.mkdirSync(BUILD_DIR, { recursive: true }) fs.copyFileSync(masterPng, path.join(BUILD_DIR, 'icon.png')) // .icns via an .iconset downscaled with sips. const iconset = path.join(tmpDir, 'icon.iconset') fs.mkdirSync(iconset, { recursive: true }) const variants = [ [16, 'icon_16x16.png'], [32, 'icon_16x16@2x.png'], [32, 'icon_32x32.png'], [64, 'icon_32x32@2x.png'], [128, 'icon_128x128.png'], [256, 'icon_128x128@2x.png'], [256, 'icon_256x256.png'], [512, 'icon_256x256@2x.png'], [512, 'icon_512x512.png'], [1024, 'icon_512x512@2x.png'], ] for (const [size, file] of variants) { const dest = path.join(iconset, file) execFileSync('sips', ['-z', String(size), String(size), masterPng, '--out', dest], { stdio: 'ignore', }) } execFileSync('iconutil', ['-c', 'icns', iconset, '-o', path.join(BUILD_DIR, 'icon.icns')]) // .ico with every size Windows asks for (taskbar/Explorer/Alt-Tab/tiles). const icoSizes = [16, 24, 32, 48, 64, 128, 256] const icoPngs = icoSizes.map((s) => fs.readFileSync(svgToPng(squareIconSvg(BRAND_BLUE), `app-ico-${s}`, ['-w', String(s), '-h', String(s)])), ) fs.writeFileSync(path.join(BUILD_DIR, 'icon.ico'), pngsToIco(icoPngs)) } function buildMainProcessIcons() { // Tray icons are 32x32 px and loaded @2x in tray.ts (=> ~16pt on retina). // Glyph size is controlled by targetH in trayLogoSvg(), not by an rsvg -h. const trayNormal = b64(svgToPng(trayLogoSvg(), 'tray-normal')) const trayWindows = b64(svgToPng(trayLogoSvg(BRAND_BLUE), 'tray-windows')) const trayDanger = b64(svgToPng(trayLogoSvg(DANGER_RED), 'tray-danger')) // Dock / window icons: logo on the brand plate (normal) and danger plate. const appNormal = b64(svgToPng(squareIconSvg(BRAND_BLUE), 'dock-normal', ['-w', '512', '-h', '512'])) const appDanger = b64(svgToPng(squareIconSvg(DANGER_RED), 'dock-danger', ['-w', '512', '-h', '512'])) // Windows taskbar overlay: a small danger badge (status cue, not the logo). const overlaySvg = ` ` const overlay = b64(svgToPng(overlaySvg, 'win-overlay')) const banner = `// AUTO-GENERATED from public/logo.svg by scripts/generate-brand-icons.cjs. // Do not edit by hand — run \`node scripts/generate-brand-icons.cjs\` instead. /* eslint-disable */ /* prettier-ignore-start */` const body = [ banner, '', '// macOS menu-bar template silhouette (rendered @2x).', `export const TRAY_ICON_BASE64 =\n '${trayNormal}'`, '', '// Windows tray icon: brand-blue silhouette for light tray flyouts.', `export const TRAY_WINDOWS_ICON_BASE64 =\n '${trayWindows}'`, '', '// Tray icon shown when accounts have health issues (rendered @2x, not a template).', `export const TRAY_DANGER_ICON_BASE64 =\n '${trayDanger}'`, '', '// Dock / window icon — logo on the brand-blue plate.', `export const APP_ICON_NORMAL_BASE64 =\n '${appNormal}'`, '', '// Dock / window icon — logo on a danger plate when issues exist.', `export const APP_ICON_DANGER_BASE64 =\n '${appDanger}'`, '', '// Small Windows taskbar overlay badge signalling account health issues.', `export const WINDOWS_OVERLAY_ICON_BASE64 =\n '${overlay}'`, '/* prettier-ignore-end */', '', ].join('\n') fs.writeFileSync(OUT_TS, body) } try { buildAppIcons() buildMainProcessIcons() console.log('✓ build/icon.icns, build/icon.png, build/icon.ico') console.log('✓ src/main/brand-icons.ts') } finally { cleanup() }