@@ -5,7 +5,7 @@ import { Platform } from "./metadata"
55import { dir as _tpmDir , TmpOptions } from "tmp"
66import { exec , log } from "./util"
77import { State as Gm } from "gm"
8- import { outputFile , readFile } from "fs-extra-p"
8+ import { outputFile , readFile , stat } from "fs-extra-p"
99const template = require ( "lodash.template" )
1010
1111//noinspection JSUnusedLocalSymbols
@@ -69,14 +69,31 @@ Icon=${this.metadata.name}
6969
7070 private async computeDesktopIconPath ( tempDir : string ) : Promise < Array < string > > {
7171 const outputs = await exec ( "icns2png" , [ "-x" , "-o" , tempDir , path . join ( this . buildResourcesDir , "icon.icns" ) ] )
72+ log ( outputs [ 0 ] . toString ( ) )
7273 if ( ! outputs [ 0 ] . toString ( ) . includes ( "ih32" ) ) {
73- log ( "48x48 is not found in the icns, 128x128 will be resized" )
74+ log ( "48x48 is not found in the icns, 128x128 or 256x256 will be resized" )
75+
76+ const gm = require ( "gm" )
77+
7478 // icns doesn't contain required 48x48, use gm to resize
75- await new BluebirdPromise ( ( resolve , reject ) => {
76- ( < Gm > require ( "gm" ) ( path . join ( tempDir , "icon_128x128x32.png" ) ) )
77- . resize ( 48 , 48 )
78- . write ( path . join ( tempDir , "icon_48x48x32.png" ) , error => error == null ? resolve ( ) : reject ( error ) )
79- } )
79+ function resize ( imagePath : string , size : number ) : BluebirdPromise < any > {
80+ return new BluebirdPromise ( ( resolve , reject ) => {
81+ ( < Gm > gm ( imagePath ) )
82+ . resize ( size , size )
83+ . write ( path . join ( tempDir , `icon_${ size } x${ size } x32.png` ) , error => error == null ? resolve ( ) : reject ( error ) )
84+ } )
85+ }
86+
87+ let imagePath = path . join ( tempDir , "icon_128x128x32.png" )
88+ try {
89+ await stat ( imagePath )
90+ }
91+ catch ( e ) {
92+ imagePath = path . join ( tempDir , "icon_256x256x32.png" )
93+ // 128 should be in any case
94+ await resize ( imagePath , 128 )
95+ }
96+ await resize ( imagePath , 48 )
8097 }
8198
8299 const name = this . metadata . name
0 commit comments