forked from rockybars/atom-shell-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
win32.js
114 lines (91 loc) · 3.14 KB
/
win32.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict'
const debug = require('debug')('electron-packager')
const path = require('path')
const pify = require('pify')
const App = require('./platform')
const common = require('./common')
function updateWineMissingException (err) {
if (err && err.code === 'ENOENT' && err.syscall === 'spawn wine') {
err.message = 'Could not find "wine" on your system.\n\n' +
'Wine is required to use the appCopyright, appVersion, buildVersion, icon, and \n' +
'win32metadata parameters for Windows targets.\n\n' +
'Make sure that the "wine" executable is in your PATH.\n\n' +
'See https://github.com/electron-userland/electron-packager#building-windows-apps-from-non-windows-platforms for details.'
}
return err
}
class WindowsApp extends App {
get originalElectronName () {
return 'electron.exe'
}
get newElectronName () {
return `${common.sanitizeAppName(this.executableName)}.exe`
}
get electronBinaryPath () {
return path.join(this.stagingPath, this.newElectronName)
}
generateRceditOptionsSansIcon () {
const win32metadata = Object.assign({
FileDescription: this.opts.name,
InternalName: this.opts.name,
OriginalFilename: this.newElectronName,
ProductName: this.opts.name
}, this.opts.win32metadata)
let rcOpts = { 'version-string': win32metadata }
if (this.opts.appVersion) {
rcOpts['product-version'] = rcOpts['file-version'] = this.opts.appVersion
}
if (this.opts.buildVersion) {
rcOpts['file-version'] = this.opts.buildVersion
}
if (this.opts.appCopyright) {
rcOpts['version-string'].LegalCopyright = this.opts.appCopyright
}
const manifestProperties = ['application-manifest', 'requested-execution-level']
for (const manifestProperty of manifestProperties) {
if (win32metadata[manifestProperty]) {
rcOpts[manifestProperty] = win32metadata[manifestProperty]
}
}
return rcOpts
}
getIconPath () {
if (!this.opts.icon) {
return Promise.resolve()
}
return this.normalizeIconExtension('.ico')
}
needsRcedit () {
return this.opts.icon || this.opts.win32metadata || this.opts.appCopyright || this.opts.appVersion || this.opts.buildVersion
}
runRcedit () {
/* istanbul ignore if */
if (!this.needsRcedit()) {
return Promise.resolve()
}
const rcOpts = this.generateRceditOptionsSansIcon()
return this.getIconPath()
.then(icon => {
// Icon might be omitted or only exist in one OS's format, so skip it if normalizeExt reports an error
if (icon) {
rcOpts.icon = icon
}
debug(`Running rcedit with the options ${JSON.stringify(rcOpts)}`)
return pify(require('rcedit'))(this.electronBinaryPath, rcOpts)
}).catch(err => {
/* istanbul ignore next */
throw updateWineMissingException(err)
})
}
create () {
return this.initialize()
.then(() => this.renameElectron())
.then(() => this.copyExtraResources())
.then(() => this.runRcedit())
.then(() => this.move())
}
}
module.exports = {
App: WindowsApp,
updateWineMissingException: updateWineMissingException
}