Skip to content

Commit

Permalink
feat(linux): Categories desktop entry
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Sep 7, 2016
1 parent 1b90ec6 commit 87616c0
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 120 deletions.
8 changes: 6 additions & 2 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Don't customize paths to background and icon, — just follow conventions.
| Name | Description
| --- | ---
| 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>
| 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>
| copyright | <a name="BuildMetadata-copyright"></a>The human-readable copyright line for the app. Defaults to `Copyright © year author`.
| 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>
| productName | <a name="BuildMetadata-productName"></a>See [AppMetadata.productName](#AppMetadata-productName).
Expand All @@ -76,12 +75,14 @@ MacOS specific build options.

| Name | Description
| --- | ---
| 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>
| 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).
| 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>
| 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).
| 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>
| 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>
| 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)).
| helperBundleId | <a name="MacOptions-helperBundleId"></a>The bundle identifier to use in the application helper's plist. Defaults to `${appBundleIdentifier}.helper`.

<a name="DmgOptions"></a>
### `.build.dmg`
Expand Down Expand Up @@ -142,7 +143,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| 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.
| 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).
| 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).
| 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).
| language | <a name="NsisOptions-language"></a>* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).

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

| Name | Description
| --- | ---
| category | <a name="LinuxBuildOptions-category"></a>The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
| 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.
| description | <a name="LinuxBuildOptions-description"></a>As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
| 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>
| synopsis | <a name="LinuxBuildOptions-synopsis"></a>*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
| maintainer | <a name="LinuxBuildOptions-maintainer"></a>The maintainer. Defaults to [author](#AppMetadata-author).
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).
| desktop | <a name="LinuxBuildOptions-desktop"></a>The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.

Expand Down
9 changes: 0 additions & 9 deletions src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ export class AppInfo {
return this.metadata.name
}

get category() {
const metadata = this.devMetadata.build
const old = (<any>metadata)["app-category-type"]
if (old != null) {
warn('"app-category-type" is deprecated — please use "category" instead')
}
return metadata.category || old
}

get copyright(): string {
const metadata = this.devMetadata.build
const old = (<any>metadata)["app-copyright"]
Expand Down
2 changes: 1 addition & 1 deletion src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {

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

Expand Down
5 changes: 2 additions & 3 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
}

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

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

if (!hasMas || targets.length > 1) {
const appOutDir = this.computeAppOutDir(outDir, arch)
nonMasPromise = this.doPack(packOptions, outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
nonMasPromise = this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
.then(() => this.sign(appOutDir, null))
.then(() => {
this.packageInDistributableFormat(appOutDir, targets, postAsyncTasks)
Expand All @@ -86,7 +85,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
const appOutDir = path.join(outDir, "mas")
const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (<any>this.devMetadata.build).mas)
//noinspection JSUnusedGlobalSymbols
await this.doPack(packOptions, outDir, appOutDir, "mas", arch, masBuildOptions)
await this.doPack(outDir, appOutDir, "mas", arch, masBuildOptions)
await this.sign(appOutDir, masBuildOptions)
}

Expand Down
49 changes: 35 additions & 14 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsarOptions } from "asar-electron-builder"
import { ElectronPackagerOptions } from "./packager/dirPackager"
import { PlatformPackager } from "./platformPackager"

export interface Metadata {
readonly repository?: string | RepositoryInfo | null
Expand Down Expand Up @@ -91,15 +91,6 @@ export interface BuildMetadata {
*/
readonly appId?: string | null

/*
*macOS-only.* The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.
For example, `"category": "public.app-category.developer-tools"` will set the application category to *Developer Tools*.
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).
*/
readonly category?: string | null

/*
The human-readable copyright line for the app. Defaults to `Copyright © year author`.
*/
Expand Down Expand Up @@ -219,7 +210,11 @@ export interface BuildMetadata {

export interface AfterPackContext {
readonly appOutDir: string
readonly options: ElectronPackagerOptions

// deprecated
readonly options: any

readonly packager: PlatformPackager<any>
}

/*
Expand All @@ -228,6 +223,15 @@ export interface AfterPackContext {
MacOS specific build options.
*/
export interface MacOptions extends PlatformSpecificBuildOptions {
/*
The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.
For example, `"category": "public.app-category.developer-tools"` will set the application category to *Developer Tools*.
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).
*/
readonly category?: string | null

/*
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).
*/
Expand Down Expand Up @@ -262,6 +266,11 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)).
*/
readonly bundleVersion?: string | null

/*
The bundle identifier to use in the application helper's plist. Defaults to `${appBundleIdentifier}.helper`.
*/
readonly helperBundleId?: string | null
}

/*
Expand Down Expand Up @@ -432,7 +441,7 @@ export interface NsisOptions {
readonly script?: string | null

/*
* LCID Dec, defaults to `1033`(`English - United States`, see https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx?f=255&MSPPError=-2147217396).
* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).
*/
readonly language?: string | null
}
Expand All @@ -443,6 +452,16 @@ export interface NsisOptions {
Linux specific build options.
*/
export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
/*
The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
*/
readonly category?: string | null

/*
The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
*/
readonly packageCategory?: string | null

/*
As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
*/
Expand Down Expand Up @@ -475,8 +494,10 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
// should be not documented, only to experiment
readonly fpm?: Array<string> | null

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

readonly afterInstall?: string | null
readonly afterRemove?: string | null
Expand Down
18 changes: 3 additions & 15 deletions src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Promise as BluebirdPromise } from "bluebird"
import { emptyDir } from "fs-extra-p"
import { warn } from "../util/log"
import { AppInfo } from "../appInfo"
import { PlatformPackager } from "../platformPackager"

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

export interface ElectronPackagerOptions {
"extend-info"?: string

appInfo: AppInfo
platformPackager: PlatformPackager<any>

"helper-bundle-id"?: string | null

ignore?: any
}

function createDownloadOpts(opts: any, platform: string, arch: string, electronVersion: string) {
const downloadOpts = Object.assign({
cache: opts.cache,
Expand All @@ -40,15 +28,15 @@ function subOptionWarning (properties: any, optionName: any, parameter: any, val
properties[parameter] = value
}

export async function pack(opts: ElectronPackagerOptions, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
export async function pack(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(createDownloadOpts(opts, platform, arch, electronVersion)),
downloadElectron(createDownloadOpts(packager.devMetadata.build, platform, arch, electronVersion)),
emptyDir(out)
]))[0]
await extract(zipPath, {dir: out})

if (platform === "darwin" || platform === "mas") {
await(<any>require("./mac")).createApp(opts, out, initializeApp)
await(<any>require("./mac")).createApp(packager, out, initializeApp)
}
else {
await initializeApp()
Expand Down
Loading

0 comments on commit 87616c0

Please sign in to comment.