Skip to content

Commit

Permalink
fix: handle aborted event
Browse files Browse the repository at this point in the history
Close #1975
  • Loading branch information
develar committed Sep 1, 2017
1 parent 723441e commit a7ea361
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ Platform specific `7zip-bin-*` packages are `optionalDependencies`, which may re

## Boilerplates

* [electron-webpack-quick-start](https://github.com/electron-userland/electron-webpack-quick-start) — A bare minimum project structure to get started developing with [electron-webpack](https://github.com/electron-userland/electron-webpack). Recommended.
* [electron-react-boilerplate](https://github.com/chentsulin/electron-react-boilerplate) A boilerplate for scalable cross-platform desktop apps.
* [electron-react-redux-boilerplate](https://github.com/jschr/electron-react-redux-boilerplate) A minimal boilerplate to get started with Electron, React and Redux.
* [electron-boilerplate](https://github.com/szwacz/electron-boilerplate) A minimalistic yet comprehensive boilerplate application.
* [electron-vue](https://github.com/SimulatedGREG/electron-vue) A boilerplate for making electron applications built with vue.
* [electron-webpack](https://github.com/electron-userland/electron-webpack-quick-start) — A bare minimun project structure to get started developing with [`electron-webpack`](https://github.com/electron-userland/electron-webpack).

## Quick Setup Guide

Expand Down Expand Up @@ -72,12 +71,11 @@ Platform specific `7zip-bin-*` packages are `optionalDependencies`, which may re
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps"` to your `package.json`.

5. If you have native addons of your own that are part of the application (not as a dependency), add `"nodeGypRebuild": true` to the `build` section of your development `package.json`.
:bulb: Don't [use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075) [npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm) (neither `.npmrc`) for configuring electron headers. Use [node-gyp-rebuild](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241488783) bin instead.

:bulb: Don't [use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075) [npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm) (neither `.npmrc`) for configuring electron headers. Use `electron-builder node-gyp-rebuild` instead.

6. Install the [required system packages](https://electron.build/multi-platform-build) if you are not on macOS 10.12+.

Please note that everything is packaged into an asar archive [by default](https://electron.build/configuration/configuration#Config-asar).
Please note that everything is packaged into an asar archive [by default](https://electron.build/configuration/configuration#Configuration-asar).

For an app that will be shipped to production, you should sign your application. See [Where to buy code signing certificates](https://electron.build/code-signing#where-to-buy-code-signing-certificate).

Expand All @@ -86,7 +84,7 @@ For an app that will be shipped to production, you should sign your application.
See [Command Line Interface](https://www.electron.build/cli).

## Programmatic Usage
See `node_modules/electron-builder/out/electron-builder.d.ts`. [Typings](https://github.com/Microsoft/TypeScript/wiki/Typings-for-npm-packages) is supported.
See `node_modules/electron-builder/out/index.d.ts`. Typings for TypeScript is provided.

```js
"use strict"
Expand Down Expand Up @@ -122,7 +120,7 @@ and other distributable formats.

## Community

[electron-builder](https://slackin.electron.build) on Slack (please use [threads](https://get.slack.help/hc/en-us/articles/115000769927-Message-threads)).
[electron-builder](https://slackin.electron.build) on Slack (please use [threads](https://get.slack.help/hc/articles/115000769927-Message-threads)).
Public [archive](http://electron-builder.slackarchive.io) without registration.

## Further Reading
Expand Down
2 changes: 1 addition & 1 deletion book.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": "./docs",
"title": "electron-builder",
"plugins": ["edit-link", "github", "github-buttons", "develar-toolbar-buttons", "analytics"],
"plugins": ["edit-link", "github", "github-buttons", "develar-toolbar-buttons", "analytics", "advanced-emoji"],
"pluginsConfig": {
"edit-link": {
"base": "https://github.com/electron-userland/electron-builder/tree/master/docs"
Expand Down
20 changes: 9 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A complete solution to package and build a ready for distribution Electron app f

| Question | Answer |
|--------|-------|
| “I want to configure electron-builder” | [See options](configuration/configuration.md) |
| “I want to configure electron-builder” | [See options](/configuration/configuration.md) |
| “I have a question” | [Open an issue](https://github.com/electron-userland/electron-builder/issues) or [join the chat](https://slackin.electron.build) |
| “I found a bug” | [Open an issue](https://github.com/electron-userland/electron-builder/issues/new) |
| “I want to donate” | [Donate](/donate.md) |
Expand All @@ -37,17 +37,16 @@ Platform specific `7zip-bin-*` packages are `optionalDependencies`, which may re

## Boilerplates

* [electron-webpack-quick-start](https://github.com/electron-userland/electron-webpack-quick-start) — A bare minimum project structure to get started developing with [electron-webpack](https://github.com/electron-userland/electron-webpack). Recommended.
* [electron-react-boilerplate](https://github.com/chentsulin/electron-react-boilerplate) A boilerplate for scalable cross-platform desktop apps.
* [electron-react-redux-boilerplate](https://github.com/jschr/electron-react-redux-boilerplate) A minimal boilerplate to get started with Electron, React and Redux.
* [electron-boilerplate](https://github.com/szwacz/electron-boilerplate) A minimalistic yet comprehensive boilerplate application.
* [electron-vue](https://github.com/SimulatedGREG/electron-vue) A boilerplate for making electron applications built with vue.
* [electron-webpack](https://github.com/electron-userland/electron-webpack-quick-start) — A bare minimun project structure to get started developing with [`electron-webpack`](https://github.com/electron-userland/electron-webpack).

## Quick Setup Guide

1. Specify the standard fields in the application `package.json`[name](configuration/configuration.md#Metadata-name), `description`, `version` and [author](https://docs.npmjs.com/files/package.json#people-fields-author-contributors).
1. Specify the standard fields in the application `package.json`[name](/configuration/configuration.md#Metadata-name), `description`, `version` and [author](https://docs.npmjs.com/files/package.json#people-fields-author-contributors).

2. Specify the [build](configuration/configuration.md#configuration) configuration in the `package.json` as follows:
2. Specify the [build](/configuration/configuration.md#configuration) configuration in the `package.json` as follows:
```json
"build": {
"appId": "your.id",
Expand All @@ -56,9 +55,9 @@ Platform specific `7zip-bin-*` packages are `optionalDependencies`, which may re
}
}
```
See [all options](configuration/configuration.md#configuration).
See [all options](/configuration/configuration.md#configuration).

3. Add [icons](icons.md).
3. Add [icons](/icons.md).

4. Add the [scripts](https://docs.npmjs.com/cli/run-script) key to the development `package.json`:
```json
Expand All @@ -72,8 +71,7 @@ Platform specific `7zip-bin-*` packages are `optionalDependencies`, which may re
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps"` to your `package.json`.

5. If you have native addons of your own that are part of the application (not as a dependency), add `"nodeGypRebuild": true` to the `build` section of your development `package.json`.
:bulb: Don't [use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075) [npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm) (neither `.npmrc`) for configuring electron headers. Use [node-gyp-rebuild](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241488783) bin instead.

:bulb: Don't [use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075) [npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm) (neither `.npmrc`) for configuring electron headers. Use `electron-builder node-gyp-rebuild` instead.

6. Install the [required system packages](multi-platform-build.md) if you are not on macOS 10.12+.

Expand All @@ -82,7 +80,7 @@ Please note that everything is packaged into an asar archive [by default](config
For an app that will be shipped to production, you should sign your application. See [Where to buy code signing certificates](code-signing.md#where-to-buy-code-signing-certificate).

## Programmatic Usage
See `node_modules/electron-builder/out/electron-builder.d.ts`. [Typings](https://github.com/Microsoft/TypeScript/wiki/Typings-for-npm-packages) is supported.
See `node_modules/electron-builder/out/index.d.ts`. Typings for TypeScript is provided.

```js
"use strict"
Expand Down Expand Up @@ -118,5 +116,5 @@ and other distributable formats.

## Community

[electron-builder](https://slackin.electron.build) on Slack (please use [threads](https://get.slack.help/hc/en-us/articles/115000769927-Message-threads)).
[electron-builder](https://slackin.electron.build) on Slack (please use [threads](https://get.slack.help/hc/articles/115000769927-Message-threads)).
Public [archive](http://electron-builder.slackarchive.io) without registration.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"electron-builder-tslint-config": "^1.0.4",
"env-paths": "^1.0.0",
"finalhandler": "^1.0.4",
"gitbook-plugin-advanced-emoji": "^0.2.2",
"gitbook-plugin-analytics": "^0.2.1",
"gitbook-plugin-develar-toolbar-buttons": "^1.0.2",
"gitbook-plugin-edit-link": "^2.0.2",
Expand Down
9 changes: 6 additions & 3 deletions packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createHash, Hash } from "crypto"
import _debug from "debug"
import { EventEmitter } from "events"
import { createWriteStream } from "fs-extra-p"
import { IncomingMessage, RequestOptions } from "http"
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http"
import { Socket } from "net"
import { Transform } from "stream"
import { parse as parseUrl } from "url"
Expand All @@ -14,7 +14,7 @@ export { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTrans

const debug = _debug("electron-builder")

export interface RequestHeaders {
export interface RequestHeaders extends OutgoingHttpHeaders {
[key: string]: string
}

Expand All @@ -32,7 +32,7 @@ export interface Response extends EventEmitter {
}

export interface DownloadOptions {
readonly headers?: RequestHeaders | null
readonly headers?: OutgoingHttpHeaders | null
readonly skipDirCreation?: boolean
readonly sha2?: string | null
readonly sha512?: string | null
Expand Down Expand Up @@ -151,6 +151,9 @@ export abstract class HttpExecutor<REQUEST> {
})
this.addTimeOutHandler(request, callback)
request.on("error", callback)
request.on("aborted", () => {
callback(new Error("Request has been aborted by the server"))
})
onCancel(() => request.abort())
request.end()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/fileTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function createElectronCompilerHost(projectDir: string, cacheDir: string)
return require(path.join(electronCompilePath, "config-parser")).createCompilerHostFromProjectRoot(projectDir, cacheDir)
}

const ignoredPackageMetadataProperties = new Set(["dist", "gitHead", "keywords", "build", "devDependencies", "scripts", "jspm", "ava", "xo", "nyc", "eslintConfig"])
const ignoredPackageMetadataProperties = new Set(["dist", "gitHead", "keywords", "build", "scripts", "jspm", "ava", "xo", "nyc", "eslintConfig"])

function cleanupPackageJson(data: any, isMain: boolean): any {
const deps = data.dependencies
Expand Down
6 changes: 6 additions & 0 deletions packages/electron-updater/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 2.8.8 (2017-09-01)


### Bug Fixes

* fix: handle aborted event (https://github.com/electron-userland/electron-builder/issues/1975).
15 changes: 4 additions & 11 deletions packages/electron-updater/src/electronHttpExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _debug from "debug"
import { net, session } from "electron"
import { CancellationToken, configureRequestOptions, DownloadOptions, dumpRequestOptions, HttpExecutor, RequestOptionsEx } from "electron-builder-http"
import { CancellationToken, configureRequestOptions, configureRequestOptionsFromUrl, DownloadOptions, dumpRequestOptions, HttpExecutor, RequestOptionsEx } from "electron-builder-http"
import { ensureDir } from "fs-extra-p"
import * as path from "path"
import { parse as parseUrl } from "url"

export const NET_SESSION_NAME = "electron-updater"

Expand All @@ -12,7 +11,7 @@ const debug = _debug("electron-builder")
export type LoginCallback = (username: string, password: string) => void

export class ElectronHttpExecutor extends HttpExecutor<Electron.ClientRequest> {
constructor(private proxyLoginCallback?: (authInfo: any, callback: LoginCallback) => void) {
constructor(private readonly proxyLoginCallback?: (authInfo: any, callback: LoginCallback) => void) {
super()
}

Expand All @@ -22,15 +21,9 @@ export class ElectronHttpExecutor extends HttpExecutor<Electron.ClientRequest> {
}

return await options.cancellationToken.createPromise<string>((resolve, reject, onCancel) => {
const parsedUrl = parseUrl(url)

this.doDownload(configureRequestOptions({
protocol: parsedUrl.protocol,
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port ? parseInt(parsedUrl.port, 10) : undefined,
this.doDownload(configureRequestOptions(configureRequestOptionsFromUrl(url, {
headers: options.headers || undefined,
}), destination, 0, options, (error: Error) => {
})), destination, 0, options, (error: Error) => {
if (error == null) {
resolve(destination)
}
Expand Down
6 changes: 3 additions & 3 deletions test/out/mac/__snapshots__/macArchiveTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ exports[`invalid target 1`] = `
object { artifactName?, asar?, asarUnpack?, binaries?, bundleVersion?, category?, entitlements?, entitlementsInherit?, extendInfo?, extraFiles?, extraResources?, fileAssociations?, files?, forceCodeSigning?, helperBundleId?, icon?, identity?, publish?, requirements?, target?, type? } | {
\\"type\\": \\"null\\"
}
macOS options.
Options related to how build macOS targets.
Details:
* configuration.mac.target should be an object.
* configuration.mac.target[0] should be an object.
Expand All @@ -39,7 +39,7 @@ exports[`invalid target 1`] = `
\\"type\\": \\"null\\"
}
The target package type: list of \`default\`, \`dmg\`, \`mas\`, \`pkg\`, \`7z\`, \`zip\`, \`tar.xz\`, \`tar.lz\`, \`tar.gz\`, \`tar.bz2\`, \`dir\`. Defaults to \`default\` (dmg and zip for Squirrel.Mac).
* configuration.mac should be null:
{
\\"type\\": \\"null\\"
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,10 @@ electron-osx-sign@0.4.7:
minimist "^1.2.0"
plist "^2.1.0"

emojify.js@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/emojify.js/-/emojify.js-1.1.0.tgz#079fff223307c9007f570785e8e4935d5c398beb"

encodeurl@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"
Expand Down Expand Up @@ -1534,6 +1538,12 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

gitbook-plugin-advanced-emoji@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/gitbook-plugin-advanced-emoji/-/gitbook-plugin-advanced-emoji-0.2.2.tgz#08bcc69f62a749cd69204435276518c941c319e3"
dependencies:
emojify.js "^1.1.0"

gitbook-plugin-analytics@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/gitbook-plugin-analytics/-/gitbook-plugin-analytics-0.2.1.tgz#272056a03c7edb5a800860b318e29e6bcdc22522"
Expand Down

0 comments on commit a7ea361

Please sign in to comment.