IWithDownloads.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2024 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. /// <remarks>
  24. /// On iOS, downloads are only supported on iOS 14.5 or newer because older versions of iOS lack download support.
  25. /// On versions of iOS older than 14.5, enabling downloads has no effect.
  26. /// </remarks>
  27. /// <example>
  28. /// <code>
  29. /// await webViewPrefab.WaitUntilInitialized();
  30. /// var webViewWithDownloads = webViewPrefab.WebView as IWithDownloads;
  31. /// if (webViewWithDownloads == null) {
  32. /// Debug.Log("This 3D WebView plugin doesn't yet support IWithDownloads: " + webViewPrefab.WebView.PluginType);
  33. /// return;
  34. /// }
  35. /// webViewWithDownloads.SetDownloadsEnabled(true);
  36. /// webViewWithDownloads.DownloadProgressChanged += (sender, eventArgs) => {
  37. /// Debug.Log(
  38. /// $@"DownloadProgressChanged:
  39. /// Type: {eventArgs.Type},
  40. /// Url: {eventArgs.Url},
  41. /// Progress: {eventArgs.Progress},
  42. /// Id: {eventArgs.Id},
  43. /// FilePath: {eventArgs.FilePath},
  44. /// ContentType: {eventArgs.ContentType}"
  45. /// );
  46. /// if (eventArgs.Type == ProgressChangeType.Finished) {
  47. /// Debug.Log("Download finished");
  48. /// // Now that the file has finished downloading, do something with it.
  49. /// // For example, you can move it to a different location.
  50. /// File.Move(eventArgs.FilePath, someOtherLocation);
  51. /// }
  52. /// };
  53. /// </code>
  54. /// </example>
  55. public interface IWithDownloads {
  56. /// <summary>
  57. /// Sets whether file downloads are enabled. The default is disabled.
  58. /// </summary>
  59. void SetDownloadsEnabled(bool enabled);
  60. /// <summary>
  61. /// Indicates that the progress of a file download changed.
  62. /// </summary>
  63. event EventHandler<DownloadChangedEventArgs> DownloadProgressChanged;
  64. }
  65. }