download method

Future<void> download(
  1. ReleaseArtifact release
)

Initiates the downloading of the provided release.

Implementation

Future<void> download(ReleaseArtifact release) async {
  final releaseDownload = ReleaseDownload(release.url);
  activeDownload.value?.cancel();
  activeDownload.value = releaseDownload;

  try {
    await activeDownload.value?.start();
    activeDownload.value = releaseDownload;
  } on DioException catch (e) {
    switch (e.type) {
      case DioExceptionType.cancel:
        activeDownload.value?.cancel();
        activeDownload.value = null;
        break;

      case DioExceptionType.connectionTimeout:
      case DioExceptionType.sendTimeout:
      case DioExceptionType.receiveTimeout:
      case DioExceptionType.badCertificate:
      case DioExceptionType.badResponse:
      case DioExceptionType.connectionError:
      case DioExceptionType.unknown:
        activeDownload.value?.cancel();
        activeDownload.value = null;
        try {
          await launchUrlString(release.url);
        } catch (e) {
          MessagePopup.error(e);
          rethrow;
        }
    }
  } catch (e) {
    activeDownload.value?.cancel();
    activeDownload.value = null;
    MessagePopup.error(e);
    rethrow;
  }
}