@@ -30,38 +30,49 @@ export class LinuxTargetHelper {
3030
3131 // must be name without spaces and other special characters, but not product name used
3232 private async computeDesktopIcons ( ) : Promise < Array < Array < string > > > {
33- const tempDir = await this . tempDirPromise
34- try {
35- const mappings : Array < Array < string > > = [ ]
36- const pngIconsDir = path . join ( this . packager . buildResourcesDir , "icons" )
37- let maxSize = 0
38- for ( let file of ( await readdir ( pngIconsDir ) ) ) {
39- if ( file . endsWith ( ".png" ) || file . endsWith ( ".PNG" ) ) {
40- // If parseInt encounters a character that is not a numeral in the specified radix,
41- // it returns the integer value parsed up to that point
42- try {
43- const size = parseInt ( file ! , 10 )
44- if ( size > 0 ) {
45- const iconPath = `${ pngIconsDir } /${ file } `
46- mappings . push ( [ iconPath , `${ size } x${ size } /apps/${ this . packager . appInfo . name } .png` ] )
47-
48- if ( size > maxSize ) {
49- maxSize = size
50- this . maxIconPath = iconPath
51- }
33+ const resourceList = await this . packager . resourceList
34+ if ( resourceList . includes ( "icons" ) ) {
35+ return this . iconsFromDir ( path . join ( this . packager . buildResourcesDir , "icons" ) )
36+ }
37+ else {
38+ return this . createFromIcns ( await this . tempDirPromise )
39+ }
40+ }
41+
42+ private async iconsFromDir ( iconsDir : string ) {
43+ const mappings : Array < Array < string > > = [ ]
44+ let maxSize = 0
45+ for ( let file of ( await readdir ( iconsDir ) ) ) {
46+ if ( file . endsWith ( ".png" ) || file . endsWith ( ".PNG" ) ) {
47+ // If parseInt encounters a character that is not a numeral in the specified radix,
48+ // it returns the integer value parsed up to that point
49+ try {
50+ const size = parseInt ( file ! , 10 )
51+ if ( size > 0 ) {
52+ const iconPath = `${ iconsDir } /${ file } `
53+ mappings . push ( [ iconPath , `${ size } x${ size } /apps/${ this . packager . appInfo . name } .png` ] )
54+
55+ if ( size > maxSize ) {
56+ maxSize = size
57+ this . maxIconPath = iconPath
5258 }
5359 }
54- catch ( e ) {
55- console . error ( e )
56- }
60+ }
61+ catch ( e ) {
62+ console . error ( e )
5763 }
5864 }
59-
60- return mappings
6165 }
62- catch ( e ) {
63- return this . createFromIcns ( tempDir )
66+ return mappings
67+ }
68+
69+ private async getIcns ( ) : Promise < string | null > {
70+ const build = this . packager . devMetadata . build
71+ let iconPath = ( build . mac || { } ) . icon || build . icon
72+ if ( iconPath != null && ! iconPath . endsWith ( ".icns" ) ) {
73+ iconPath += ".icns"
6474 }
75+ return iconPath == null ? await this . packager . getDefaultIcon ( "icns" ) : path . resolve ( this . packager . projectDir , iconPath )
6576 }
6677
6778 async computeDesktopEntry ( exec ?: string , extra ?: string ) : Promise < string > {
@@ -86,7 +97,12 @@ ${extra == null ? "" : `${extra}\n`}`)
8697 }
8798
8899 private async createFromIcns ( tempDir : string ) : Promise < Array < Array < string > > > {
89- const output = await exec ( "icns2png" , [ "-x" , "-o" , tempDir , path . join ( this . packager . buildResourcesDir , "icon.icns" ) ] )
100+ const iconPath = await this . getIcns ( )
101+ if ( iconPath == null ) {
102+ return this . iconsFromDir ( path . join ( __dirname , ".." , ".." , "templates" , "linux" , "electron-icons" ) )
103+ }
104+
105+ const output = await exec ( "icns2png" , [ "-x" , "-o" , tempDir , iconPath ] )
90106 debug ( output )
91107
92108 //noinspection UnnecessaryLocalVariableJS
0 commit comments