refactor: migrate to stacked architecture.

* feat: mostly done stacked architecture.

* refactor: migration to stacked architecture.
This commit is contained in:
Aunali321
2022-08-06 17:43:28 +05:30
committed by GitHub
parent 0b58ce3dca
commit 769ff72f98
20 changed files with 825 additions and 267 deletions

View File

@@ -0,0 +1,43 @@
import 'package:github/github.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class GithubAPI {
var github = GitHub();
Future<String?> latestRelease(String org, repoName) async {
var latestRelease = await github.repositories
.getLatestRelease(RepositorySlug(org, repoName));
var dlurl = latestRelease.assets?.first.browserDownloadUrl;
return dlurl;
}
Future latestCommitTime(String org, repoName) async {
var repo =
await github.repositories.getRepository(RepositorySlug(org, repoName));
var commitTime = repo.pushedAt?.difference(
DateTime.now().toLocal(),
);
final hours = commitTime!.inHours.abs();
if (hours > 24) {
var days = (commitTime.inDays).abs().toString();
return "$days days";
} else if (hours > 1 && hours < 24) {
var hours = (commitTime.inHours).abs().toString();
return "$hours hours";
} else {
var minutes = (commitTime.inMinutes).abs().toString();
return "$minutes mins";
}
}
Future contributors(String org, repoName) async {
var contributors =
github.repositories.listContributors(RepositorySlug(org, repoName));
contributors.forEach((contributor) {});
return contributors;
}
}

View File

@@ -0,0 +1,58 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:injectable/injectable.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
@lazySingleton
class ManagerAPI {
Dio dio = Dio();
GithubAPI githubAPI = GithubAPI();
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;
}
}
Future<void> downloadPatches() async {
await downloadAssets(patchesRepo);
}
Future<void> downloadIntegrations() async {
await downloadAssets(integrationsRepo);
}
}

View File

@@ -0,0 +1,12 @@
import 'package:injectable/injectable.dart';
import 'package:stacked_services/stacked_services.dart';
@module
abstract class ThirdPartyServicesModule {
@lazySingleton
NavigationService get navigationService;
@lazySingleton
DialogService get dialogService;
@lazySingleton
SnackbarService get snackbarService;
}