Skip to content

Commit

Permalink
feat: custom app scheme
Browse files Browse the repository at this point in the history
Closes #575
  • Loading branch information
develar committed Aug 22, 2016
1 parent e3a5899 commit b7121c5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 23 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Here documented only `electron-builder` specific options:
| files | <a name="BuildMetadata-files"></a><p>A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.</p> <p>See [File Patterns](#multiple-glob-patterns).</p>
| extraResources | <a name="BuildMetadata-extraResources"></a><p>A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the project directory, when specified, copy the file or directory with matching names directly into the app’s resources directory (<code>Contents/Resources</code> for MacOS, <code>resources</code> for Linux/Windows).</p> <p>Glob rules the same as for [files](#multiple-glob-patterns).</p>
| extraFiles | <a name="BuildMetadata-extraFiles"></a>The same as [extraResources](#BuildMetadata-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows).
| fileAssociations | <a name="BuildMetadata-fileAssociations"></a>File associations. See [.build.fileAssociations](#FileAssociation).
| fileAssociations | <a name="BuildMetadata-fileAssociations"></a>The file associations. See [.build.fileAssociations](#FileAssociation).
| protocols | <a name="BuildMetadata-protocols"></a>The URL protocol scheme(s) to associate the app with. See [.build.protocol](#Protocol).
| mac | <a name="BuildMetadata-mac"></a>See [.build.mac](#MacOptions).
| dmg | <a name="BuildMetadata-dmg"></a>See [.build.dmg](#DmgOptions).
| mas | <a name="BuildMetadata-mas"></a>See [.build.mas](#MasBuildOptions).
Expand Down Expand Up @@ -172,6 +173,16 @@ NSIS only, [in progress](/~https://github.com/electron-userland/electron-builder/i
| description | <a name="FileAssociation-description"></a>*windows-only.* The description.
| icon | <a name="FileAssociation-icon"></a>*windows-only.* The path to icon (`.ico`), relative to `build` (build resources directory). Defaults to `${ext}.ico`.

<a name="Protocol"></a>
### `.build.protocols`

macOS only.

| Name | Description
| --- | ---
| **name** | <a name="Protocol-name"></a>The name. e.g. `IRC server URL`
| **schemes** | <a name="Protocol-schemes"></a>The schemes. e.g. `["irc", "ircs"]`

<a name="MetadataDirectories"></a>
## `.directories`
| Name | Description
Expand Down
28 changes: 25 additions & 3 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ export interface BuildMetadata {
readonly extraFiles?: Array<string> | string | null

/*
File associations. See [.build.fileAssociations](#FileAssociation).
The file associations. See [.build.fileAssociations](#FileAssociation).
*/
readonly fileAssociations?: Array<FileAssociation> | FileAssociation

/*
The URL protocol scheme(s) to associate the app with. See [.build.protocol](#Protocol).
*/
readonly protocols?: Array<Protocol> | Protocol

/*
See [.build.mac](#MacOptions).
*/
Expand Down Expand Up @@ -490,12 +495,12 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
*/
export interface FileAssociation {
/*
The extension (minus the leading period). e.g. `png`
The extension (minus the leading period). e.g. `png`.
*/
readonly ext: string

/*
The name. e.g. `PNG`
The name. e.g. `PNG`.
*/
readonly name: string

Expand All @@ -510,6 +515,23 @@ export interface FileAssociation {
readonly icon?: string
}

/*
### `.build.protocols`
macOS only.
*/
export interface Protocol {
/*
The name. e.g. `IRC server URL`.
*/
readonly name: string

/*
The schemes. e.g. `["irc", "ircs"]`.
*/
readonly schemes: Array<string>
}

/*
## `.directories`
*/
Expand Down
3 changes: 1 addition & 2 deletions src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { emptyDir } from "fs-extra-p"
import { warn } from "../util/log"
import { AppInfo } from "../appInfo"
import { PlatformPackager } from "../platformPackager"
import { Protocol } from "../metadata"

const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download"))
const extract: any = BluebirdPromise.promisify(require("extract-zip"))
Expand All @@ -13,8 +14,6 @@ const __awaiter = require("../util/awaiter")
export interface ElectronPackagerOptions {
"extend-info"?: string

protocols?: any

appInfo: AppInfo
platformPackager: PlatformPackager<any>

Expand Down
9 changes: 5 additions & 4 deletions src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rename, readFile, writeFile, copy } from "fs-extra-p"
import * as path from "path"
import { parse as parsePlist, build as buildPlist } from "plist"
import { Promise as BluebirdPromise } from "bluebird"
import { use } from "../util/util"
import { use, asArray } from "../util/util"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../util/awaiter")
Expand Down Expand Up @@ -79,11 +79,12 @@ export async function createApp(opts: ElectronPackagerOptions, appOutDir: string
})
use(appInfo.buildVersion, it => appPlist.CFBundleVersion = it)

if (opts.protocols && opts.protocols.length) {
appPlist.CFBundleURLTypes = opts.protocols.map(function (protocol: any) {
const protocols = asArray(opts.platformPackager.devMetadata.build.protocols).concat(asArray(opts.platformPackager.platformSpecificBuildOptions.protocols))
if (protocols.length > 0) {
appPlist.CFBundleURLTypes = protocols.map(protocol => {
return {
CFBundleURLName: protocol.name,
CFBundleURLSchemes: [].concat(protocol.schemes)
CFBundleURLSchemes: protocol.schemes.slice()
}
})
}
Expand Down
14 changes: 1 addition & 13 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WinPackager } from "../winPackager"
import { Arch, NsisOptions, FileAssociation } from "../metadata"
import { exec, debug, doSpawn, handleProcess, use } from "../util/util"
import { exec, debug, doSpawn, handleProcess, use, asArray } from "../util/util"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { getBinFromBintray } from "../util/binDownload"
Expand Down Expand Up @@ -285,16 +285,4 @@ export default class NsisTarget extends Target {
// remove leading dot
function normalizeExt(ext: string) {
return ext.startsWith(".") ? ext.substring(1) : ext
}

function asArray<T>(v: n | T | Array<T>): Array<T> {
if (v == null) {
return []
}
else if (Array.isArray(v)) {
return v
}
else {
return [v]
}
}
12 changes: 12 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,16 @@ export function unlinkIfExists(file: string) {
.catch(() => {
// ignore
})
}

export function asArray<T>(v: n | T | Array<T>): Array<T> {
if (v == null) {
return []
}
else if (Array.isArray(v)) {
return v
}
else {
return [v]
}
}

0 comments on commit b7121c5

Please sign in to comment.