Skip to content

fix: use Downloads folder as default path for file dialogs - #49538

Closed
souravxbera wants to merge 4 commits into
electron:mainfrom
souravxbera:fix/file-dialog-default-path
Closed

souravxbera wants to merge 4 commits into
electron:mainfrom
souravxbera:fix/file-dialog-default-path

Conversation

@souravxbera

Copy link
Copy Markdown
Contributor

Description of Change

Fixes file dialogs opening in CWD when no defaultPath is provided. Dialogs now default to the user's Downloads folder (or Home directory if Downloads doesn't exist) instead of the current working directory.

Closes #49237

My Approach: Added GetSmartDefaultPath() helper function across all platforms that:

  1. Tries Downloads folder first (DIR_DEFAULT_DOWNLOADS)
  2. Falls back to Home directory if Downloads doesn't exist
  3. Returns empty path if neither exists (system default)

This only affects dialogs when no defaultPath is explicitly provided, so existing code that specifies a path continues to work unchanged.

Checklist

Release Notes

Notes: File dialogs now default to the Downloads folder when no defaultPath is specified, improving UX by opening in a location users expect instead of the current working directory.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jan 26, 2026
@souravxbera

Copy link
Copy Markdown
Contributor Author

Hi maintainers! 👋

Could someone please add the semver/patch label when you have a moment??

This is a component enhancement that makes file dialogs default to the Downloads folder (with Home directory fallback) instead of CWD when no defaultPath is specified. No breaking changes or new APIs added.

Thanks!

@souravxbera
souravxbera marked this pull request as ready for review January 27, 2026 07:31
Comment thread shell/browser/ui/file_dialog_win.cc Resolved
Comment thread shell/browser/ui/file_dialog_win.cc Resolved
@souravxbera
souravxbera force-pushed the fix/file-dialog-default-path branch from 0dbe675 to 9543e4a Compare January 27, 2026 11:12
@souravxbera
souravxbera marked this pull request as draft January 27, 2026 11:33
@souravxbera

Copy link
Copy Markdown
Contributor Author

@codebytere Thanks for the review!
About the GetDefaultPath() duplication - it's in an anonymous namespace in each platform file since they compile separately for Windows/macOS/Linux. I kept it this way to avoid a larger refactoring, but I'm happy to do a follow-up PR to move it to a shared header (like file_dialog.h) if you'd prefer.
Let me know if you want me to tackle that or if the current approach is fine for now.

@souravxbera
souravxbera marked this pull request as ready for review January 27, 2026 11:39
@souravxbera

Copy link
Copy Markdown
Contributor Author

Hi @codebytere , just a quick ping to let you know I’ve addressed the suggested changes and pushed the updates. Please let me know if anything else is needed. Thanks!

@codebytere

Copy link
Copy Markdown
Member

@sbera01

About the GetDefaultPath() duplication - it's in an anonymous namespace in each platform file since they compile separately for Windows/macOS/Linux.

i'm well aware of this, yes. Please extract the helper into shell/common/electron_paths.h in this PR.

@souravxbera
souravxbera force-pushed the fix/file-dialog-default-path branch 2 times, most recently from c6dbbeb to b504a95 Compare January 29, 2026 21:37
@souravxbera

Copy link
Copy Markdown
Contributor Author

Done! GetDefaultPath() is now in electron_paths.h as requested. @codebytere PTAL !!
Thanks.

@souravxbera
souravxbera force-pushed the fix/file-dialog-default-path branch from b504a95 to 1da35b8 Compare January 31, 2026 19:57
@souravxbera

souravxbera commented Jan 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey, I have rebased it on latest main and resolved merge conflicts with the PathProvider changes. PTAL.
Thanks!

Comment thread shell/browser/ui/file_dialog_mac.mm Resolved
Comment thread shell/browser/ui/file_dialog_mac.mm Resolved
Comment thread shell/browser/ui/file_dialog_win.cc Resolved
Comment thread shell/browser/ui/file_dialog_win.cc Resolved
Comment thread shell/browser/ui/file_dialog_linux.cc Resolved
Comment thread shell/browser/ui/file_dialog_linux.cc Resolved
@souravxbera

Copy link
Copy Markdown
Contributor Author

Oops, my mistake, thanks for catching that! I’ll clean it up and push a fix shortly.

@souravxbera

Copy link
Copy Markdown
Contributor Author

Done. PTAL!!
Thanks.

@codebytere

codebytere commented Feb 2, 2026 •

Copy link
Copy Markdown
Member

@sbera01 tests and lint are failing - the test failure is related. Did you test this before marking ready? the failure would have been caught by running a simple example.

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Feb 3, 2026
@jkleinsc jkleinsc added the semver/minor backwards-compatible functionality label Feb 5, 2026
@codebytere

Copy link
Copy Markdown
Member

@sbera01 do you still want to pursue this PR?

@souravxbera

Copy link
Copy Markdown
Contributor Author

@codebytere Sorry for the late reply. I’ve looked into it further, but I don’t currently have the required setup/resources to properly test and validate the changes. Given that, I won’t be able to continue pursuing this PR.

I really apologize for the inconvenience, and please feel free to close it if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/requested 🗳 semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When first calling dialog.showSaveDialog, default to downloads/documents

3 participants