Skip to content

Commit 04f11f6

Browse files
committed
feat: Different icons for application/file extension with same name on macOS and Windows
Close #1268
1 parent 9c69ce4 commit 04f11f6

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

packages/electron-builder/src/metadata.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ export interface Macros {
347347
}
348348

349349
export function getPlatformIconFileName(value: string | null | undefined, isMac: boolean) {
350-
if (value == null) {
350+
if (value === undefined) {
351+
return undefined
352+
}
353+
if (value === null) {
351354
return null
352355
}
353356

packages/electron-builder/src/platformPackager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
510510
}
511511
}
512512
else if (!isEmptyOrSpaces(custom)) {
513-
return path.resolve(this.projectDir, custom)
513+
let p = path.resolve(this.buildResourcesDir, custom)
514+
if (await statOrNull(p) == null) {
515+
p = path.resolve(this.projectDir, custom)
516+
if (await statOrNull(p) == null) {
517+
throw new Error(`Cannot find specified resource "${custom}", nor relative to "${this.buildResourcesDir}", neither relative to project dir ("${this.projectDir}")`)
518+
}
519+
}
520+
return p
514521
}
515522
return null
516523
}

test/out/mac/__snapshots__/macPackagerTest.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Object {
2020
"CFBundleTypeRole": "Shell",
2121
"LSTypeIsPackage": true,
2222
},
23+
Object {
24+
"CFBundleTypeExtensions": Array [
25+
"bar",
26+
],
27+
"CFBundleTypeIconFile": "someFoo.icns",
28+
"CFBundleTypeName": "Bar",
29+
"CFBundleTypeRole": "Shell",
30+
},
2331
],
2432
"CFBundleExecutable": "Test App ßW",
2533
"CFBundleIconFile": "Test App ßW.icns",

test/src/mac/macPackagerTest.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { readJson } from "fs-extra-p"
55
import * as path from "path"
66
import { assertThat } from "../helpers/fileAssert"
77
import { app, appThrows, assertPack, convertUpdateInfo, platform } from "../helpers/packTester"
8+
import BluebirdPromise from "bluebird-lst-c"
89

910
test.ifMac("two-package", () => assertPack("test-app", {targets: createTargets([Platform.MAC], null, "all")}, {signed: true, useTempDir: true}))
1011

@@ -31,15 +32,26 @@ test.ifMac("one-package", app({
3132
role: "Shell",
3233
isPackage: true,
3334
},
35+
{
36+
ext: "bar",
37+
name: "Bar",
38+
role: "Shell",
39+
// If I specify `fileAssociations.icon` as `build/lhtmldoc.icns` will it know to use `build/lhtmldoc.ico` for Windows?
40+
icon: "someFoo.ico"
41+
},
3442
]
3543
}
3644
}
3745
}, {
3846
signed: true,
39-
projectDirCreated: projectDir => copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "foo.icns")),
47+
projectDirCreated: projectDir => BluebirdPromise.all([
48+
copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "foo.icns")),
49+
copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "someFoo.icns")),
50+
]),
4051
checkMacApp: async (appDir, info) => {
4152
expect(info).toMatchSnapshot()
4253
await assertThat(path.join(appDir, "Contents", "Resources", "foo.icns")).isFile()
54+
await assertThat(path.join(appDir, "Contents", "Resources", "someFoo.icns")).isFile()
4355
},
4456
packed: async context => {
4557
expect(convertUpdateInfo(await readJson(path.join(context.outDir, "latest-mac.json")))).toMatchSnapshot()

0 commit comments

Comments
 (0)