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

feat: Add download started and download completed callbacks #530

Merged
merged 54 commits into from
Oct 19, 2022

Conversation

atlanticaccent
Copy link
Contributor

@atlanticaccent atlanticaccent commented Mar 27, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Windows works completely - the callbacks fire and the file downloads. The download location can even be changed through the crude API I've implemented (a &mut String passed to the download started callback). One note on changing download location paths is that Universal Naming Convention file paths do not work (they start with slashes and a question mark) - these are generated when calling canonicalize so an alternative solution is necessary.

Linux seems to be working to some extent - both callbacks fire, however controlling where the file is saved seems to have no effect and causes the download to stall indefinitely. Not setting the download path causes bizarre behaviour where webkitgtk either claims that the download has succeeded (to where is unclear) or that the path (which is full of invalid characters) is occupied.

I attempted a macOS implementation however seem to have failed completely. I have a DownloadDelegate being created and set, and a couple of what I think are necessary methods implemented on the WKWebview, but nothing seems to get the actual delegate functions to fire.
The macOS implementation is effectively on par with the linux implementation, in that all the callbacks now fire correctly, but setting the download location causes the entire download to fail, and not setting it does not seem to actually write out a download/file.

@atlanticaccent atlanticaccent requested review from a team March 27, 2022 23:24
@atlanticaccent atlanticaccent requested a review from a team as a code owner March 27, 2022 23:24
src/webview/mod.rs Outdated Show resolved Hide resolved
src/webview/webkitgtk/web_context.rs Outdated Show resolved Hide resolved
src/webview/mod.rs Outdated Show resolved Hide resolved
src/webview/mod.rs Outdated Show resolved Hide resolved
@atlanticaccent atlanticaccent force-pushed the implement-download-event branch from bf039b2 to 799da8e Compare April 30, 2022 20:30
Now has handler for download start/deny and download completed callback
This avoids the indirection of the closure builder pattern whilst still
solving the lifetime issues.
@keiya01
Copy link
Member

keiya01 commented Jul 12, 2022

What is this PR status?

@atlanticaccent atlanticaccent force-pushed the implement-download-event branch from 7e82e16 to b600926 Compare September 16, 2022 23:06
macOS implementation works, but may rely on an incorrect assumption -
clicking the download link seems to return a random blob URL, so we
just grab the first saved blob URL
@atlanticaccent
Copy link
Contributor Author

@amrbashir I believe I've addressed your comments, plus cleaned some things up. Would you be able to give it another look over?

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

Other than these two nit-picks, the Linux/Windows implementation looks good, as for macOS, I will leave it for @wusyong or @lucasfernog to approve.

src/webview/mod.rs Outdated Show resolved Hide resolved
src/webview/mod.rs Outdated Show resolved Hide resolved
amrbashir
amrbashir previously approved these changes Sep 19, 2022
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

LGTM now for Windows and Linux

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to merge this PR, our macOS expert is currently on vacation

Comment on lines +406 to +407
cls.add_ivar::<*mut c_void>("function");
cls.add_ivar::<*mut c_void>("HasDownloadHandler");
Copy link
Member

Choose a reason for hiding this comment

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

Can we extract these two strings into some consts so it is easier to track/change in the future? Actually any ivar used more than one time should be in a const

Copy link
Member

Choose a reason for hiding this comment

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

There are many more ivar like this. I think we should do this in another PR.

@wusyong wusyong self-assigned this Oct 19, 2022
wusyong
wusyong previously approved these changes Oct 19, 2022
@wusyong wusyong merged commit 3691c4f into tauri-apps:dev Oct 19, 2022
@wusyong
Copy link
Member

wusyong commented Oct 19, 2022

Thanks for this amazing PR @atlanticaccent !

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.

5 participants