Skip to content

Commit

Permalink
Add dialogOptions options (#158)
Browse files Browse the repository at this point in the history
Co-authored-by: Pio Neto <pio.neto@db1.com.br>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
3 people authored Nov 10, 2022
1 parent 3c3a7c2 commit 3927689
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BrowserView, BrowserWindow, DownloadItem} from 'electron';
import {BrowserView, BrowserWindow, DownloadItem, SaveDialogOptions} from 'electron';

declare namespace electronDl {
interface Progress {
Expand Down Expand Up @@ -118,6 +118,15 @@ declare namespace electronDl {
@default false
*/
readonly overwrite?: boolean;

/**
Customize the save dialog.
If `defaultPath` is not explicity defined, a default value is assigned based on the file path.
@default {}
*/
readonly dialogOptions?: SaveDialogOptions;
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function registerListener(session, options, callback = () => {}) {
const errorMessage = options.errorMessage || 'The download of {filename} was interrupted';

if (options.saveAs) {
item.setSaveDialogOptions({defaultPath: filePath});
item.setSaveDialogOptions({defaultPath: filePath, ...options.dialogOptions});
} else {
item.setSavePath(filePath);
}
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ Allow downloaded files to overwrite files with the same name in the directory th

The default behavior is to append a number to the filename.

#### dialogOptions

Type: [`SaveDialogOptions`](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions)\
Default: `{}`

Customize the save dialog.

If `defaultPath` is not explicity defined, a default value is assigned based on the file path.

## Development

After making changes, run the automated tests:
Expand Down

0 comments on commit 3927689

Please sign in to comment.