mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Auto retry failed download (3 times) (#634)
This commit is contained in:
		| @@ -21,7 +21,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart'; | |||||||
| // ignore: implementation_imports | // ignore: implementation_imports | ||||||
| import 'package:easy_localization/src/localization.dart'; | import 'package:easy_localization/src/localization.dart'; | ||||||
|  |  | ||||||
| const String currentVersion = '0.13.20'; | const String currentVersion = '0.13.21'; | ||||||
| const String currentReleaseTag = | const String currentReleaseTag = | ||||||
|     'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES |     'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES | ||||||
|  |  | ||||||
|   | |||||||
| @@ -144,6 +144,24 @@ class AppsProvider with ChangeNotifier { | |||||||
|     }(); |     }(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   Future<File> downloadFileWithRetry( | ||||||
|  |       String url, String fileNameNoExt, Function? onProgress, | ||||||
|  |       {bool useExisting = true, | ||||||
|  |       Map<String, String>? headers, | ||||||
|  |       int retries = 3}) async { | ||||||
|  |     try { | ||||||
|  |       return await downloadFile(url, fileNameNoExt, onProgress, | ||||||
|  |           useExisting: useExisting, headers: headers); | ||||||
|  |     } catch (e) { | ||||||
|  |       if (retries > 0 && e is ClientException) { | ||||||
|  |         return await downloadFileWithRetry(url, fileNameNoExt, onProgress, | ||||||
|  |             useExisting: useExisting, headers: headers, retries: (retries - 1)); | ||||||
|  |       } else { | ||||||
|  |         rethrow; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   Future<File> downloadFile( |   Future<File> downloadFile( | ||||||
|       String url, String fileNameNoExt, Function? onProgress, |       String url, String fileNameNoExt, Function? onProgress, | ||||||
|       {bool useExisting = true, Map<String, String>? headers}) async { |       {bool useExisting = true, Map<String, String>? headers}) async { | ||||||
| @@ -236,8 +254,9 @@ class AppsProvider with ChangeNotifier { | |||||||
|       notificationsProvider?.cancel(notif.id); |       notificationsProvider?.cancel(notif.id); | ||||||
|       int? prevProg; |       int? prevProg; | ||||||
|       var fileNameNoExt = '${app.id}-${downloadUrl.hashCode}'; |       var fileNameNoExt = '${app.id}-${downloadUrl.hashCode}'; | ||||||
|       var downloadedFile = await downloadFile(downloadUrl, fileNameNoExt, |       var downloadedFile = await downloadFileWithRetry( | ||||||
|           headers: source.requestHeaders, (double? progress) { |           downloadUrl, fileNameNoExt, headers: source.requestHeaders, | ||||||
|  |           (double? progress) { | ||||||
|         int? prog = progress?.ceil(); |         int? prog = progress?.ceil(); | ||||||
|         if (apps[app.id] != null) { |         if (apps[app.id] != null) { | ||||||
|           apps[app.id]!.downloadProgress = progress; |           apps[app.id]!.downloadProgress = progress; | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |||||||
| # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | ||||||
| # In Windows, build-name is used as the major, minor, and patch parts | # In Windows, build-name is used as the major, minor, and patch parts | ||||||
| # of the product and file versions while build-number is used as the build suffix. | # of the product and file versions while build-number is used as the build suffix. | ||||||
| version: 0.13.20+184 # When changing this, update the tag in main() accordingly | version: 0.13.21+185 # When changing this, update the tag in main() accordingly | ||||||
|  |  | ||||||
| environment: | environment: | ||||||
|   sdk: '>=2.18.2 <3.0.0' |   sdk: '>=2.18.2 <3.0.0' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user