Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/icon.ico
Binary file not shown.
8 changes: 4 additions & 4 deletions electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ module.exports = {
{ target: 'nsis', arch: ['x64'] },
{ target: 'portable', arch: ['x64'] },
],
icon: 'assets/icon.png',
icon: 'assets/icon.ico',
},

nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
installerIcon: 'assets/icon.png',
uninstallerIcon: 'assets/icon.png',
installerHeaderIcon: 'assets/icon.png',
installerIcon: 'assets/icon.ico',
uninstallerIcon: 'assets/icon.ico',
installerHeaderIcon: 'assets/icon.ico',
createDesktopShortcut: true,
createStartMenuShortcut: true,
shortcutName: 'Resgrid Unit',
Expand Down
74 changes: 74 additions & 0 deletions scripts/generate-ico.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const inputPng = path.join(__dirname, '../assets/icon.png');

Check failure on line 5 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'__dirname' is not defined
const outputIco = path.join(__dirname, '../assets/icon.ico');

Check failure on line 6 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'__dirname' is not defined
const tempPng = path.join(__dirname, '../assets/icon-256.png');

Check failure on line 7 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'__dirname' is not defined
Comment thread
coderabbitai[bot] marked this conversation as resolved.

try {
console.log('Resizing icon to 256x256 using PowerShell...');
// Use PowerShell to resize the image because we don't want to add sharp/jimp dependencies just for this one-off
const psCommand = `
Add-Type -AssemblyName System.Drawing;
$img = [System.Drawing.Image]::FromFile('${inputPng}');
$newImg = new-object System.Drawing.Bitmap(256, 256);
$graph = [System.Drawing.Graphics]::FromImage($newImg);
$graph.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic;
$graph.DrawImage($img, 0, 0, 256, 256);
$newImg.Save('${tempPng}', [System.Drawing.Imaging.ImageFormat]::Png);
$img.Dispose();
$newImg.Dispose();
$graph.Dispose();
`;

execSync(`powershell -Command "${psCommand.replace(/\n/g, ' ')}"`, { stdio: 'inherit' });

if (!fs.existsSync(tempPng)) {
throw new Error('Failed to create resized PNG');
}

console.log('Generating ICO file...');
const pngBuffer = fs.readFileSync(tempPng);
const size = 256; // We resized it to 256

Check warning on line 33 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'size' is assigned a value but never used
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

Check warning on line 34 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

Delete `··`
// ICO Header
// 0-1: Reserved (0)
// 2-3: Type (1 for ICO)
// 4-5: Number of images (1)
const header = Buffer.alloc(6);

Check failure on line 39 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'Buffer' is not defined
header.writeUInt16LE(0, 0);
header.writeUInt16LE(1, 2);
header.writeUInt16LE(1, 4);

// Icon Directory Entry
// 0: Width (0 for 256)
// 1: Height (0 for 256)
// 2: Color count (0 for >= 256 colors)
// 3: Reserved (0)
// 4-5: Color planes (1)
// 6-7: Bits per pixel (32)
// 8-11: Size of image data
// 12-15: Offset of image data
const entry = Buffer.alloc(16);

Check failure on line 53 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'Buffer' is not defined
entry.writeUInt8(0, 0); // 256 width -> 0
entry.writeUInt8(0, 1); // 256 height -> 0
entry.writeUInt8(0, 2);

Check warning on line 56 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

Delete `·`
entry.writeUInt8(0, 3);
entry.writeUInt16LE(1, 4);
entry.writeUInt16LE(32, 6);
entry.writeUInt32LE(pngBuffer.length, 8);
entry.writeUInt32LE(6 + 16, 12); // Header (6) + 1 Entry (16)

const icoBuffer = Buffer.concat([header, entry, pngBuffer]);

Check failure on line 63 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

'Buffer' is not defined
fs.writeFileSync(outputIco, icoBuffer);

// Clean up
fs.unlinkSync(tempPng);

console.log(`Successfully created ${outputIco}`);

Check warning on line 69 in scripts/generate-ico.js

View workflow job for this annotation

GitHub Actions / test

Delete `⏎`

} catch (error) {
console.error('Error generating ICO:', error);
process.exit(1);
}
Loading