electron-dl
Advanced tools
Comparing version 1.11.0 to 1.12.0
23
index.js
@@ -8,4 +8,3 @@ 'use strict'; | ||
const app = electron.app; | ||
const shell = electron.shell; | ||
const {app, shell} = electron; | ||
@@ -40,3 +39,3 @@ function getFilenameFromMime(name, mime) { | ||
if (webContents.getType() === 'webview') { | ||
hostWebContents = webContents.hostWebContents; | ||
({hostWebContents} = webContents); | ||
} | ||
@@ -63,2 +62,6 @@ const win = electron.BrowserWindow.fromWebContents(hostWebContents); | ||
if (typeof options.onStarted === 'function') { | ||
options.onStarted(item); | ||
} | ||
item.on('updated', () => { | ||
@@ -98,3 +101,11 @@ receivedBytes = [...downloadItems].reduce((receivedBytes, item) => { | ||
if (state === 'interrupted') { | ||
if (options.unregisterWhenDone) { | ||
session.removeListener('will-download', listener); | ||
} | ||
if (state === 'cancelled') { | ||
if (typeof options.onCancel === 'function') { | ||
options.onCancel(item); | ||
} | ||
} else if (state === 'interrupted') { | ||
const message = pupa(errorMessage, {filename: item.getFilename()}); | ||
@@ -112,6 +123,2 @@ electron.dialog.showErrorBox(errorTitle, message); | ||
if (options.unregisterWhenDone) { | ||
session.removeListener('will-download', listener); | ||
} | ||
cb(null, item); | ||
@@ -118,0 +125,0 @@ } |
{ | ||
"name": "electron-dl", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Simplified file downloads for your Electron app", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -118,2 +118,9 @@ # electron-dl [![Build Status](https://travis-ci.org/sindresorhus/electron-dl.svg?branch=master)](https://travis-ci.org/sindresorhus/electron-dl) | ||
#### onStarted | ||
Type: `Function` | ||
Optional callback that receives the [download item](https://electronjs.org/docs/api/download-item). | ||
You can use this for advanced handling such as canceling the item like `item.cancel()`. | ||
#### onProgress | ||
@@ -125,2 +132,8 @@ | ||
#### onCancel | ||
Type: `Function` | ||
Optional callback that receives the downloadItem for which the download has been cancelled. | ||
#### openFolderWhenDone | ||
@@ -127,0 +140,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
10003
116
177