Files
client/scripts/render-icon.cjs
T
omar 7287fdb63e
ci / linux-x64 (push) Failing after 1m26s
ci / linux-arm64-cross (push) Failing after 2m20s
TeamsPeach desktop client: Electron UI, Rust core bridge, TS6 stream viewer, CI
2026-10-24 03:31:54 +03:00

32 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Rasterizes build/icon.svg to build/icon.png (512×512, transparent) and app/renderer/assets/icon.png
// with Electron's own renderer, so no extra image tooling is needed.
// npx electron scripts/render-icon.cjs
const { app, BrowserWindow } = require('electron');
const fs = require('node:fs');
const path = require('node:path');
const root = path.resolve(__dirname, '..');
const svg = fs.readFileSync(path.join(root, 'build', 'icon.svg'), 'utf8');
app.whenReady().then(async () => {
const win = new BrowserWindow({
width: 512,
height: 512,
show: false,
transparent: true,
frame: false,
webPreferences: { offscreen: true },
});
win.webContents.setFrameRate(1);
const html = `<!doctype html><html><body style="margin:0;background:transparent">${svg.replace('<svg ', '<svg width="512" height="512" ')}</body></html>`;
await win.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(html)}`);
await new Promise((r) => setTimeout(r, 300));
const image = await win.webContents.capturePage({ x: 0, y: 0, width: 512, height: 512 });
const png = image.resize({ width: 512, height: 512 }).toPNG();
fs.writeFileSync(path.join(root, 'build', 'icon.png'), png);
fs.mkdirSync(path.join(root, 'app', 'renderer', 'assets'), { recursive: true });
fs.writeFileSync(path.join(root, 'app', 'renderer', 'assets', 'icon.png'), image.resize({ width: 256, height: 256 }).toPNG());
console.log('icon written');
app.quit();
});