mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-23 19:21:03 +00:00
feat: download latest patches and integrations.
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:github/github.dart';
|
||||
class GithubAPI {
|
||||
var github = GitHub();
|
||||
|
||||
Future latestRelease(String org, repoName) async {
|
||||
Future<String?> latestRelease(String org, repoName) async {
|
||||
var latestRelease = await github.repositories
|
||||
.getLatestRelease(RepositorySlug(org, repoName));
|
||||
var dlurl = latestRelease.assets
|
||||
@@ -12,7 +12,7 @@ class GithubAPI {
|
||||
element.browserDownloadUrl!.contains(".apk"))
|
||||
.browserDownloadUrl;
|
||||
print(dlurl);
|
||||
return latestRelease;
|
||||
return dlurl;
|
||||
}
|
||||
|
||||
Future latestCommitTime(String org, repoName) async {
|
||||
@@ -53,7 +53,7 @@ class GithubAPI {
|
||||
|
||||
void main(List<String> args) {
|
||||
GithubAPI githubAPI = GithubAPI();
|
||||
// githubAPI.latestRelease('revanced', 'revanced-patches');
|
||||
githubAPI.latestRelease('revanced', 'revanced-patches');
|
||||
// githubAPI.latestCommitTime("revanced", "revanced-patches");
|
||||
// githubAPI.contributors("revanced", "revanced-manager");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,45 @@
|
||||
import 'dart:io';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:path_provider/path_provider.dart' as p;
|
||||
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();
|
||||
|
||||
void getPath() async {
|
||||
final path = await p.getExternalStorageDirectory();
|
||||
print(path);
|
||||
Future<String?> getPath() async {
|
||||
final path = await p.getApplicationSupportDirectory();
|
||||
final workDir = Directory('${path.path}/revanced').createSync();
|
||||
final workDirPath = "${path.path}/revanced";
|
||||
return workDirPath;
|
||||
}
|
||||
|
||||
Future<File?> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user