-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture-icon.js
More file actions
54 lines (44 loc) · 1.35 KB
/
capture-icon.js
File metadata and controls
54 lines (44 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { app, BrowserWindow } = require('electron');
const path = require('path');
const fs = require('fs');
app.disableHardwareAcceleration(); // Often needed in headless envs
app.on('ready', async () => {
try {
console.log('Launching browser window...');
const win = new BrowserWindow({
width: 1024,
height: 1024,
show: false,
frame: false,
transparent: true,
webPreferences: {
offscreen: true,
nodeIntegration: true,
contextIsolation: false
}
});
const htmlPath = path.join(__dirname, 'public', 'logo-render.html');
console.log(`Loading ${htmlPath}`);
await win.loadFile(htmlPath);
console.log('Waiting for render...');
// Wait for rendering
setTimeout(async () => {
try {
console.log('Capturing page...');
const image = await win.capturePage();
const buffer = image.toPNG();
const outputPath = path.join(__dirname, 'src', 'assets', 'icon.png');
console.log(`Writing to ${outputPath} (${buffer.length} bytes)`);
fs.writeFileSync(outputPath, buffer);
console.log('Done.');
app.quit();
} catch (err) {
console.error('Capture failed:', err);
app.exit(1);
}
}, 2000);
} catch (err) {
console.error('Setup failed:', err);
app.exit(1);
}
});