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 {
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");
}

View File

@ -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;
}
}

View File

@ -10,3 +10,7 @@ const pink40 = Color(0xFF7D5260);
final interTextStyle = GoogleFonts.inter();
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: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/installed_apps_card.dart';
import 'package:revanced_manager_flutter/ui/widgets/latest_commit_card.dart';
@ -24,9 +23,7 @@ class HomeScreen extends StatelessWidget {
Align(
alignment: Alignment.topRight,
child: IconButton(
onPressed: () {
getPath();
},
onPressed: () {},
icon: const Icon(
Icons.more_vert,
),

View File

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

View File

@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.6"
fake_async:
dependency: transitive
description:
@ -235,41 +242,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:

View File

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

View File

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

View File

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