Skip to content

Commit e516fd4

Browse files
authored
chore: add windows proxy executable customization (#33)
1 parent 9a31bf3 commit e516fd4

3 files changed

Lines changed: 110 additions & 65 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vscode/gulp-electron",
3-
"version": "1.39.0",
3+
"version": "1.40.0",
44
"description": "gulp plugin for packaging Electron into VS Code",
55
"main": "src/index.js",
66
"scripts": {

src/win32.js

Lines changed: 107 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -60,76 +60,113 @@ exports.getAppPath = function (opts) {
6060
return path.join("resources", "app");
6161
};
6262

63+
function applyRcedit(f, patch, cb) {
64+
var tempPath = temp.path();
65+
var ostream = fs.createWriteStream(tempPath);
66+
67+
f.contents.pipe(ostream);
68+
ostream.on("close", function () {
69+
// Remove codesignature before editing exe file
70+
const signToolPath = getSignTool();
71+
const {error} = spawnSync(signToolPath, ["remove", "/s", tempPath]);
72+
if (error) {
73+
return cb(error);
74+
}
75+
76+
rcedit(tempPath, patch).then(() => {
77+
fs.readFile(tempPath, function (err, data) {
78+
if (err) {
79+
return cb(err);
80+
}
81+
82+
f.contents = data;
83+
84+
fs.unlink(tempPath, function (err) {
85+
if (err) {
86+
return cb(err);
87+
}
88+
89+
cb(null, f);
90+
});
91+
});
92+
}).catch(err => {
93+
if (err) {
94+
return cb(err);
95+
}
96+
});
97+
});
98+
}
99+
63100
function patchExecutable(opts) {
64101
return es.map(function (f, cb) {
65-
if (
66-
f.relative !== getOriginalAppFullName(opts) ||
67-
process.platform !== "win32"
68-
) {
102+
if (process.platform !== "win32") {
69103
return cb(null, f);
70104
}
71105

72-
var patch = {
73-
"version-string": {
74-
CompanyName: opts.companyName || "GitHub, Inc.",
75-
FileDescription: opts.productAppName || opts.productName,
76-
LegalCopyright:
77-
opts.copyright ||
78-
"Copyright (C) 2014 GitHub, Inc. All rights reserved",
79-
ProductName: opts.productAppName || opts.productName,
80-
ProductVersion: opts.productVersion,
81-
},
82-
"file-version": opts.productVersion,
83-
"product-version": opts.productVersion,
84-
};
85-
86-
if (opts.createVersionedResources) {
87-
if (!opts.productVersionString) {
88-
throw new Error("productVersionString must be defined.");
89-
}
90-
patch["resource-string"] = {
91-
2: opts.productVersionString
106+
if (f.relative === getOriginalAppFullName(opts)) {
107+
var patch = {
108+
"version-string": {
109+
CompanyName: opts.companyName || "GitHub, Inc.",
110+
FileDescription: opts.productAppName || opts.productName,
111+
LegalCopyright:
112+
opts.copyright ||
113+
"Copyright (C) 2014 GitHub, Inc. All rights reserved",
114+
ProductName: opts.productAppName || opts.productName,
115+
ProductVersion: opts.productVersion,
116+
},
117+
"file-version": opts.productVersion,
118+
"product-version": opts.productVersion,
92119
};
93-
}
94120

95-
if (opts.winIcon) {
96-
patch.icon = opts.winIcon;
121+
if (opts.createVersionedResources) {
122+
if (!opts.productVersionString) {
123+
throw new Error("productVersionString must be defined.");
124+
}
125+
patch["resource-string"] = {
126+
2: opts.productVersionString
127+
};
128+
}
129+
130+
if (opts.winIcon) {
131+
patch.icon = opts.winIcon;
132+
}
133+
134+
return applyRcedit(f, patch, cb);
97135
}
98136

99-
var tempPath = temp.path();
100-
var ostream = fs.createWriteStream(tempPath);
137+
if (opts.win32ProxyAppName && f.relative === "electron_proxy.exe") {
138+
var patch = {
139+
"version-string": {
140+
CompanyName: opts.companyName || "GitHub, Inc.",
141+
FileDescription: opts.win32ProxyAppName,
142+
LegalCopyright:
143+
opts.copyright ||
144+
"Copyright (C) 2014 GitHub, Inc. All rights reserved",
145+
ProductName: opts.win32ProxyAppName,
146+
ProductVersion: opts.productVersion,
147+
},
148+
"file-version": opts.productVersion,
149+
"product-version": opts.productVersion,
150+
"resource-string": {
151+
3: `${opts.productName}.exe`
152+
},
153+
};
101154

102-
f.contents.pipe(ostream);
103-
ostream.on("close", function () {
104-
// Remove codesignature before editing exe file
105-
const signToolPath = getSignTool();
106-
const {error} = spawnSync(signToolPath, ["remove", "/s", tempPath]);
107-
if (error) {
108-
return cb(error);
155+
if (opts.createVersionedResources) {
156+
if (!opts.productVersionString) {
157+
throw new Error("productVersionString must be defined.");
158+
}
159+
patch["resource-string"][2] = opts.productVersionString;
109160
}
110161

111-
rcedit(tempPath, patch).then(() => {
112-
fs.readFile(tempPath, function (err, data) {
113-
if (err) {
114-
return cb(err);
115-
}
116-
117-
f.contents = data;
162+
if (opts.win32ProxyIcon) {
163+
patch.icon = opts.win32ProxyIcon;
164+
}
118165

119-
fs.unlink(tempPath, function (err) {
120-
if (err) {
121-
return cb(err);
122-
}
166+
return applyRcedit(f, patch, cb);
167+
}
123168

124-
cb(null, f);
125-
});
126-
});
127-
}).catch(err => {
128-
if (err) {
129-
return cb(err);
130-
}
131-
});
132-
});
169+
return cb(null, f);
133170
});
134171
}
135172

@@ -145,12 +182,12 @@ function removeDefaultApp() {
145182

146183
function renameApp(opts) {
147184
return rename(function (path) {
148-
if (
149-
path.dirname === "." &&
150-
path.basename === getOriginalAppName(opts) &&
151-
path.extname === ".exe"
152-
) {
153-
path.basename = opts.productName;
185+
if (path.dirname === "." && path.extname === ".exe") {
186+
if (path.basename === getOriginalAppName(opts)) {
187+
path.basename = opts.productName;
188+
} else if (opts.win32ProxyAppName && path.basename === "electron_proxy") {
189+
path.basename = opts.win32ProxyAppName;
190+
}
154191
}
155192
});
156193
}
@@ -168,6 +205,14 @@ function moveFilesExceptExecutable(opts) {
168205
return f;
169206
}
170207

208+
// Skip if the file is the renamed proxy executable
209+
if (
210+
opts.win32ProxyAppName &&
211+
f.relative === `${opts.win32ProxyAppName}.exe`
212+
) {
213+
return f;
214+
}
215+
171216
// Move other files to version subfolder
172217
if (f.path && f.base) {
173218
const relativePath = path.relative(f.base, f.path);

0 commit comments

Comments
 (0)