Skip to content

Commit

Permalink
Updated dependencies & migrated breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanSikarwar committed Apr 2, 2023
1 parent 0b95257 commit e6743b0
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 97 deletions.
5 changes: 5 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
coreLibraryDesugaringEnabled true
}

kotlinOptions {
Expand All @@ -48,6 +49,7 @@ android {
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand Down Expand Up @@ -81,4 +83,7 @@ dependencies {
implementation("org.microg:cronet-common:$cronetVersion")
implementation("org.microg:cronet-native:$cronetVersion")

// Core libraries
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ late SharedPreferences prefs;
Future main() async {
await ThemeManager.initialise();
await setupLocator();
WidgetsFlutterBinding.ensureInitialized();
// WidgetsFlutterBinding.ensureInitialized();
await locator<ManagerAPI>().initialize();
final String apiUrl = locator<ManagerAPI>().getApiUrl();
await locator<RevancedAPI>().initialize(apiUrl);
Expand Down
34 changes: 19 additions & 15 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';

import 'package:collection/collection.dart';
import 'package:dio/dio.dart';
import 'package:dio_http_cache_lts/dio_http_cache_lts.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -12,9 +12,9 @@ import 'package:revanced_manager/models/patch.dart';
@lazySingleton
class GithubAPI {
late Dio _dio = Dio();
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
final Options _cacheOptions = buildCacheOptions(
const Duration(hours: 6),
final _cacheOptions = CacheOptions(
store: MemCacheStore(),
policy: CachePolicy.forceCache,
maxStale: const Duration(days: 1),
);
final Map<String, String> repoAppPath = {
Expand All @@ -36,7 +36,8 @@ class GithubAPI {
),
);

_dio.interceptors.add(_dioCacheManager.interceptor);
_dio.interceptors
.add(DioCacheInterceptor(options: _cacheOptions));
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand All @@ -46,20 +47,19 @@ class GithubAPI {

Future<void> clearAllCache() async {
try {
await _dioCacheManager.clearAll();
_cacheOptions.store!.clean();
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
}
}

Future<Map<String, dynamic>?> getLatestRelease(String repoName) async {
Future<Map<String, dynamic>?> getLatestRelease(
String repoName,
) async {
try {
final response = await _dio.get(
'/repos/$repoName/releases',
options: _cacheOptions,
);
final response = await _dio.get('/repos/$repoName/releases');
return response.data[0];
} on Exception catch (e) {
if (kDebugMode) {
Expand All @@ -83,7 +83,6 @@ class GithubAPI {
'path': path,
'since': since.toIso8601String(),
},
options: _cacheOptions,
);
final List<dynamic> commits = response.data;
return commits
Expand All @@ -102,9 +101,13 @@ class GithubAPI {
return [];
}

Future<File?> getLatestReleaseFile(String extension, String repoName) async {
Future<File?> getLatestReleaseFile(
String extension,
String repoName,
) async {
try {
final Map<String, dynamic>? release = await getLatestRelease(repoName);
final Map<String, dynamic>? release =
await getLatestRelease(repoName);
if (release != null) {
final Map<String, dynamic>? asset =
(release['assets'] as List<dynamic>).firstWhereOrNull(
Expand Down Expand Up @@ -143,7 +146,8 @@ class GithubAPI {

Future<String> getLastestReleaseVersion(String repoName) async {
try {
final Map<String, dynamic>? release = await getLatestRelease(repoName);
final Map<String, dynamic>? release =
await getLatestRelease(repoName);
if (release != null) {
return release['tag_name'];
} else {
Expand Down
68 changes: 49 additions & 19 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ManagerAPI {
Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
storedPatchesFile =
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
(await getApplicationDocumentsDirectory()).path +
storedPatchesFile;
}

String getApiUrl() {
Expand Down Expand Up @@ -72,7 +73,8 @@ class ManagerAPI {
}

String getIntegrationsRepo() {
return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo;
return _prefs.getString('integrationsRepo') ??
defaultIntegrationsRepo;
}

Future<void> setIntegrationsRepo(String value) async {
Expand Down Expand Up @@ -132,10 +134,14 @@ class ManagerAPI {

List<PatchedApplication> getPatchedApps() {
final List<String> apps = _prefs.getStringList('patchedApps') ?? [];
return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList();
return apps
.map((a) => PatchedApplication.fromJson(jsonDecode(a)))
.toList();
}

Future<void> setPatchedApps(List<PatchedApplication> patchedApps) async {
Future<void> setPatchedApps(
List<PatchedApplication> patchedApps,
) async {
if (patchedApps.length > 1) {
patchedApps.sort((a, b) => a.name.compareTo(b.name));
}
Expand Down Expand Up @@ -237,15 +243,24 @@ class ManagerAPI {
}

Future<File?> downloadManager() async {
return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
return await _revancedAPI.getLatestReleaseFile(
'.apk',
defaultManagerRepo,
);
}

Future<String?> getLatestPatcherReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo);
return await _revancedAPI.getLatestReleaseTime(
'.gz',
defaultPatcherRepo,
);
}

Future<String?> getLatestManagerReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
return await _revancedAPI.getLatestReleaseTime(
'.apk',
defaultManagerRepo,
);
}

Future<String?> getLatestManagerVersion() async {
Expand Down Expand Up @@ -286,10 +301,12 @@ class ManagerAPI {
final List<PatchedApplication> unsavedApps = [];
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
final List<String> installedApps = await _rootAPI.getInstalledApps();
final List<String> installedApps =
await _rootAPI.getInstalledApps();
for (final String packageName in installedApps) {
if (!patchedApps.any((app) => app.packageName == packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
final ApplicationWithIcon? application =
await DeviceApps.getApp(
packageName,
true,
) as ApplicationWithIcon?;
Expand All @@ -315,8 +332,10 @@ class ManagerAPI {
for (final Application app in userApps) {
if (app.packageName.startsWith('app.revanced') &&
!app.packageName.startsWith('app.revanced.manager.') &&
!patchedApps.any((uapp) => uapp.packageName == app.packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
!patchedApps
.any((uapp) => uapp.packageName == app.packageName)) {
final ApplicationWithIcon? application =
await DeviceApps.getApp(
app.packageName,
true,
) as ApplicationWithIcon?;
Expand Down Expand Up @@ -359,8 +378,9 @@ class ManagerAPI {
final int currentInstalledVersionInt = int.parse(
currentInstalledVersion.replaceAll(RegExp('[^0-9]'), ''),
);
final int currentSavedVersionInt =
int.parse(currentSavedVersion.replaceAll(RegExp('[^0-9]'), ''));
final int currentSavedVersionInt = int.parse(
currentSavedVersion.replaceAll(RegExp('[^0-9]'), ''),
);
if (currentInstalledVersionInt > currentSavedVersionInt) {
app.hasUpdates = true;
}
Expand All @@ -372,9 +392,11 @@ class ManagerAPI {

Future<bool> isAppUninstalled(PatchedApplication app) async {
bool existsRoot = false;
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
final bool existsNonRoot =
await DeviceApps.isAppInstalled(app.packageName);
if (app.isRooted) {
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
final bool hasRootPermissions =
await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
}
Expand All @@ -383,7 +405,10 @@ class ManagerAPI {
return !existsNonRoot;
}

Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async {
Future<bool> hasAppUpdates(
String packageName,
DateTime patchDate,
) async {
final List<String> commits = await _githubAPI.getCommits(
packageName,
getPatchesRepo(),
Expand Down Expand Up @@ -421,9 +446,13 @@ class ManagerAPI {
return app != null && app.isSplit;
}

Future<void> setSelectedPatches(String app, List<String> patches) async {
Future<void> setSelectedPatches(
String app,
List<String> patches,
) async {
final File selectedPatchesFile = File(storedPatchesFile);
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
final Map<String, dynamic> patchesMap =
await readSelectedPatchesFile();
if (patches.isEmpty) {
patchesMap.remove(app);
} else {
Expand All @@ -433,7 +462,8 @@ class ManagerAPI {
}

Future<List<String>> getSelectedPatches(String app) async {
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
final Map<String, dynamic> patchesMap =
await readSelectedPatchesFile();
return List.from(patchesMap.putIfAbsent(app, () => List.empty()));
}

Expand Down
26 changes: 15 additions & 11 deletions lib/services/revanced_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import 'dart:io';

import 'package:collection/collection.dart';
import 'package:dio/dio.dart';
import 'package:dio_http_cache_lts/dio_http_cache_lts.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:injectable/injectable.dart';
import 'package:native_dio_client/native_dio_client.dart';
import 'package:native_dio_adapter/native_dio_adapter.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/utils/check_for_gms.dart';
import 'package:timeago/timeago.dart';

@lazySingleton
class RevancedAPI {
late Dio _dio = Dio();
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
final Options _cacheOptions = buildCacheOptions(
const Duration(hours: 6),
final _cacheOptions = CacheOptions(
store: MemCacheStore(),
policy: CachePolicy.forceCache,
maxStale: const Duration(days: 1),
);

Expand All @@ -40,7 +40,8 @@ class RevancedAPI {
)..httpClientAdapter = NativeAdapter();
log('ReVanced API: Using CronetEngine + $isGMSInstalled');
}
_dio.interceptors.add(_dioCacheManager.interceptor);
_dio.interceptors
.add(DioCacheInterceptor(options: _cacheOptions));
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand All @@ -50,7 +51,7 @@ class RevancedAPI {

Future<void> clearAllCache() async {
try {
await _dioCacheManager.clearAll();
_cacheOptions.store!.clean();
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand All @@ -61,7 +62,7 @@ class RevancedAPI {
Future<Map<String, List<dynamic>>> getContributors() async {
final Map<String, List<dynamic>> contributors = {};
try {
final response = await _dio.get('/contributors', options: _cacheOptions);
final response = await _dio.get('/contributors');
final List<dynamic> repositories = response.data['repositories'];
for (final Map<String, dynamic> repo in repositories) {
final String name = repo['name'];
Expand All @@ -78,7 +79,7 @@ class RevancedAPI {

Future<List<Patch>> getPatches() async {
try {
final response = await _dio.get('/patches', options: _cacheOptions);
final response = await _dio.get('/patches');
final List<dynamic> patches = response.data;
return patches.map((patch) => Patch.fromJson(patch)).toList();
} on Exception catch (e) {
Expand All @@ -94,7 +95,7 @@ class RevancedAPI {
String repoName,
) async {
try {
final response = await _dio.get('/tools', options: _cacheOptions);
final response = await _dio.get('/tools');
final List<dynamic> tools = response.data['tools'];
return tools.firstWhereOrNull(
(t) =>
Expand Down Expand Up @@ -130,7 +131,10 @@ class RevancedAPI {
return null;
}

Future<File?> getLatestReleaseFile(String extension, String repoName) async {
Future<File?> getLatestReleaseFile(
String extension,
String repoName,
) async {
try {
final Map<String, dynamic>? release = await _getLatestRelease(
extension,
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/views/contributors/contributors_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class ContributorsViewModel extends BaseViewModel {
Future<void> getContributors() async {
final Map<String, List<dynamic>> contributors =
await _managerAPI.getContributors();
patcherContributors = contributors[_managerAPI.defaultPatcherRepo] ?? [];
patchesContributors = contributors[_managerAPI.getPatchesRepo()] ?? [];
patcherContributors =
contributors[_managerAPI.defaultPatcherRepo] ?? [];
patchesContributors =
contributors[_managerAPI.getPatchesRepo()] ?? [];
integrationsContributors =
contributors[_managerAPI.getIntegrationsRepo()] ?? [];
cliContributors = contributors[_managerAPI.defaultCliRepo] ?? [];
managerContributors = contributors[_managerAPI.defaultManagerRepo] ?? [];
managerContributors =
contributors[_managerAPI.defaultManagerRepo] ?? [];
notifyListeners();
}
}
Loading

0 comments on commit e6743b0

Please sign in to comment.