@@ -9,8 +9,13 @@ import { getTemplatePath } from "../util/pathManager"
9
9
10
10
export const installPrefix = "/opt"
11
11
12
+ export interface IconInfo {
13
+ file : string
14
+ size : number
15
+ }
16
+
12
17
export class LinuxTargetHelper {
13
- readonly icons : Promise < Array < Array < string > > >
18
+ readonly icons : Promise < Array < IconInfo > >
14
19
15
20
maxIconPath : string | null = null
16
21
@@ -19,7 +24,7 @@ export class LinuxTargetHelper {
19
24
}
20
25
21
26
// must be name without spaces and other special characters, but not product name used
22
- private async computeDesktopIcons ( ) : Promise < Array < Array < string > > > {
27
+ private async computeDesktopIcons ( ) : Promise < Array < IconInfo > > {
23
28
const packager = this . packager
24
29
const customIconSetDir = packager . platformSpecificBuildOptions . icon
25
30
if ( customIconSetDir != null ) {
@@ -55,7 +60,7 @@ export class LinuxTargetHelper {
55
60
}
56
61
57
62
private async iconsFromDir ( iconDir : string ) {
58
- const mappings : Array < Array < string > > = [ ]
63
+ const mappings : Array < IconInfo > = [ ]
59
64
let maxSize = 0
60
65
for ( const file of ( await readdir ( iconDir ) ) ) {
61
66
if ( file . endsWith ( ".png" ) || file . endsWith ( ".PNG" ) ) {
@@ -66,7 +71,10 @@ export class LinuxTargetHelper {
66
71
const size = sizeString == null ? 0 : parseInt ( sizeString [ 0 ] , 10 )
67
72
if ( size > 0 ) {
68
73
const iconPath = `${ iconDir } /${ file } `
69
- mappings . push ( [ iconPath , `${ size } x${ size } /apps/${ this . packager . executableName } .png` ] )
74
+ mappings . push ( {
75
+ file : iconPath ,
76
+ size,
77
+ } )
70
78
71
79
if ( size > maxSize ) {
72
80
maxSize = size
@@ -100,7 +108,14 @@ export class LinuxTargetHelper {
100
108
return options . description || this . packager . appInfo . description
101
109
}
102
110
103
- async computeDesktopEntry ( targetSpecificOptions : LinuxTargetSpecificOptions , exec ?: string , destination ?: string | null , extra ?: { [ key : string ] : string ; } ) : Promise < string > {
111
+ async writeDesktopEntry ( targetSpecificOptions : LinuxTargetSpecificOptions , exec ?: string , destination ?: string | null , extra ?: { [ key : string ] : string ; } ) : Promise < string > {
112
+ const data = await this . computeDesktopEntry ( targetSpecificOptions , exec , extra )
113
+ const tempFile = destination || await this . packager . getTempFile ( `${ this . packager . appInfo . productFilename } .desktop` )
114
+ await outputFile ( tempFile , data )
115
+ return tempFile
116
+ }
117
+
118
+ async computeDesktopEntry ( targetSpecificOptions : LinuxTargetSpecificOptions , exec ?: string , extra ?: { [ key : string ] : string ; } ) : Promise < string > {
104
119
if ( exec != null && exec . length === 0 ) {
105
120
throw new Error ( "Specified exec is emptyd" )
106
121
}
@@ -115,7 +130,9 @@ export class LinuxTargetHelper {
115
130
Exec : exec == null ? `"${ installPrefix } /${ productFilename } /${ this . packager . executableName } " %U` : exec ,
116
131
Terminal : "false" ,
117
132
Type : "Application" ,
118
- Icon : this . packager . executableName , ...extra , ...targetSpecificOptions . desktop
133
+ Icon : this . packager . executableName ,
134
+ ...extra ,
135
+ ...targetSpecificOptions . desktop ,
119
136
}
120
137
121
138
let category = targetSpecificOptions . category
@@ -143,13 +160,10 @@ export class LinuxTargetHelper {
143
160
data += `\n${ name } =${ value } `
144
161
}
145
162
data += "\n"
146
-
147
- const tempFile = destination || await this . packager . getTempFile ( `${ productFilename } .desktop` )
148
- await outputFile ( tempFile , data )
149
- return tempFile
163
+ return data
150
164
}
151
165
152
- private async createFromIcns ( tempDir : string ) : Promise < Array < Array < string > > > {
166
+ private async createFromIcns ( tempDir : string ) : Promise < Array < IconInfo > > {
153
167
const iconPath = await this . getIcns ( )
154
168
if ( iconPath == null ) {
155
169
return await this . iconsFromDir ( path . join ( getTemplatePath ( "linux" ) , "electron-icons" ) )
@@ -210,22 +224,23 @@ export class LinuxTargetHelper {
210
224
}
211
225
212
226
private createMappings ( tempDir : string ) {
213
- const name = this . packager . executableName
214
-
215
- function createMapping ( size : string ) {
216
- return [ process . platform === "darwin" ? `${ tempDir } /icon_${ size } x${ size } .png` : `${ tempDir } /icon_${ size } x${ size } x32.png` , `${ size } x${ size } /apps/${ name } .png` ]
227
+ function createMapping ( size : number ) : IconInfo {
228
+ return {
229
+ file : process . platform === "darwin" ? `${ tempDir } /icon_${ size } x${ size } .png` : `${ tempDir } /icon_${ size } x${ size } x32.png` ,
230
+ size,
231
+ }
217
232
}
218
233
219
234
return [
220
- createMapping ( "16" ) ,
221
- createMapping ( "24" ) ,
222
- createMapping ( "32" ) ,
223
- createMapping ( "48" ) ,
224
- createMapping ( "64" ) ,
225
- createMapping ( "96" ) ,
226
- createMapping ( " 128" ) ,
227
- createMapping ( " 256" ) ,
228
- createMapping ( " 512" ) ,
235
+ createMapping ( 16 ) ,
236
+ createMapping ( 24 ) ,
237
+ createMapping ( 32 ) ,
238
+ createMapping ( 48 ) ,
239
+ createMapping ( 64 ) ,
240
+ createMapping ( 96 ) ,
241
+ createMapping ( 128 ) ,
242
+ createMapping ( 256 ) ,
243
+ createMapping ( 512 ) ,
229
244
]
230
245
}
231
246
}
0 commit comments