-
Notifications
You must be signed in to change notification settings - Fork 52
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
Avalonia: How do properly handle file downloads? #379
Comments
It seems that adding an event handler to any of the Download events (DownloadCancelled, DownloadCompleted, DownloadProgressChanged) throws a NullReferenceException in InternalDownloadHandler.OnDownloadUpdated, the problem appears to be with the CefDownloadItem! The CefDownloadItem is being Disposed() before OnDownloadUpdated can use it. To my pleasant surprise downloads work perfectly fine as fire and forget operations (not using DownloadCancelled, DownloadCompleted, DownloadProgressChanged); however, for my use case I really need to be able to track the download so I did a little debugging. I believe that a simple change to WebView.InternalDownloadHandler like below will solve the problem:
Thanks and God Bless, |
Can you submit a PR? |
I have never submitted a PR before; however, I doubt it is that difficult! I am generally kind of hesitant to work on other peoples code; however, it would probably be a good exercise for me. I will work on that today! Thanks! |
It occurred to me that the way the API is designed tracking multiple downloads is potentially a little wonky since the downloadItem.Id is not sent as a parameter to the public download events. I do not want to break the public API so I will leave that decision for the project owners! For now, I suppose a suitable work around would probably be to delay tracking (on the UI side anyway) the download until the resourcePath != "", especially in more advanced scenarios. Anyway, my further testing is delaying my PR! |
You can add events similiar to the existing ones, but with extra id param, so that we don't have breaking changes. I would probably create a class/record to put that data so that in the future this problem doesn't happen |
Greetings, as the question states how do you properly handle file downloads?
Thanks and God Bless,
- Dean
The text was updated successfully, but these errors were encountered: