Skip to content

Commit

Permalink
Always generate largest icon (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cykelero authored Jul 29, 2022
1 parent cbabf27 commit 43e5418
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const appdmg = require('appdmg');
const plist = require('plist');
const Ora = require('ora');
const execa = require('execa');
const addLicenseAgreementIfNeeded = require('./sla.js');
const addLicenseAgreementIfNeeded = require('./sla');
const composeIcon = require('./compose-icon');

if (process.platform !== 'darwin') {
Expand Down
17 changes: 14 additions & 3 deletions compose-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ const filterMap = (map, filterFn) => Object.entries(map).filter(filterFn).reduce
// Drive icon from `/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns``
const baseDiskIconPath = `${__dirname}/disk-icon.icns`;

const biggestPossibleIconType = 'ic10';

async function composeIcon(type, appIcon, mountIcon, composedIcon) {
mountIcon = gm(mountIcon);
appIcon = gm(appIcon);
const appIconSize = await promisify(appIcon.size.bind(appIcon))();
const mountIconSize = appIconSize;

const [appIconSize, mountIconSize] = await Promise.all([
promisify(appIcon.size.bind(appIcon))(),
promisify(appIcon.size.bind(mountIcon))()
]);

// Change the perspective of the app icon to match the mount drive icon
appIcon = appIcon.out('-matte').out('-virtual-pixel', 'transparent').out('-distort', 'Perspective', `1,1 ${appIconSize.width * 0.08},1 ${appIconSize.width},1 ${appIconSize.width * 0.92},1 1,${appIconSize.height} 1,${appIconSize.height} ${appIconSize.width},${appIconSize.height} ${appIconSize.width},${appIconSize.height}`);

// Resize the app icon to fit it inside the mount icon, aspect ration should not be kept to create the perspective illution
appIcon = appIcon.resize(appIconSize.width / 1.7, appIconSize.height / 1.78, '!');
appIcon = appIcon.resize(mountIconSize.width / 1.7, mountIconSize.height / 1.78, '!');

const tempAppIconPath = tempy.file({extension: 'png'});
await promisify(appIcon.write.bind(appIcon))(tempAppIconPath);
Expand Down Expand Up @@ -65,6 +70,12 @@ module.exports = async appIconPath => {
console.warn('There is no base image for this type', type);
}));

if (!composedIcon[biggestPossibleIconType]) {
// Make sure the highest-resolution variant is generated
const largestAppIcon = Object.values(appIcon).sort((a, b) => Buffer.byteLength(b) - Buffer.byteLength(a))[0];
await composeIcon(biggestPossibleIconType, largestAppIcon, baseDiskIcons[biggestPossibleIconType], composedIcon);
}

const tempComposedIcon = tempy.file({extension: 'icns'});

await writeFile(tempComposedIcon, icns.format(composedIcon));
Expand Down

0 comments on commit 43e5418

Please sign in to comment.