Skip to content

Commit 7f8d3df

Browse files
authored
feat: add support for CFBundleIconName (#37)
* feat: add support for CFBundleIconName * chore: separate option for miniapp * chore: fix tests
1 parent 318acf7 commit 7f8d3df

8 files changed

Lines changed: 197 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ The following options are **optional**:
102102
- **Darwin**
103103

104104
- `darwinIcon` - path to an `.icns` file
105+
- `darwinAssetsCar` - path to an `Assets.car` file for the main app
106+
- `darwinMiniAppAssetsCar` - path to an `Assets.car` file for the miniapp (requires `darwinMiniAppName`)
105107
- `darwinHelpBookFolder` - the `CFBundleHelpBookFolder` value
106108
- `darwinHelpBookName` - the `CFBundleHelpBookName` value
107109
- `darwinBundleDocumentTypes` - ([reference](https://developer.apple.com/library/ios/documentation/filemanagement/conceptual/documentinteraction_topicsforios/Articles/RegisteringtheFileTypesYourAppSupports.html)) array of dictionaries, each containing the following structure:

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.40.1",
3+
"version": "1.41.0",
44
"description": "gulp plugin for packaging Electron into VS Code",
55
"main": "src/index.js",
66
"scripts": {

src/darwin.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,63 @@ function patchIcon(opts) {
8787
return es.duplex(pass, es.merge(src, icon));
8888
}
8989

90+
function patchAssetsCar(opts) {
91+
if (!opts.darwinAssetsCar) {
92+
return es.through();
93+
}
94+
95+
var assetsCarPath = path.join(
96+
getOriginalAppFullName(opts),
97+
"Contents",
98+
"Resources",
99+
"Assets.car"
100+
);
101+
var pass = es.through();
102+
103+
// Filter out the existing Assets.car so the provided one replaces it.
104+
var src = pass.pipe(
105+
es.mapSync(function (f) {
106+
if (f.relative !== assetsCarPath) {
107+
return f;
108+
}
109+
})
110+
);
111+
112+
var assets = vfs.src(opts.darwinAssetsCar).pipe(rename(assetsCarPath));
113+
114+
return es.duplex(pass, es.merge(src, assets));
115+
}
116+
117+
function patchMiniAppAssetsCar(opts) {
118+
if (!opts.darwinMiniAppName || !opts.darwinMiniAppAssetsCar) {
119+
return es.through();
120+
}
121+
122+
var assetsCarPath = path.join(
123+
getOriginalAppFullName(opts),
124+
"Contents",
125+
"Applications",
126+
getOriginalMiniAppFullName(opts),
127+
"Contents",
128+
"Resources",
129+
"Assets.car"
130+
);
131+
var pass = es.through();
132+
133+
// Filter out the existing Assets.car so the provided one replaces it.
134+
var src = pass.pipe(
135+
es.mapSync(function (f) {
136+
if (f.relative !== assetsCarPath) {
137+
return f;
138+
}
139+
})
140+
);
141+
142+
var assets = vfs.src(opts.darwinMiniAppAssetsCar).pipe(rename(assetsCarPath));
143+
144+
return es.duplex(pass, es.merge(src, assets));
145+
}
146+
90147
function patchInfoPlist(opts) {
91148
var contentsPath = path.join(getOriginalAppFullName(opts), "Contents");
92149
var resourcesPath = path.join(contentsPath, "Resources");
@@ -113,6 +170,7 @@ function patchInfoPlist(opts) {
113170

114171
f.contents.on("end", function () {
115172
var infoPlist = plist.parse(contents.toString("utf8"));
173+
var iconName = opts.productName || "AppIcon";
116174

117175
opts.darwinBundleIdentifier &&
118176
(infoPlist["CFBundleIdentifier"] = opts.darwinBundleIdentifier);
@@ -127,6 +185,7 @@ function patchInfoPlist(opts) {
127185
opts.copyright &&
128186
(infoPlist["NSHumanReadableCopyright"] = opts.copyright);
129187
infoPlist["CFBundleIconFile"] = opts.productName + ".icns";
188+
infoPlist["CFBundleIconName"] = iconName;
130189

131190
if (opts.darwinExecutable) {
132191
infoPlist["CFBundleExecutable"] = opts.darwinExecutable;
@@ -326,6 +385,7 @@ function patchMiniAppInfoPlist(opts) {
326385
var infoPlist = plist.parse(contents.toString("utf8"));
327386

328387
var miniAppName = getMiniAppName(opts);
388+
var iconName = miniAppName || "AppIcon";
329389

330390
// Bundle identifier
331391
if (opts.darwinMiniAppBundleIdentifier) {
@@ -349,6 +409,7 @@ function patchMiniAppInfoPlist(opts) {
349409
if (opts.darwinMiniAppIcon) {
350410
infoPlist["CFBundleIconFile"] = path.basename(opts.darwinMiniAppIcon);
351411
}
412+
infoPlist["CFBundleIconName"] = iconName;
352413

353414
// Copyright
354415
if (opts.copyright) {
@@ -702,11 +763,13 @@ exports.patch = function (opts) {
702763
var src = pass
703764
.pipe(opts.keepDefaultApp ? es.through() : removeDefaultApp(opts))
704765
.pipe(patchIcon(opts))
766+
.pipe(patchAssetsCar(opts))
705767
.pipe(patchInfoPlist(opts))
706768
.pipe(patchHelperInfoPlist(opts))
707769
.pipe(patchMiniAppInfoPlist(opts))
708770
.pipe(patchMiniAppHelperInfoPlist(opts))
709771
.pipe(patchMiniAppIcon(opts))
772+
.pipe(patchMiniAppAssetsCar(opts))
710773
.pipe(createEntitlementsPlist(opts))
711774
.pipe(addCredits(opts))
712775
.pipe(moveChromiumLicense(opts))

test/darwin.test.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"use strict";
2+
3+
var assert = require("assert");
4+
var path = require("path");
5+
var es = require("event-stream");
6+
var File = require("vinyl");
7+
var darwin = require("../src/darwin");
8+
9+
function runPatch(opts, inputFiles, cb) {
10+
var files = {};
11+
12+
es.readArray(inputFiles)
13+
.pipe(darwin.patch(opts))
14+
.on("data", function (f) {
15+
files[f.relative] = f;
16+
})
17+
.on("error", cb)
18+
.on("end", function () {
19+
cb(null, files);
20+
});
21+
}
22+
23+
function createFile(relativePath, contents) {
24+
return new File({
25+
cwd: process.cwd(),
26+
base: process.cwd(),
27+
path: path.join(process.cwd(), relativePath),
28+
contents: Buffer.from(contents, "utf8"),
29+
});
30+
}
31+
32+
var describeDarwin = process.platform === "darwin" ? describe : describe.skip;
33+
34+
describeDarwin("darwin patch", function () {
35+
it("should use separate assets options for app and miniapp", function (cb) {
36+
var mainAssetsPath = path.join(__dirname, "fixtures", "AssetsMain.car");
37+
var miniAssetsPath = path.join(__dirname, "fixtures", "AssetsMini.car");
38+
39+
var mainTarget = path.join(
40+
"Electron.app",
41+
"Contents",
42+
"Resources",
43+
"Assets.car"
44+
);
45+
var miniTarget = path.join(
46+
"Electron.app",
47+
"Contents",
48+
"Applications",
49+
"Electron MiniApp.app",
50+
"Contents",
51+
"Resources",
52+
"Assets.car"
53+
);
54+
55+
runPatch(
56+
{
57+
version: "35.0.0",
58+
productName: "Electron",
59+
productVersion: "1.0.0",
60+
darwinMiniAppName: "Electron MiniApp",
61+
darwinAssetsCar: mainAssetsPath,
62+
darwinMiniAppAssetsCar: miniAssetsPath,
63+
},
64+
[
65+
createFile(mainTarget, "old-main"),
66+
createFile(miniTarget, "old-mini"),
67+
],
68+
function (err, files) {
69+
if (err) {
70+
return cb(err);
71+
}
72+
73+
assert(files[mainTarget]);
74+
assert(files[miniTarget]);
75+
assert.equal(files[mainTarget].contents.toString("utf8"), "main-assets-car\n");
76+
assert.equal(files[miniTarget].contents.toString("utf8"), "mini-assets-car\n");
77+
cb();
78+
}
79+
);
80+
});
81+
82+
it("should not patch miniapp assets when only darwinAssetsCar is provided", function (cb) {
83+
var mainAssetsPath = path.join(__dirname, "fixtures", "AssetsMain.car");
84+
85+
var mainTarget = path.join(
86+
"Electron.app",
87+
"Contents",
88+
"Resources",
89+
"Assets.car"
90+
);
91+
var miniTarget = path.join(
92+
"Electron.app",
93+
"Contents",
94+
"Applications",
95+
"Electron MiniApp.app",
96+
"Contents",
97+
"Resources",
98+
"Assets.car"
99+
);
100+
101+
runPatch(
102+
{
103+
version: "35.0.0",
104+
productName: "Electron",
105+
productVersion: "1.0.0",
106+
darwinMiniAppName: "Electron MiniApp",
107+
darwinAssetsCar: mainAssetsPath,
108+
},
109+
[
110+
createFile(mainTarget, "old-main"),
111+
createFile(miniTarget, "old-mini"),
112+
],
113+
function (err, files) {
114+
if (err) {
115+
return cb(err);
116+
}
117+
118+
assert(files[mainTarget]);
119+
assert(files[miniTarget]);
120+
assert.equal(files[mainTarget].contents.toString("utf8"), "main-assets-car\n");
121+
assert.equal(files[miniTarget].contents.toString("utf8"), "old-mini");
122+
cb();
123+
}
124+
);
125+
});
126+
});

test/fixtures/AssetsMain.car

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main-assets-car

test/fixtures/AssetsMini.car

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mini-assets-car

test/package.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe("electron", function () {
114114
var infoPlist = plist.parse(files[infoPlistPath].contents.toString("utf8"));
115115
assert.equal(infoPlist["CFBundleName"], "FakeTemplateApp")
116116
assert.equal(infoPlist["CFBundleDisplayName"], "FakeTemplateApp")
117+
assert.equal(infoPlist["CFBundleIconName"], "FakeTemplateApp")
117118

118119
// Added helper Info.plist validation
119120
var helperBasePath = path.join(

0 commit comments

Comments
 (0)