Dark theme by default (stored choices kept); updateChannel pref; new peach icon (transparent); packaged device evidence
This commit is contained in:
1 parent
41e90fb5e8
commit
456041bfde
15 files changed
+363
-45
No files matched your search
+47
-37
@@ -1,5 +1,6 @@
|
||||
// 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.
|
||||
// Exports the transparent SVG master to build/icon.png (512), the runtime PNG (256),
|
||||
// and a seven-size Windows ICO. Draw each size directly to a transparent canvas:
|
||||
// window capture can include scrollbars and depends on the host display scaling.
|
||||
// npx electron scripts/render-icon.cjs
|
||||
const { app, BrowserWindow } = require('electron');
|
||||
const fs = require('node:fs');
|
||||
@@ -10,41 +11,50 @@ 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 },
|
||||
webPreferences: { offscreen: true, contextIsolation: true, nodeIntegration: false },
|
||||
});
|
||||
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());
|
||||
// Windows icon with PNG-compressed entries, so packaging needs no image conversion tool.
|
||||
const sizes = [16, 24, 32, 48, 64, 128, 256];
|
||||
const pngs = sizes.map((s) => image.resize({ width: s, height: s, quality: 'best' }).toPNG());
|
||||
const header = Buffer.alloc(6 + 16 * sizes.length);
|
||||
header.writeUInt16LE(0, 0);
|
||||
header.writeUInt16LE(1, 2);
|
||||
header.writeUInt16LE(sizes.length, 4);
|
||||
let offset = header.length;
|
||||
sizes.forEach((s, i) => {
|
||||
const e = 6 + 16 * i;
|
||||
header.writeUInt8(s === 256 ? 0 : s, e);
|
||||
header.writeUInt8(s === 256 ? 0 : s, e + 1);
|
||||
header.writeUInt16LE(1, e + 4);
|
||||
header.writeUInt16LE(32, e + 6);
|
||||
header.writeUInt32LE(pngs[i].length, e + 8);
|
||||
header.writeUInt32LE(offset, e + 12);
|
||||
offset += pngs[i].length;
|
||||
});
|
||||
fs.writeFileSync(path.join(root, 'build', 'icon.ico'), Buffer.concat([header, ...pngs]));
|
||||
console.log('icon written');
|
||||
app.quit();
|
||||
try {
|
||||
await win.loadURL('data:text/html;charset=utf-8,<!doctype html><html></html>');
|
||||
const sizes = [16, 24, 32, 48, 64, 128, 256];
|
||||
const source = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
||||
const encoded = await win.webContents.executeJavaScript(`(async () => {
|
||||
const image = new Image();
|
||||
image.src = ${JSON.stringify(source)};
|
||||
await image.decode();
|
||||
return ${JSON.stringify([...sizes, 512])}.map((size) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = canvas.height = size;
|
||||
canvas.getContext('2d').drawImage(image, 0, 0, size, size);
|
||||
return canvas.toDataURL('image/png').split(',')[1];
|
||||
});
|
||||
})()`);
|
||||
const pngs = encoded.map((data) => Buffer.from(data, 'base64'));
|
||||
fs.writeFileSync(path.join(root, 'build', 'icon.png'), pngs.pop());
|
||||
fs.mkdirSync(path.join(root, 'app', 'renderer', 'assets'), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, 'app', 'renderer', 'assets', 'icon.png'), pngs.at(-1));
|
||||
// PNG-compressed RGBA entries preserve alpha at every Windows icon size.
|
||||
const header = Buffer.alloc(6 + 16 * sizes.length);
|
||||
header.writeUInt16LE(0, 0);
|
||||
header.writeUInt16LE(1, 2);
|
||||
header.writeUInt16LE(sizes.length, 4);
|
||||
let offset = header.length;
|
||||
sizes.forEach((s, i) => {
|
||||
const e = 6 + 16 * i;
|
||||
header.writeUInt8(s === 256 ? 0 : s, e);
|
||||
header.writeUInt8(s === 256 ? 0 : s, e + 1);
|
||||
header.writeUInt16LE(1, e + 4);
|
||||
header.writeUInt16LE(32, e + 6);
|
||||
header.writeUInt32LE(pngs[i].length, e + 8);
|
||||
header.writeUInt32LE(offset, e + 12);
|
||||
offset += pngs[i].length;
|
||||
});
|
||||
fs.writeFileSync(path.join(root, 'build', 'icon.ico'), Buffer.concat([header, ...pngs]));
|
||||
console.log('Icons exported: build/icon.png (512), app/renderer/assets/icon.png (256), build/icon.ico (16/24/32/48/64/128/256).');
|
||||
} finally {
|
||||
win.destroy();
|
||||
}
|
||||
}).then(() => app.quit()).catch((error) => {
|
||||
console.error(error);
|
||||
app.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user