IWithDownloads.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2022 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System;
  15. namespace Vuplex.WebView {
  16. /// <summary>
  17. /// An interface implemented by a webview if it supports file downloads.
  18. /// </summary>
  19. /// <remarks>
  20. /// When downloads are enabled enabled, files are downloaded to Application.temporaryCachePath, but you can move them to a different
  21. /// location after they finish downloading.
  22. /// </remarks>
  23. /// <example>
  24. /// <code>
  25. /// await webViewPrefab.WaitUntilInitialized();
  26. /// var webViewWithDownloads = webViewPrefab.WebView as IWithDownloads;
  27. /// if (webViewWithDownloads != null) {
  28. /// webViewWithDownloads.SetDownloadsEnabled(true);
  29. /// webViewWithDownloads.DownloadProgressChanged += (sender, eventArgs) => {
  30. /// Debug.Log(
  31. /// $@"DownloadProgressChanged:
  32. /// Type: {eventArgs.Type},
  33. /// Url: {eventArgs.Url},
  34. /// Progress: {eventArgs.Progress},
  35. /// Id: {eventArgs.Id},
  36. /// FilePath: {eventArgs.FilePath},
  37. /// ContentType: {eventArgs.ContentType}"
  38. /// );
  39. /// if (eventArgs.Type == ProgressChangeType.Finished) {
  40. /// Debug.Log("Download finished");
  41. /// File.Move(eventArgs.FilePath, someOtherLocation);
  42. /// }
  43. /// };
  44. /// }
  45. /// </code>
  46. /// </example>
  47. public interface IWithDownloads {
  48. /// <summary>
  49. /// Sets whether file downloads are enabled. The default is disabled.
  50. /// </summary>
  51. void SetDownloadsEnabled(bool enabled);
  52. /// <summary>
  53. /// Indicates that the progress of a file download changed.
  54. /// </summary>
  55. event EventHandler<DownloadChangedEventArgs> DownloadProgressChanged;
  56. }
  57. }