Skip to content

Commit 87616c0

Browse files
committed
feat(linux): Categories desktop entry
Closes #727, #641
1 parent 1b90ec6 commit 87616c0

File tree

19 files changed

+141
-120
lines changed

19 files changed

+141
-120
lines changed

docs/Options.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ Don't customize paths to background and icon, — just follow conventions.
4949
| Name | Description
5050
| --- | ---
5151
| appId | <a name="BuildMetadata-appId"></a><p>The application id. Used as [CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070) for MacOS and as [Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx) for Windows (NSIS target only, Squirrel.Windows not supported).</p> <p>Defaults to <code>com.electron.${name}</code>. It is strongly recommended that an explicit ID be set.</p>
52-
| category | <a name="BuildMetadata-category"></a><p>*macOS-only.* The application category type, as shown in the Finder via *View -&gt; Arrange by Application Category* when viewing the Applications directory.</p> <p>For example, <code>&quot;category&quot;: &quot;public.app-category.developer-tools&quot;</code> will set the application category to *Developer Tools*.</p> <p>Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).</p>
5352
| copyright | <a name="BuildMetadata-copyright"></a>The human-readable copyright line for the app. Defaults to `Copyright © year author`.
5453
| asar | <a name="BuildMetadata-asar"></a><p>Whether to package the application’s source code into an archive, using [Electron’s archive format](https://github.com/electron/asar). Defaults to <code>true</code>. Reasons why you may want to disable this feature are described in [an application packaging tutorial in Electron’s documentation](http://electron.atom.io/docs/latest/tutorial/application-packaging/#limitations-on-node-api/).</p> <p>Or you can pass object of any asar options.</p> <p>Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set <code>asar.unpackDir</code> - please file issue if this doesn’t work.</p>
5554
| productName | <a name="BuildMetadata-productName"></a>See [AppMetadata.productName](#AppMetadata-productName).
@@ -76,12 +75,14 @@ MacOS specific build options.
7675

7776
| Name | Description
7877
| --- | ---
78+
| category | <a name="MacOptions-category"></a><p>The application category type, as shown in the Finder via *View -&gt; Arrange by Application Category* when viewing the Applications directory.</p> <p>For example, <code>&quot;category&quot;: &quot;public.app-category.developer-tools&quot;</code> will set the application category to *Developer Tools*.</p> <p>Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).</p>
7979
| target | <a name="MacOptions-target"></a>Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
8080
| identity | <a name="MacOptions-identity"></a><p>The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing). MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity).</p>
8181
| icon | <a name="MacOptions-icon"></a>The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration).
8282
| entitlements | <a name="MacOptions-entitlements"></a><p>The path to entitlements file for signing the app. <code>build/entitlements.mac.plist</code> will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).</p>
8383
| entitlementsInherit | <a name="MacOptions-entitlementsInherit"></a><p>The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. <code>build/entitlements.mac.inherit.plist</code> will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.darwin.inherit.plist).</p> <p>This option only applies when signing with <code>entitlements</code> provided.</p>
8484
| bundleVersion | <a name="MacOptions-bundleVersion"></a>The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)).
85+
| helperBundleId | <a name="MacOptions-helperBundleId"></a>The bundle identifier to use in the application helper's plist. Defaults to `${appBundleIdentifier}.helper`.
8586

8687
<a name="DmgOptions"></a>
8788
### `.build.dmg`
@@ -142,7 +143,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
142143
| installerHeaderIcon | <a name="NsisOptions-installerHeaderIcon"></a>*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/installerHeaderIcon.ico` or application icon.
143144
| include | <a name="NsisOptions-include"></a>The path to NSIS include script to customize installer. Defaults to `build/installer.nsh`. See [Custom NSIS script](https://github.com/electron-userland/electron-builder/wiki/NSIS#custom-nsis-script).
144145
| script | <a name="NsisOptions-script"></a>The path to NSIS script to customize installer. Defaults to `build/installer.nsi`. See [Custom NSIS script](https://github.com/electron-userland/electron-builder/wiki/NSIS#custom-nsis-script).
145-
| language | <a name="NsisOptions-language"></a>* LCID Dec, defaults to `1033`(`English - United States`, see https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx?f=255&MSPPError=-2147217396).
146+
| language | <a name="NsisOptions-language"></a>* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).
146147

147148
<a name="LinuxBuildOptions"></a>
148149
### `.build.linux`
@@ -151,11 +152,14 @@ Linux specific build options.
151152

152153
| Name | Description
153154
| --- | ---
155+
| category | <a name="LinuxBuildOptions-category"></a>The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
156+
| packageCategory | <a name="LinuxBuildOptions-packageCategory"></a>The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
154157
| description | <a name="LinuxBuildOptions-description"></a>As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
155158
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>. Defaults to <code>AppImage</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> and <code>AppImage</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>
156159
| synopsis | <a name="LinuxBuildOptions-synopsis"></a>*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
157160
| maintainer | <a name="LinuxBuildOptions-maintainer"></a>The maintainer. Defaults to [author](#AppMetadata-author).
158161
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).
162+
| desktop | <a name="LinuxBuildOptions-desktop"></a>The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
159163
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
160164
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
161165

src/appInfo.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ export class AppInfo {
6161
return this.metadata.name
6262
}
6363

64-
get category() {
65-
const metadata = this.devMetadata.build
66-
const old = (<any>metadata)["app-category-type"]
67-
if (old != null) {
68-
warn('"app-category-type" is deprecated — please use "category" instead')
69-
}
70-
return metadata.category || old
71-
}
72-
7364
get copyright(): string {
7465
const metadata = this.devMetadata.build
7566
const old = (<any>metadata)["app-copyright"]

src/linuxPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
6161

6262
async pack(outDir: string, arch: Arch, targets: Array<Target>, postAsyncTasks: Array<Promise<any>>): Promise<any> {
6363
const appOutDir = this.computeAppOutDir(outDir, arch)
64-
await this.doPack(await this.computePackOptions(), outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
64+
await this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
6565
postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch, targets))
6666
}
6767

src/macPackager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
6767
}
6868

6969
async pack(outDir: string, arch: Arch, targets: Array<Target>, postAsyncTasks: Array<Promise<any>>): Promise<any> {
70-
const packOptions = await this.computePackOptions()
7170
let nonMasPromise: Promise<any> | null = null
7271

7372
const hasMas = targets.length !== 0 && targets.some(it => it.name === "mas")
7473

7574
if (!hasMas || targets.length > 1) {
7675
const appOutDir = this.computeAppOutDir(outDir, arch)
77-
nonMasPromise = this.doPack(packOptions, outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
76+
nonMasPromise = this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
7877
.then(() => this.sign(appOutDir, null))
7978
.then(() => {
8079
this.packageInDistributableFormat(appOutDir, targets, postAsyncTasks)
@@ -86,7 +85,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
8685
const appOutDir = path.join(outDir, "mas")
8786
const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (<any>this.devMetadata.build).mas)
8887
//noinspection JSUnusedGlobalSymbols
89-
await this.doPack(packOptions, outDir, appOutDir, "mas", arch, masBuildOptions)
88+
await this.doPack(outDir, appOutDir, "mas", arch, masBuildOptions)
9089
await this.sign(appOutDir, masBuildOptions)
9190
}
9291

src/metadata.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AsarOptions } from "asar-electron-builder"
2-
import { ElectronPackagerOptions } from "./packager/dirPackager"
2+
import { PlatformPackager } from "./platformPackager"
33

44
export interface Metadata {
55
readonly repository?: string | RepositoryInfo | null
@@ -91,15 +91,6 @@ export interface BuildMetadata {
9191
*/
9292
readonly appId?: string | null
9393

94-
/*
95-
*macOS-only.* The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.
96-
97-
For example, `"category": "public.app-category.developer-tools"` will set the application category to *Developer Tools*.
98-
99-
Valid values are listed in [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).
100-
*/
101-
readonly category?: string | null
102-
10394
/*
10495
The human-readable copyright line for the app. Defaults to `Copyright © year author`.
10596
*/
@@ -219,7 +210,11 @@ export interface BuildMetadata {
219210

220211
export interface AfterPackContext {
221212
readonly appOutDir: string
222-
readonly options: ElectronPackagerOptions
213+
214+
// deprecated
215+
readonly options: any
216+
217+
readonly packager: PlatformPackager<any>
223218
}
224219

225220
/*
@@ -228,6 +223,15 @@ export interface AfterPackContext {
228223
MacOS specific build options.
229224
*/
230225
export interface MacOptions extends PlatformSpecificBuildOptions {
226+
/*
227+
The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.
228+
229+
For example, `"category": "public.app-category.developer-tools"` will set the application category to *Developer Tools*.
230+
231+
Valid values are listed in [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).
232+
*/
233+
readonly category?: string | null
234+
231235
/*
232236
Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
233237
*/
@@ -262,6 +266,11 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
262266
The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)).
263267
*/
264268
readonly bundleVersion?: string | null
269+
270+
/*
271+
The bundle identifier to use in the application helper's plist. Defaults to `${appBundleIdentifier}.helper`.
272+
*/
273+
readonly helperBundleId?: string | null
265274
}
266275

267276
/*
@@ -432,7 +441,7 @@ export interface NsisOptions {
432441
readonly script?: string | null
433442

434443
/*
435-
* LCID Dec, defaults to `1033`(`English - United States`, see https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx?f=255&MSPPError=-2147217396).
444+
* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).
436445
*/
437446
readonly language?: string | null
438447
}
@@ -443,6 +452,16 @@ export interface NsisOptions {
443452
Linux specific build options.
444453
*/
445454
export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
455+
/*
456+
The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
457+
*/
458+
readonly category?: string | null
459+
460+
/*
461+
The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
462+
*/
463+
readonly packageCategory?: string | null
464+
446465
/*
447466
As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
448467
*/
@@ -475,8 +494,10 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
475494
// should be not documented, only to experiment
476495
readonly fpm?: Array<string> | null
477496

478-
//.desktop file template
479-
readonly desktop?: string | null
497+
/**
498+
The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
499+
*/
500+
readonly desktop?: { [key: string]: string; } | null
480501

481502
readonly afterInstall?: string | null
482503
readonly afterRemove?: string | null

src/packager/dirPackager.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Promise as BluebirdPromise } from "bluebird"
22
import { emptyDir } from "fs-extra-p"
33
import { warn } from "../util/log"
4-
import { AppInfo } from "../appInfo"
54
import { PlatformPackager } from "../platformPackager"
65

76
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download"))
@@ -10,17 +9,6 @@ const extract: any = BluebirdPromise.promisify(require("extract-zip"))
109
//noinspection JSUnusedLocalSymbols
1110
const __awaiter = require("../util/awaiter")
1211

13-
export interface ElectronPackagerOptions {
14-
"extend-info"?: string
15-
16-
appInfo: AppInfo
17-
platformPackager: PlatformPackager<any>
18-
19-
"helper-bundle-id"?: string | null
20-
21-
ignore?: any
22-
}
23-
2412
function createDownloadOpts(opts: any, platform: string, arch: string, electronVersion: string) {
2513
const downloadOpts = Object.assign({
2614
cache: opts.cache,
@@ -40,15 +28,15 @@ function subOptionWarning (properties: any, optionName: any, parameter: any, val
4028
properties[parameter] = value
4129
}
4230

43-
export async function pack(opts: ElectronPackagerOptions, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
31+
export async function pack(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
4432
const zipPath = (await BluebirdPromise.all<any>([
45-
downloadElectron(createDownloadOpts(opts, platform, arch, electronVersion)),
33+
downloadElectron(createDownloadOpts(packager.devMetadata.build, platform, arch, electronVersion)),
4634
emptyDir(out)
4735
]))[0]
4836
await extract(zipPath, {dir: out})
4937

5038
if (platform === "darwin" || platform === "mas") {
51-
await(<any>require("./mac")).createApp(opts, out, initializeApp)
39+
await(<any>require("./mac")).createApp(packager, out, initializeApp)
5240
}
5341
else {
5442
await initializeApp()

0 commit comments

Comments
 (0)