Skip to content

Commit

Permalink
feat: Different icons for application/file extension with same name o…
Browse files Browse the repository at this point in the history
…n macOS and Windows

Close #1268
  • Loading branch information
develar committed Feb 15, 2017
1 parent 9c69ce4 commit 04f11f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ export interface Macros {
}

export function getPlatformIconFileName(value: string | null | undefined, isMac: boolean) {
if (value == null) {
if (value === undefined) {
return undefined
}
if (value === null) {
return null
}

Expand Down
9 changes: 8 additions & 1 deletion packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}
else if (!isEmptyOrSpaces(custom)) {
return path.resolve(this.projectDir, custom)
let p = path.resolve(this.buildResourcesDir, custom)
if (await statOrNull(p) == null) {
p = path.resolve(this.projectDir, custom)
if (await statOrNull(p) == null) {
throw new Error(`Cannot find specified resource "${custom}", nor relative to "${this.buildResourcesDir}", neither relative to project dir ("${this.projectDir}")`)
}
}
return p
}
return null
}
Expand Down
8 changes: 8 additions & 0 deletions test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ Object {
"CFBundleTypeRole": "Shell",
"LSTypeIsPackage": true,
},
Object {
"CFBundleTypeExtensions": Array [
"bar",
],
"CFBundleTypeIconFile": "someFoo.icns",
"CFBundleTypeName": "Bar",
"CFBundleTypeRole": "Shell",
},
],
"CFBundleExecutable": "Test App ßW",
"CFBundleIconFile": "Test App ßW.icns",
Expand Down
14 changes: 13 additions & 1 deletion test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readJson } from "fs-extra-p"
import * as path from "path"
import { assertThat } from "../helpers/fileAssert"
import { app, appThrows, assertPack, convertUpdateInfo, platform } from "../helpers/packTester"
import BluebirdPromise from "bluebird-lst-c"

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

Expand All @@ -31,15 +32,26 @@ test.ifMac("one-package", app({
role: "Shell",
isPackage: true,
},
{
ext: "bar",
name: "Bar",
role: "Shell",
// If I specify `fileAssociations.icon` as `build/lhtmldoc.icns` will it know to use `build/lhtmldoc.ico` for Windows?
icon: "someFoo.ico"
},
]
}
}
}, {
signed: true,
projectDirCreated: projectDir => copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "foo.icns")),
projectDirCreated: projectDir => BluebirdPromise.all([
copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "foo.icns")),
copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "someFoo.icns")),
]),
checkMacApp: async (appDir, info) => {
expect(info).toMatchSnapshot()
await assertThat(path.join(appDir, "Contents", "Resources", "foo.icns")).isFile()
await assertThat(path.join(appDir, "Contents", "Resources", "someFoo.icns")).isFile()
},
packed: async context => {
expect(convertUpdateInfo(await readJson(path.join(context.outDir, "latest-mac.json")))).toMatchSnapshot()
Expand Down

0 comments on commit 04f11f6

Please sign in to comment.