Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog options [continuation and fix of #153] #158

Merged
merged 14 commits into from
Nov 10, 2022
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;

/**
Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path.

louis-cf-lin marked this conversation as resolved.
Show resolved Hide resolved
See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties.

@default {}
*/
readonly dialogOptions?: SaveDialogOptions;
}
}

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

if (options.saveAs) {
item.setSaveDialogOptions({defaultPath: filePath});
let saveOptions = options.dialogOptions ? options.dialogOptions : {};
if (!saveOptions.defaultPath) {
saveOptions.defaultPath = filePath;
}
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

item.setSaveDialogOptions(saveOptions);
} 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: `{}`

Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path.

See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties.

## Development

After making changes, run the automated tests:
Expand Down