mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-21 18:23:57 +00:00
refactor: migrate to stacked architecture.
* feat: mostly done stacked architecture. * refactor: migration to stacked architecture.
This commit is contained in:
43
lib/services/github_api.dart
Normal file
43
lib/services/github_api.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
58
lib/services/manager_api.dart
Normal file
58
lib/services/manager_api.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
12
lib/services/third_party_services_modules.dart
Normal file
12
lib/services/third_party_services_modules.dart
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user