Skip to content

Commit d987a28

Browse files
committed
Improve error when relative path is passed to the directory option
Closes #143
1 parent 972e0e8 commit d987a28

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ declare namespace electronDl {
2626
readonly saveAs?: boolean;
2727

2828
/**
29-
Directory to save the file in.
29+
The directory to save the file in.
30+
31+
Must be an absolute path.
3032
3133
Default: [User's downloads directory](https://electronjs.org/docs/api/app/#appgetpathname)
3234
*/

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ function registerListener(session, options, callback = () => {}) {
6767

6868
const window_ = majorElectronVersion() >= 12 ? BrowserWindow.fromWebContents(webContents) : getWindowFromWebContents(webContents);
6969

70+
if (options.directory && !path.isAbsolute(options.directory)) {
71+
throw new Error('The `directory` option must be an absolute path');
72+
}
73+
7074
const directory = options.directory || app.getPath('downloads');
75+
7176
let filePath;
7277
if (options.filename) {
7378
filePath = path.join(directory, options.filename);

index.test-d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference lib="dom"/>
2-
/// <reference types="node"/>
31
import {expectType} from 'tsd';
42
import {BrowserWindow, DownloadItem} from 'electron';
53
import electronDl = require('.');

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ Note: Only use this option when strictly necessary. Downloading directly without
9292
Type: `string`\
9393
Default: [User's downloads directory](https://electronjs.org/docs/api/app/#appgetpathname)
9494

95-
Directory to save the file in.
95+
The directory to save the file in.
96+
97+
Must be an absolute path.
9698

9799
#### filename
98100

0 commit comments

Comments
 (0)