Skip to content

Add more download supports in Electron - #2840

Merged
zcbenz merged 12 commits into
masterfrom
download-item
Sep 24, 2015
Merged

zcbenz merged 12 commits into
masterfrom
download-item

Conversation

@hokein

@hokein hokein commented Sep 20, 2015

Copy link
Copy Markdown
Contributor

Fixes #2491.

This patch indroduces:

  • A session.setOpenDownloadDialog downloadItem.setSavePath API for allowing user enable/disable the prompted save dialog.
  • Make item returned in will-download event as an EventEmitter and add more APIs to control the download item.

ToDo

  • Add spec

\cc @kjlaw89

@kjlaw89

kjlaw89 commented Sep 20, 2015

Copy link
Copy Markdown

@hokein That looks perfect! One small question - is there a way to detect whether the Content Disposition was inline or attachment? That would let me know if the file that was being downloaded (mostly PDF's in our case) was meant to be viewed in the application or saved for later viewing. I'm not sure if the getMimeType() returns that information or not. Otherwise I think you've got everything I'm after!

Thanks for looking at this!

* Rename `completed` to `done`, making it align with Chromium's style.
* Add 'state' in `done` event's result. It can check the download item final
status: cancelled, completed, interrupted.
@zcbenz

zcbenz commented Sep 21, 2015

Copy link
Copy Markdown
Contributor

How about fully relying on will-download event to determine the download path? Like this:

session.on 'will-download', (event, item) ->
  savePath = require('dialog').openSaveDialog()
  if savePath
    item.setSavePath(savePath)
  else
    item.cancel()

And if user doesn't set a path for download item, we then use the original routine to determine the save path. In this way we no longer need to a bunch of other APIs to control how to show the dialog.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since one content::DownloadItem maps to one api::DownloadItem, I think we no longer need to do the comparison?

@zcbenz

zcbenz commented Sep 21, 2015

Copy link
Copy Markdown
Contributor

We need to store the JavaScript item somewhere before it is destroyed, otherwise it might be garbage collected since it is not referenced anywhere. We can probably save the items in a static member of api::DownloadItem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to inherit mate::TrackableObject, we don't need to enumerate all items and there is no need to destroy the item on exit.

@kjlaw89

kjlaw89 commented Sep 21, 2015

Copy link
Copy Markdown

I think calling the Open Save Dialog only when needed would be just fine!

@kjlaw89

kjlaw89 commented Sep 23, 2015

Copy link
Copy Markdown

@hokein Any more progress on this? Thanks for looking at it!

Previously, the suggested file name(Always 'empty') returned by
'download_item->GetSuggestedFilename' is not the same with the default one saved
in local disk.

The patch reimplement this API allowing it to return the default file name, which
is more expected from user.
@hokein

hokein commented Sep 24, 2015

Copy link
Copy Markdown
Contributor Author

@zcbenz . This PR has been updated with your suggestions. It's ready for review again now.

@kjlaw89 Indeed, I'm working on this, thanks for your patience.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually hide the constructor under protected: if there is a Create method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@zcbenz

zcbenz commented Sep 24, 2015

Copy link
Copy Markdown
Contributor

Awesome, thanks!

zcbenz added a commit that referenced this pull request Sep 24, 2015
Add more download supports in Electron
@zcbenz
zcbenz merged commit ecefd35 into master Sep 24, 2015
@zcbenz
zcbenz deleted the download-item branch September 24, 2015 13:04
@zhm

zhm commented Sep 25, 2015

Copy link
Copy Markdown

The "interrupted" constant has a typo :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants