From 94677f3d70866582635c717b042194f0c75bbf01 Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Thu, 8 Feb 2024 21:39:28 +0000 Subject: [PATCH] fix(mac): merge `fileAssociations` with existing `CFBundleDocumentTypes` if defined in `mac.extendInfo` (#8035) --- .changeset/fifty-lions-burn.md | 5 +++++ packages/app-builder-lib/src/electron/electronMac.ts | 5 ++++- test/snapshots/mac/macPackagerTest.js.snap | 7 +++++++ test/src/mac/macPackagerTest.ts | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changeset/fifty-lions-burn.md diff --git a/.changeset/fifty-lions-burn.md b/.changeset/fifty-lions-burn.md new file mode 100644 index 00000000000..c633685cffe --- /dev/null +++ b/.changeset/fifty-lions-burn.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +fix(mac): merge `fileAssociations` with existing `CFBundleDocumentTypes` if defined in `mac.extendInfo` diff --git a/packages/app-builder-lib/src/electron/electronMac.ts b/packages/app-builder-lib/src/electron/electronMac.ts index cd0855f9f04..960d3271a09 100644 --- a/packages/app-builder-lib/src/electron/electronMac.ts +++ b/packages/app-builder-lib/src/electron/electronMac.ts @@ -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 @@ -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) { diff --git a/test/snapshots/mac/macPackagerTest.js.snap b/test/snapshots/mac/macPackagerTest.js.snap index cbe82efabb3..58a26252ccb 100644 --- a/test/snapshots/mac/macPackagerTest.js.snap +++ b/test/snapshots/mac/macPackagerTest.js.snap @@ -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", diff --git a/test/src/mac/macPackagerTest.ts b/test/src/mac/macPackagerTest.ts index 7b7ae470530..b9de7f7eff2 100644 --- a/test/src/mac/macPackagerTest.ts +++ b/test/src/mac/macPackagerTest.ts @@ -54,6 +54,13 @@ test.ifMac( appId: "foo", extendInfo: { LSUIElement: true, + CFBundleDocumentTypes: [ + { + CFBundleTypeName: "Folders", + CFBundleTypeRole: "Editor", + LSItemContentTypes: ["public.folder"], + }, + ], }, minimumSystemVersion: "10.12.0", fileAssociations: [