feat: download latest patches and integrations.

This commit is contained in:
Aunali321 2022-08-02 13:25:01 +05:30
parent d9256149e7
commit 729ad82f77
9 changed files with 59 additions and 55 deletions

View file

@ -3,7 +3,7 @@ import 'package:github/github.dart';
class GithubAPI { class GithubAPI {
var github = GitHub(); var github = GitHub();
Future latestRelease(String org, repoName) async { Future<String?> latestRelease(String org, repoName) async {
var latestRelease = await github.repositories var latestRelease = await github.repositories
.getLatestRelease(RepositorySlug(org, repoName)); .getLatestRelease(RepositorySlug(org, repoName));
var dlurl = latestRelease.assets var dlurl = latestRelease.assets
@ -12,7 +12,7 @@ class GithubAPI {
element.browserDownloadUrl!.contains(".apk")) element.browserDownloadUrl!.contains(".apk"))
.browserDownloadUrl; .browserDownloadUrl;
print(dlurl); print(dlurl);
return latestRelease; return dlurl;
} }
Future latestCommitTime(String org, repoName) async { Future latestCommitTime(String org, repoName) async {
@ -53,7 +53,7 @@ class GithubAPI {
void main(List<String> args) { void main(List<String> args) {
GithubAPI githubAPI = GithubAPI(); GithubAPI githubAPI = GithubAPI();
// githubAPI.latestRelease('revanced', 'revanced-patches'); githubAPI.latestRelease('revanced', 'revanced-patches');
// githubAPI.latestCommitTime("revanced", "revanced-patches"); // githubAPI.latestCommitTime("revanced", "revanced-patches");
// githubAPI.contributors("revanced", "revanced-manager"); // githubAPI.contributors("revanced", "revanced-manager");
} }

View file

@ -1,10 +1,45 @@
import 'dart:io'; 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: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 // use path_provider to get the path of the storage directory
Dio dio = Dio();
GithubAPI githubAPI = GithubAPI();
void getPath() async { Future<String?> getPath() async {
final path = await p.getExternalStorageDirectory(); final path = await p.getApplicationSupportDirectory();
print(path); 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;
}
} }

View file

@ -10,3 +10,7 @@ const pink40 = Color(0xFF7D5260);
final interTextStyle = GoogleFonts.inter(); final interTextStyle = GoogleFonts.inter();
final robotoTextStyle = GoogleFonts.roboto(); final robotoTextStyle = GoogleFonts.roboto();
const ghOrg = "revanced";
const patchesRepo = "revanced-patches";
const integrationsRepo = "revanced-integrations";

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager_flutter/backend/api/manager_api.dart';
import 'package:revanced_manager_flutter/ui/widgets/available_updates_card.dart'; import 'package:revanced_manager_flutter/ui/widgets/available_updates_card.dart';
import 'package:revanced_manager_flutter/ui/widgets/installed_apps_card.dart'; import 'package:revanced_manager_flutter/ui/widgets/installed_apps_card.dart';
import 'package:revanced_manager_flutter/ui/widgets/latest_commit_card.dart'; import 'package:revanced_manager_flutter/ui/widgets/latest_commit_card.dart';
@ -24,9 +23,7 @@ class HomeScreen extends StatelessWidget {
Align( Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {},
getPath();
},
icon: const Icon( icon: const Icon(
Icons.more_vert, Icons.more_vert,
), ),

View file

@ -17,10 +17,10 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
String lastManagerCommit = "Loading..."; String lastManagerCommit = "Loading...";
void latestCommit() async { void latestCommit() async {
lastPatcherCommit = // lastPatcherCommit =
await githubAPI.latestCommitTime("revanced", "revanced-patcher"); // await githubAPI.latestCommitTime("revanced", "revanced-patcher");
lastManagerCommit = // lastManagerCommit =
await githubAPI.latestCommitTime("revanced", "revanced-manager"); // await githubAPI.latestCommitTime("revanced", "revanced-manager");
} }
@override @override

View file

@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.6"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -235,41 +242,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "10.0.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
url: "https://pub.dartlang.org"
source: hosted
version: "10.0.0"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.4"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:

View file

@ -38,8 +38,8 @@ dependencies:
google_fonts: ^3.0.1 google_fonts: ^3.0.1
http: ^0.13.4 http: ^0.13.4
github: ^9.4.0 github: ^9.4.0
permission_handler: ^10.0.0
path_provider: ^2.0.11 path_provider: ^2.0.11
dio: ^4.0.6
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -6,9 +6,6 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <permission_handler_windows/permission_handler_windows_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
} }

View file

@ -3,7 +3,6 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
permission_handler_windows
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST