@@ -5,7 +5,7 @@ import { Platform } from "./metadata"
5
5
import { dir as _tpmDir , TmpOptions } from "tmp"
6
6
import { exec , log } from "./util"
7
7
import { State as Gm } from "gm"
8
- import { outputFile , readFile } from "fs-extra-p"
8
+ import { outputFile , readFile , stat } from "fs-extra-p"
9
9
const template = require ( "lodash.template" )
10
10
11
11
//noinspection JSUnusedLocalSymbols
@@ -69,14 +69,31 @@ Icon=${this.metadata.name}
69
69
70
70
private async computeDesktopIconPath ( tempDir : string ) : Promise < Array < string > > {
71
71
const outputs = await exec ( "icns2png" , [ "-x" , "-o" , tempDir , path . join ( this . buildResourcesDir , "icon.icns" ) ] )
72
+ log ( outputs [ 0 ] . toString ( ) )
72
73
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
+
74
78
// 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 )
80
97
}
81
98
82
99
const name = this . metadata . name
0 commit comments