electron-dl
Advanced tools
Comparing version 1.14.0 to 2.0.0
import {BrowserWindow, DownloadItem} from 'electron'; | ||
declare namespace electronDl { | ||
interface Progress { | ||
percent: number; | ||
transferredBytes: number; | ||
totalBytes: number; | ||
} | ||
interface Options { | ||
@@ -50,5 +56,5 @@ /** | ||
/** | ||
Optional callback that receives a number between `0` and `1` representing the progress of the current download. | ||
Optional callback that receives an object containing information about the progress of the current download item. | ||
*/ | ||
readonly onProgress?: (percent: number) => void; | ||
readonly onProgress?: (progress: Progress) => void; | ||
@@ -119,7 +125,4 @@ /** | ||
): Promise<DownloadItem>; | ||
// TODO: Remove this for the next major release | ||
default: typeof electronDl; | ||
}; | ||
export = electronDl; |
12
index.js
@@ -78,3 +78,10 @@ 'use strict'; | ||
if (typeof options.onProgress === 'function') { | ||
options.onProgress(progressDownloadItems()); | ||
const itemTransferredBytes = item.getReceivedBytes(); | ||
const itemTotalBytes = item.getTotalBytes(); | ||
options.onProgress({ | ||
percent: itemTotalBytes ? itemTransferredBytes / itemTotalBytes : 0, | ||
transferredBytes: itemTransferredBytes, | ||
totalBytes: itemTotalBytes | ||
}); | ||
} | ||
@@ -133,5 +140,2 @@ }); | ||
// TODO: Remove this for the next major release | ||
module.exports.default = module.exports; | ||
module.exports.download = (win, url, options) => new Promise((resolve, reject) => { | ||
@@ -138,0 +142,0 @@ options = Object.assign({}, options, {unregisterWhenDone: true}); |
{ | ||
"name": "electron-dl", | ||
"version": "1.14.0", | ||
"version": "2.0.0", | ||
"description": "Simplified file downloads for your Electron app", | ||
@@ -30,17 +30,17 @@ "license": "MIT", | ||
"ext-name": "^5.0.0", | ||
"pupa": "^1.0.0", | ||
"unused-filename": "^1.0.0" | ||
"pupa": "^2.0.1", | ||
"unused-filename": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^11.13.0", | ||
"ava": "^1.4.1", | ||
"cp-file": "^6.2.0", | ||
"electron": "^3.1.2", | ||
"@types/node": "^12.12.8", | ||
"ava": "^2.4.0", | ||
"cp-file": "^7.0.0", | ||
"electron": "^7.1.2", | ||
"minimist": "^1.2.0", | ||
"node-static": "^0.7.11", | ||
"pify": "^4.0.1", | ||
"spectron": "^5.0.0", | ||
"tsd": "^0.7.2", | ||
"spectron": "^9.0.0", | ||
"tsd": "^0.11.0", | ||
"uuid": "^3.3.2", | ||
"xo": "^0.24.0" | ||
"xo": "^0.25.3" | ||
}, | ||
@@ -47,0 +47,0 @@ "xo": { |
@@ -61,5 +61,5 @@ # electron-dl [](https://travis-ci.org/sindresorhus/electron-dl) | ||
### electronDl([options]) | ||
### electronDl(options?) | ||
### electronDl.download(window, url, [options]): Promise<[DownloadItem](https://electronjs.org/docs/api/download-item)> | ||
### electronDl.download(window, url, options?): Promise<[DownloadItem](https://electronjs.org/docs/api/download-item)> | ||
@@ -80,7 +80,7 @@ ### window | ||
Type: `Object` | ||
Type: `object` | ||
#### saveAs | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -94,3 +94,3 @@ | ||
Type: `string`<br> | ||
Type: `string`\ | ||
Default: [User's downloads directory](https://electronjs.org/docs/api/app/#appgetpathname) | ||
@@ -102,3 +102,3 @@ | ||
Type: `string`<br> | ||
Type: `string`\ | ||
Default: [`downloadItem.getFilename()`](https://electronjs.org/docs/api/download-item/#downloaditemgetfilename) | ||
@@ -112,4 +112,4 @@ | ||
Type: `string`<br> | ||
Default: `Download Error` | ||
Type: `string`\ | ||
Default: `'Download Error'` | ||
@@ -120,4 +120,4 @@ Title of the error dialog. Can be customized for localization. | ||
Type: `string`<br> | ||
Default: `The download of {filename} was interrupted` | ||
Type: `string`\ | ||
Default: `'The download of {filename} was interrupted'` | ||
@@ -137,4 +137,12 @@ Message of the error dialog. `{filename}` is replaced with the name of the actual file. Can be customized for localization. | ||
Optional callback that receives a number between `0` and `1` representing the progress of the current download. | ||
Optional callback that receives an object containing information about the progress of the current download item. | ||
```js | ||
{ | ||
percent: 0.1, | ||
transferredBytes: 100, | ||
totalBytes: 1000 | ||
} | ||
``` | ||
#### onCancel | ||
@@ -148,3 +156,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -156,3 +164,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -184,6 +192,1 @@ | ||
- [electron-unhandled](https://github.com/sindresorhus/electron-unhandled) - Catch unhandled errors and promise rejections in your Electron app | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
13538
219
183
+ Addedescape-goat@2.1.1(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpupa@2.1.1(transitive)
+ Addedunused-filename@2.1.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpupa@1.0.0(transitive)
- Removedunused-filename@1.0.0(transitive)
Updatedpupa@^2.0.1
Updatedunused-filename@^2.1.0