@@ -13,17 +13,22 @@ const filterMap = (map, filterFn) => Object.entries(map).filter(filterFn).reduce
13
13
// Drive icon from `/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns``
14
14
const baseDiskIconPath = `${ __dirname } /disk-icon.icns` ;
15
15
16
+ const biggestPossibleIconType = 'ic10' ;
17
+
16
18
async function composeIcon ( type , appIcon , mountIcon , composedIcon ) {
17
19
mountIcon = gm ( mountIcon ) ;
18
20
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
+ ] ) ;
21
26
22
27
// Change the perspective of the app icon to match the mount drive icon
23
28
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 } ` ) ;
24
29
25
30
// 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 , '!' ) ;
27
32
28
33
const tempAppIconPath = tempy . file ( { extension : 'png' } ) ;
29
34
await promisify ( appIcon . write . bind ( appIcon ) ) ( tempAppIconPath ) ;
@@ -65,6 +70,12 @@ module.exports = async appIconPath => {
65
70
console . warn ( 'There is no base image for this type' , type ) ;
66
71
} ) ) ;
67
72
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
+
68
79
const tempComposedIcon = tempy . file ( { extension : 'icns' } ) ;
69
80
70
81
await writeFile ( tempComposedIcon , icns . format ( composedIcon ) ) ;
0 commit comments