diff --git a/index.d.ts b/index.d.ts index 0afb5fe..66ffa8f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -import {BrowserView, BrowserWindow, DownloadItem} from 'electron'; +import {BrowserView, BrowserWindow, DownloadItem, SaveDialogOptions} from 'electron'; declare namespace electronDl { interface Progress { @@ -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; } } diff --git a/index.js b/index.js index b52440d..cb0879f 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/readme.md b/readme.md index b91680b..5a49a78 100644 --- a/readme.md +++ b/readme.md @@ -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: