Skip to content

Commit e89be7a

Browse files
committed
RU-T47 Fixing build
1 parent ea43c72 commit e89be7a

3 files changed

Lines changed: 78 additions & 4 deletions

File tree

assets/icon.ico

19.4 KB
Binary file not shown.

electron-builder.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ module.exports = {
4646
{ target: 'nsis', arch: ['x64'] },
4747
{ target: 'portable', arch: ['x64'] },
4848
],
49-
icon: 'assets/icon.png',
49+
icon: 'assets/icon.ico',
5050
},
5151

5252
nsis: {
5353
oneClick: false,
5454
allowToChangeInstallationDirectory: true,
55-
installerIcon: 'assets/icon.png',
56-
uninstallerIcon: 'assets/icon.png',
57-
installerHeaderIcon: 'assets/icon.png',
55+
installerIcon: 'assets/icon.ico',
56+
uninstallerIcon: 'assets/icon.ico',
57+
installerHeaderIcon: 'assets/icon.ico',
5858
createDesktopShortcut: true,
5959
createStartMenuShortcut: true,
6060
shortcutName: 'Resgrid Unit',

scripts/generate-ico.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { execSync } = require('child_process');
4+
5+
const inputPng = path.join(__dirname, '../assets/icon.png');
6+
const outputIco = path.join(__dirname, '../assets/icon.ico');
7+
const tempPng = path.join(__dirname, '../assets/icon-256.png');
8+
9+
try {
10+
console.log('Resizing icon to 256x256 using PowerShell...');
11+
// Use PowerShell to resize the image because we don't want to add sharp/jimp dependencies just for this one-off
12+
const psCommand = `
13+
Add-Type -AssemblyName System.Drawing;
14+
$img = [System.Drawing.Image]::FromFile('${inputPng}');
15+
$newImg = new-object System.Drawing.Bitmap(256, 256);
16+
$graph = [System.Drawing.Graphics]::FromImage($newImg);
17+
$graph.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic;
18+
$graph.DrawImage($img, 0, 0, 256, 256);
19+
$newImg.Save('${tempPng}', [System.Drawing.Imaging.ImageFormat]::Png);
20+
$img.Dispose();
21+
$newImg.Dispose();
22+
$graph.Dispose();
23+
`;
24+
25+
execSync(`powershell -Command "${psCommand.replace(/\n/g, ' ')}"`, { stdio: 'inherit' });
26+
27+
if (!fs.existsSync(tempPng)) {
28+
throw new Error('Failed to create resized PNG');
29+
}
30+
31+
console.log('Generating ICO file...');
32+
const pngBuffer = fs.readFileSync(tempPng);
33+
const size = 256; // We resized it to 256
34+
35+
// ICO Header
36+
// 0-1: Reserved (0)
37+
// 2-3: Type (1 for ICO)
38+
// 4-5: Number of images (1)
39+
const header = Buffer.alloc(6);
40+
header.writeUInt16LE(0, 0);
41+
header.writeUInt16LE(1, 2);
42+
header.writeUInt16LE(1, 4);
43+
44+
// Icon Directory Entry
45+
// 0: Width (0 for 256)
46+
// 1: Height (0 for 256)
47+
// 2: Color count (0 for >= 256 colors)
48+
// 3: Reserved (0)
49+
// 4-5: Color planes (1)
50+
// 6-7: Bits per pixel (32)
51+
// 8-11: Size of image data
52+
// 12-15: Offset of image data
53+
const entry = Buffer.alloc(16);
54+
entry.writeUInt8(0, 0); // 256 width -> 0
55+
entry.writeUInt8(0, 1); // 256 height -> 0
56+
entry.writeUInt8(0, 2);
57+
entry.writeUInt8(0, 3);
58+
entry.writeUInt16LE(1, 4);
59+
entry.writeUInt16LE(32, 6);
60+
entry.writeUInt32LE(pngBuffer.length, 8);
61+
entry.writeUInt32LE(6 + 16, 12); // Header (6) + 1 Entry (16)
62+
63+
const icoBuffer = Buffer.concat([header, entry, pngBuffer]);
64+
fs.writeFileSync(outputIco, icoBuffer);
65+
66+
// Clean up
67+
fs.unlinkSync(tempPng);
68+
69+
console.log(`Successfully created ${outputIco}`);
70+
71+
} catch (error) {
72+
console.error('Error generating ICO:', error);
73+
process.exit(1);
74+
}

0 commit comments

Comments
 (0)