electron-dl
Advanced tools
Comparing version 1.10.0 to 1.11.0
42
index.js
@@ -21,3 +21,3 @@ 'use strict'; | ||
function registerListener(session, opts = {}, cb = () => {}) { | ||
function registerListener(session, options, cb = () => {}) { | ||
const downloadItems = new Set(); | ||
@@ -30,2 +30,6 @@ let receivedBytes = 0; | ||
options = Object.assign({ | ||
showBadge: true | ||
}, options); | ||
const listener = (e, item, webContents) => { | ||
@@ -41,6 +45,6 @@ downloadItems.add(item); | ||
const dir = opts.directory || app.getPath('downloads'); | ||
const dir = options.directory || app.getPath('downloads'); | ||
let filePath; | ||
if (opts.filename) { | ||
filePath = path.join(dir, opts.filename); | ||
if (options.filename) { | ||
filePath = path.join(dir, options.filename); | ||
} else { | ||
@@ -53,6 +57,6 @@ const filename = item.getFilename(); | ||
const errorMessage = opts.errorMessage || 'The download of {filename} was interrupted'; | ||
const errorTitle = opts.errorTitle || 'Download Error'; | ||
const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; | ||
const errorTitle = options.errorTitle || 'Download Error'; | ||
if (!opts.saveAs) { | ||
if (!options.saveAs) { | ||
item.setSavePath(filePath); | ||
@@ -67,3 +71,3 @@ } | ||
if (['darwin', 'linux'].includes(process.platform)) { | ||
if (options.showBadge && ['darwin', 'linux'].includes(process.platform)) { | ||
app.setBadgeCount(activeDownloadItems()); | ||
@@ -76,4 +80,4 @@ } | ||
if (typeof opts.onProgress === 'function') { | ||
opts.onProgress(progressDownloadItems()); | ||
if (typeof options.onProgress === 'function') { | ||
options.onProgress(progressDownloadItems()); | ||
} | ||
@@ -86,3 +90,3 @@ }); | ||
if (['darwin', 'linux'].includes(process.platform)) { | ||
if (options.showBadge && ['darwin', 'linux'].includes(process.platform)) { | ||
app.setBadgeCount(activeDownloadItems()); | ||
@@ -107,7 +111,7 @@ } | ||
if (opts.openFolderWhenDone) { | ||
shell.showItemInFolder(filePath); | ||
if (options.openFolderWhenDone) { | ||
shell.showItemInFolder(path.join(dir, item.getFilename())); | ||
} | ||
if (opts.unregisterWhenDone) { | ||
if (options.unregisterWhenDone) { | ||
session.removeListener('will-download', listener); | ||
@@ -124,12 +128,12 @@ } | ||
module.exports = (opts = {}) => { | ||
module.exports = (options = {}) => { | ||
app.on('session-created', session => { | ||
registerListener(session, opts); | ||
registerListener(session, options); | ||
}); | ||
}; | ||
module.exports.download = (win, url, opts) => new Promise((resolve, reject) => { | ||
opts = Object.assign({}, opts, {unregisterWhenDone: true}); | ||
module.exports.download = (win, url, options) => new Promise((resolve, reject) => { | ||
options = Object.assign({}, options, {unregisterWhenDone: true}); | ||
registerListener(win.webContents.session, opts, (err, item) => { | ||
registerListener(win.webContents.session, options, (err, item) => { | ||
if (err) { | ||
@@ -136,0 +140,0 @@ reject(err); |
{ | ||
"name": "electron-dl", | ||
"version": "1.10.0", | ||
"description": "Simplified file downloads for your Electron app", | ||
"license": "MIT", | ||
"repository": "sindresorhus/electron-dl", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"scripts": { | ||
"start": "electron run.js", | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"electron", | ||
"app", | ||
"file", | ||
"download", | ||
"downloader", | ||
"progress" | ||
], | ||
"dependencies": { | ||
"ext-name": "^5.0.0", | ||
"pupa": "^1.0.0", | ||
"unused-filename": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.21.0", | ||
"cp-file": "^4.2.0", | ||
"electron": "^1.3.3", | ||
"minimist": "^1.2.0", | ||
"node-static": "^0.7.9", | ||
"pify": "^3.0.0", | ||
"spectron": "^3.7.2", | ||
"uuid": "^3.1.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"envs": [ | ||
"node", | ||
"browser" | ||
] | ||
} | ||
"name": "electron-dl", | ||
"version": "1.11.0", | ||
"description": "Simplified file downloads for your Electron app", | ||
"license": "MIT", | ||
"repository": "sindresorhus/electron-dl", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"scripts": { | ||
"start": "electron run.js", | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"electron", | ||
"app", | ||
"file", | ||
"download", | ||
"downloader", | ||
"progress" | ||
], | ||
"dependencies": { | ||
"ext-name": "^5.0.0", | ||
"pupa": "^1.0.0", | ||
"unused-filename": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"cp-file": "^5.0.0", | ||
"electron": "^1.3.3", | ||
"minimist": "^1.2.0", | ||
"node-static": "^0.7.9", | ||
"pify": "^3.0.0", | ||
"spectron": "^3.7.2", | ||
"uuid": "^3.1.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"envs": [ | ||
"node", | ||
"browser" | ||
] | ||
} | ||
} |
# electron-dl [![Build Status](https://travis-ci.org/sindresorhus/electron-dl.svg?branch=master)](https://travis-ci.org/sindresorhus/electron-dl) | ||
> Simplified file downloads for your [Electron](http://electron.atom.io) app | ||
> Simplified file downloads for your [Electron](https://electronjs.org) app | ||
@@ -59,5 +59,7 @@ | ||
It can only be used in the [main](https://electronjs.org/docs/glossary/#main-process) process. | ||
### electronDl([options]) | ||
### electronDl.download(window, url, [options]): Promise<[DownloadItem](https://github.com/electron/electron/blob/master/docs/api/download-item.md)> | ||
### electronDl.download(window, url, [options]): Promise<[DownloadItem](https://electronjs.org/docs/api/download-item)> | ||
@@ -90,3 +92,3 @@ ### window | ||
Type: `string`<br> | ||
Default: [User's downloads directory](http://electron.atom.io/docs/api/app/#appgetpathname) | ||
Default: [User's downloads directory](https://electronjs.org/docs/api/app/#appgetpathname) | ||
@@ -98,3 +100,3 @@ Directory to save the file in. | ||
Type: `string`<br> | ||
Default: [`downloadItem.getFilename()`](https://electron.atom.io/docs/api/download-item/#downloaditemgetfilename) | ||
Default: [`downloadItem.getFilename()`](https://electronjs.org/docs/api/download-item/#downloaditemgetfilename) | ||
@@ -132,3 +134,9 @@ Name of the saved file. | ||
#### showBadge | ||
Type: `boolean`<br> | ||
Default: `true` | ||
Shows the file count badge on macOS/Linux dock icons when download is in progress. | ||
## Development | ||
@@ -135,0 +143,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9488
110
164