Files
Agent-Workbench/scripts/generate-orven-icons.mjs
2026-11-06 14:08:53 +08:00

30 lines
1.6 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { chromium } from 'playwright';
// Keep the existing filenames consumed by the desktop launcher and mobile build.
const svg = fs.readFileSync(path.resolve('public/favicon.svg'), 'utf8');
const browser = await chromium.launch({ channel: 'msedge', headless: true });
try {
const page = await browser.newPage({ deviceScaleFactor: 1 });
const images = [];
for (const size of [16, 32, 48, 256]) {
await page.setViewportSize({ width: size, height: size });
await page.setContent('<style>html,body{margin:0;background:transparent}svg{display:block;width:100vw;height:100vh}</style>' + svg);
images.push({ size, bytes: await page.screenshot({ omitBackground: true }) });
}
fs.writeFileSync('public/workbench-icon.png', images.at(-1).bytes);
const header = Buffer.alloc(6 + images.length * 16);
header.writeUInt16LE(1, 2); header.writeUInt16LE(images.length, 4);
let offset = header.length;
for (let index = 0; index < images.length; index++) {
const { size, bytes } = images[index], position = 6 + index * 16;
header[position] = size === 256 ? 0 : size; header[position + 1] = size === 256 ? 0 : size;
header.writeUInt16LE(1, position + 4); header.writeUInt16LE(32, position + 6);
header.writeUInt32LE(bytes.length, position + 8); header.writeUInt32LE(offset, position + 12);
offset += bytes.length;
}
fs.writeFileSync('public/workbench-icon.ico', Buffer.concat([header, ...images.map(image => image.bytes)]));
console.log('Orven icons generated: PNG 256px; ICO 16/32/48/256px.');
} finally { await browser.close(); }