Skip to content

Commit

Permalink
fix(mac): merge fileAssociations with existing `CFBundleDocumentTyp…
Browse files Browse the repository at this point in the history
…es` if defined in `mac.extendInfo` (#8035)
  • Loading branch information
davej committed Feb 8, 2024
1 parent 6fec9e8 commit 94677f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-lions-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix(mac): merge `fileAssociations` with existing `CFBundleDocumentTypes` if defined in `mac.extendInfo`
5 changes: 4 additions & 1 deletion packages/app-builder-lib/src/electron/electronMac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa

const fileAssociations = packager.fileAssociations
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const documentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
const customIcon = await packager.getResource(getPlatformIconFileName(fileAssociation.icon, true), `${extensions[0]}.icns`)
let iconFile = appPlist.CFBundleIconFile
Expand All @@ -223,6 +223,9 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
}
return result
})

// `CFBundleDocumentTypes` may be defined in `mac.extendInfo`, so we need to merge it in that case
appPlist.CFBundleDocumentTypes = [...(appPlist.CFBundleDocumentTypes || []), ...documentTypes]
}

if (asarIntegrity != null) {
Expand Down
7 changes: 7 additions & 0 deletions test/snapshots/mac/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ exports[`one-package 2`] = `
Object {
"CFBundleDisplayName": "Test App ßW",
"CFBundleDocumentTypes": Array [
Object {
"CFBundleTypeName": "Folders",
"CFBundleTypeRole": "Editor",
"LSItemContentTypes": Array [
"public.folder",
],
},
Object {
"CFBundleTypeExtensions": Array [
"foo",
Expand Down
7 changes: 7 additions & 0 deletions test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ test.ifMac(
appId: "foo",
extendInfo: {
LSUIElement: true,
CFBundleDocumentTypes: [
{
CFBundleTypeName: "Folders",
CFBundleTypeRole: "Editor",
LSItemContentTypes: ["public.folder"],
},
],
},
minimumSystemVersion: "10.12.0",
fileAssociations: [
Expand Down

0 comments on commit 94677f3

Please sign in to comment.