Skip to content

Commit

Permalink
fix: make file association name optional
Browse files Browse the repository at this point in the history
Close #1069
  • Loading branch information
develar committed Jan 18, 2017
1 parent 8d883f1 commit 248855c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ macOS (corresponds to [CFBundleDocumentTypes](https://developer.apple.com/librar
| Name | Description
| --- | ---
| **ext** | <a name="FileAssociation-ext"></a>The extension (minus the leading period). e.g. `png`.
| **name** | <a name="FileAssociation-name"></a>The name. e.g. `PNG`.
| name | <a name="FileAssociation-name"></a>The name. e.g. `PNG`. Defaults to `ext`.
| description | <a name="FileAssociation-description"></a>*windows-only.* The description.
| icon | <a name="FileAssociation-icon"></a>The path to icon (`.icns` for MacOS and `.ico` for Windows), relative to `build` (build resources directory). Defaults to `${firstExt}.icns`/`${firstExt}.ico` (if several extensions specified, first is used) or to application icon.
| role | <a name="FileAssociation-role"></a>*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`. Corresponds to `CFBundleTypeRole`.
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ export interface FileAssociation {
readonly ext: string | Array<string>

/*
The name. e.g. `PNG`.
The name. e.g. `PNG`. Defaults to `ext`.
*/
readonly name: string
readonly name?: string | null

/*
*windows-only.* The description.
*/
readonly description?: string
readonly description?: string | null

/*
The path to icon (`.icns` for MacOS and `.ico` for Windows), relative to `build` (build resources directory). Defaults to `${firstExt}.icns`/`${firstExt}.ico` (if several extensions specified, first is used) or to application icon.
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri

const result = <any>{
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name,
CFBundleTypeName: fileAssociation.name || extensions[0],
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: iconFile
}
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export default class NsisTarget extends Target {
const icon = `"${installedIconPath}"`
const commandText = `"Open with ${packager.appInfo.productName}"`
const command = '"$appExe $\\"%1$\\""'
registerFileAssociationsScript += ` !insertmacro APP_ASSOCIATE "${ext}" "${item.name}" "${item.description || ""}" ${icon} ${commandText} ${command}\n`
registerFileAssociationsScript += ` !insertmacro APP_ASSOCIATE "${ext}" "${item.name || ext}" "${item.description || ""}" ${icon} ${commandText} ${command}\n`
}
}
script = `!macro registerFileAssociations\n${registerFileAssociationsScript}!macroend\n${script}`
Expand All @@ -277,7 +277,7 @@ export default class NsisTarget extends Target {
let unregisterFileAssociationsScript = ""
for (const item of fileAssociations) {
for (const ext of asArray(item.ext)) {
unregisterFileAssociationsScript += ` !insertmacro APP_UNASSOCIATE "${normalizeExt(ext)}" "${item.name}"\n`
unregisterFileAssociationsScript += ` !insertmacro APP_UNASSOCIATE "${normalizeExt(ext)}" "${item.name || ext}"\n`
}
}
script = `!macro unregisterFileAssociations\n${unregisterFileAssociationsScript}!macroend\n${script}`
Expand Down

0 comments on commit 248855c

Please sign in to comment.