Skip to content

Commit 43e5418

Browse files
authored
Always generate largest icon (#72)
1 parent cbabf27 commit 43e5418

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const appdmg = require('appdmg');
77
const plist = require('plist');
88
const Ora = require('ora');
99
const execa = require('execa');
10-
const addLicenseAgreementIfNeeded = require('./sla.js');
10+
const addLicenseAgreementIfNeeded = require('./sla');
1111
const composeIcon = require('./compose-icon');
1212

1313
if (process.platform !== 'darwin') {

compose-icon.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ const filterMap = (map, filterFn) => Object.entries(map).filter(filterFn).reduce
1313
// Drive icon from `/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns``
1414
const baseDiskIconPath = `${__dirname}/disk-icon.icns`;
1515

16+
const biggestPossibleIconType = 'ic10';
17+
1618
async function composeIcon(type, appIcon, mountIcon, composedIcon) {
1719
mountIcon = gm(mountIcon);
1820
appIcon = gm(appIcon);
19-
const appIconSize = await promisify(appIcon.size.bind(appIcon))();
20-
const mountIconSize = appIconSize;
21+
22+
const [appIconSize, mountIconSize] = await Promise.all([
23+
promisify(appIcon.size.bind(appIcon))(),
24+
promisify(appIcon.size.bind(mountIcon))()
25+
]);
2126

2227
// Change the perspective of the app icon to match the mount drive icon
2328
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}`);
2429

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

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

73+
if (!composedIcon[biggestPossibleIconType]) {
74+
// Make sure the highest-resolution variant is generated
75+
const largestAppIcon = Object.values(appIcon).sort((a, b) => Buffer.byteLength(b) - Buffer.byteLength(a))[0];
76+
await composeIcon(biggestPossibleIconType, largestAppIcon, baseDiskIcons[biggestPossibleIconType], composedIcon);
77+
}
78+
6879
const tempComposedIcon = tempy.file({extension: 'icns'});
6980

7081
await writeFile(tempComposedIcon, icns.format(composedIcon));

0 commit comments

Comments
 (0)