@@ -30,38 +30,49 @@ export class LinuxTargetHelper {
30
30
31
31
// must be name without spaces and other special characters, but not product name used
32
32
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
52
58
}
53
59
}
54
- catch ( e ) {
55
- console . error ( e )
56
- }
60
+ }
61
+ catch ( e ) {
62
+ console . error ( e )
57
63
}
58
64
}
59
-
60
- return mappings
61
65
}
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"
64
74
}
75
+ return iconPath == null ? await this . packager . getDefaultIcon ( "icns" ) : path . resolve ( this . packager . projectDir , iconPath )
65
76
}
66
77
67
78
async computeDesktopEntry ( exec ?: string , extra ?: string ) : Promise < string > {
@@ -86,7 +97,12 @@ ${extra == null ? "" : `${extra}\n`}`)
86
97
}
87
98
88
99
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 ] )
90
106
debug ( output )
91
107
92
108
//noinspection UnnecessaryLocalVariableJS
0 commit comments