diff --git a/lib/backend/api/manager_api.dart b/lib/backend/api/manager_api.dart index 22662003..e4857c1f 100644 --- a/lib/backend/api/manager_api.dart +++ b/lib/backend/api/manager_api.dart @@ -5,41 +5,53 @@ import 'package:revanced_manager_flutter/constants.dart'; import 'github_api.dart'; // use path_provider to get the path of the storage directory -Dio dio = Dio(); -GithubAPI githubAPI = GithubAPI(); -Future getPath() async { - final path = await p.getApplicationSupportDirectory(); - final workDir = Directory('${path.path}/revanced').createSync(); - final workDirPath = "${path.path}/revanced"; - return workDirPath; -} +class ManagerAPI { + Dio dio = Dio(); + GithubAPI githubAPI = GithubAPI(); -Future downloadAssets(String repo) async { - try { - final workDir = await getPath(); - final dlUrl = await githubAPI.latestRelease(ghOrg, repo); - final name = - dlUrl?.split('/').lastWhere((element) => element.contains('revanced')); - print(name); - final assetFile = File('$workDir/$name'); - final response = await dio.get( - dlUrl!, - options: Options( - responseType: ResponseType.bytes, - followRedirects: true, - receiveTimeout: 0, - ), - onReceiveProgress: (count, total) { - print('$count/$total'); - }, - ); - final raf = assetFile.openSync(mode: FileMode.write); - raf.writeFromSync(response.data); - raf.closeSync(); - return assetFile; - } catch (e) { - print(e); - return null; + Future getPath() async { + final path = await p.getApplicationSupportDirectory(); + final workDir = Directory('${path.path}/revanced').createSync(); + final workDirPath = "${path.path}/revanced"; + return workDirPath; + } + + Future downloadAssets(String repo) async { + try { + final workDir = await getPath(); + final dlUrl = await githubAPI.latestRelease(ghOrg, repo); + final name = dlUrl + ?.split('/') + .lastWhere((element) => element.contains('revanced')); + print(name); + final assetFile = File('$workDir/$name'); + final response = await dio.get( + dlUrl!, + options: Options( + responseType: ResponseType.bytes, + followRedirects: true, + receiveTimeout: 0, + ), + onReceiveProgress: (count, total) { + print('$count/$total'); + }, + ); + final raf = assetFile.openSync(mode: FileMode.write); + raf.writeFromSync(response.data); + raf.closeSync(); + return assetFile; + } catch (e) { + print(e); + return null; + } + } + + Future downloadPatches() async { + await downloadAssets(patchesRepo); + } + + Future downloadIntegrations() async { + await downloadAssets(integrationsRepo); } }