[Feature Request]: "blocking" version of setSaveDialogOptions
- Dominant language
- C++
- Stars
- 123k
- Forks
- 17.5k
- Avg merge
- 14h 22m
- Merged PRs (30d)
- 873
Description
### Preflight Checklist
- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.
### Problem Description
I'm writing a file downloader which makes use of `DownloadItem.setSaveDialogOptions()`, and the behavior around it is unintuitive.
- The download / event handlers start during the dialog, when I would expect it to trigger only after the user has confirmed / canceled the dialog
- `item.getFilename()` doesn't update with the filename the user has selected from the dialog
* `item.getSavePath()` will however
- No way of knowing when the dialog action has completed
### Proposed Solution
This might be difficult due to how `setSaveDialogOptions()` is coupled to the `DownloadItem`, but I'd like to see the following:
- A "blocking" version of `setSaveDialogOptions()` - `asyncSetSaveDialogOptions()`?
- When this version is used, the download is "paused" (since it seems the nature of `DownloadItem` is to just immediately download when created), and "resumed" if the user decides to save the file; `DownloadItem.cancel()` is called if the user cancels the dialog. The value returned from `asyncSetSaveDialogOptions()` would be a boolean to indicate if the user has confirmed or denied save.
### Alternatives Considered
**Edit: The below does not work. See comments on why and an actual fix**
Discovered a workaround: don't use `setSaveDialogOptions()` at all, but `dialog.showSaveDialog()` instead:
```typescript
// item from will-download handler
item.pause()
const result = await dialog.showSaveDialog(window, { defaultPath: filePath, ...saveDialogOptions })
if (result.canceled) {
item.cancel()
return
} else {
item.setSavePath(result.filePath!)
item.resume()
}
```
### Additional Information
_No response_
Contributor guide
Research direction
Start with DownloadItem.setSaveDialogOptions(), the will-download handler, and the dialog.showSaveDialog() workaround described in the issue. Trace how pause(), resume(), cancel(), getFilename(), and getSavePath() behave during the save dialog. Done means a blocking option reports whether the user confirmed or canceled and gives the download the expected lifecycle and selected path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript, typescript
- Domain
- api, desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100