From e6743b0d6b2552fdbf1c99d23e158e682362dd5d Mon Sep 17 00:00:00 2001 From: Aman Sikarwar Date: Sun, 2 Apr 2023 20:22:11 +0530 Subject: [PATCH] Updated dependencies & migrated breaking changes --- android/app/build.gradle | 5 ++ android/build.gradle | 2 +- lib/main.dart | 2 +- lib/services/github_api.dart | 34 ++++++---- lib/services/manager_api.dart | 68 +++++++++++++------ lib/services/revanced_api.dart | 26 ++++--- .../contributors/contributors_viewmodel.dart | 9 ++- lib/ui/views/home/home_viewmodel.dart | 28 ++++++-- lib/ui/views/settings/settings_viewmodel.dart | 15 ++-- lib/utils/check_for_gms.dart | 7 +- pubspec.yaml | 66 +++++++++--------- 11 files changed, 165 insertions(+), 97 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index cfb50931e3..14324d2781 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -32,6 +32,7 @@ android { compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 + coreLibraryDesugaringEnabled true } kotlinOptions { @@ -48,6 +49,7 @@ android { targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -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' + } diff --git a/android/build.gradle b/android/build.gradle index 2d13b78c77..247194c0ca 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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" } } diff --git a/lib/main.dart b/lib/main.dart index d34f9d662b..04fc5b4197 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,7 +18,7 @@ late SharedPreferences prefs; Future main() async { await ThemeManager.initialise(); await setupLocator(); - WidgetsFlutterBinding.ensureInitialized(); + // WidgetsFlutterBinding.ensureInitialized(); await locator().initialize(); final String apiUrl = locator().getApiUrl(); await locator().initialize(apiUrl); diff --git a/lib/services/github_api.dart b/lib/services/github_api.dart index 0af9fbb143..3781fb3fa0 100644 --- a/lib/services/github_api.dart +++ b/lib/services/github_api.dart @@ -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'; @@ -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 repoAppPath = { @@ -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); @@ -46,7 +47,7 @@ class GithubAPI { Future clearAllCache() async { try { - await _dioCacheManager.clearAll(); + _cacheOptions.store!.clean(); } on Exception catch (e) { if (kDebugMode) { print(e); @@ -54,12 +55,11 @@ class GithubAPI { } } - Future?> getLatestRelease(String repoName) async { + Future?> 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) { @@ -83,7 +83,6 @@ class GithubAPI { 'path': path, 'since': since.toIso8601String(), }, - options: _cacheOptions, ); final List commits = response.data; return commits @@ -102,9 +101,13 @@ class GithubAPI { return []; } - Future getLatestReleaseFile(String extension, String repoName) async { + Future getLatestReleaseFile( + String extension, + String repoName, + ) async { try { - final Map? release = await getLatestRelease(repoName); + final Map? release = + await getLatestRelease(repoName); if (release != null) { final Map? asset = (release['assets'] as List).firstWhereOrNull( @@ -143,7 +146,8 @@ class GithubAPI { Future getLastestReleaseVersion(String repoName) async { try { - final Map? release = await getLatestRelease(repoName); + final Map? release = + await getLatestRelease(repoName); if (release != null) { return release['tag_name']; } else { diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index c4eaeb60f8..8ecf7f3b25 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -33,7 +33,8 @@ class ManagerAPI { Future initialize() async { _prefs = await SharedPreferences.getInstance(); storedPatchesFile = - (await getApplicationDocumentsDirectory()).path + storedPatchesFile; + (await getApplicationDocumentsDirectory()).path + + storedPatchesFile; } String getApiUrl() { @@ -72,7 +73,8 @@ class ManagerAPI { } String getIntegrationsRepo() { - return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo; + return _prefs.getString('integrationsRepo') ?? + defaultIntegrationsRepo; } Future setIntegrationsRepo(String value) async { @@ -132,10 +134,14 @@ class ManagerAPI { List getPatchedApps() { final List apps = _prefs.getStringList('patchedApps') ?? []; - return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList(); + return apps + .map((a) => PatchedApplication.fromJson(jsonDecode(a))) + .toList(); } - Future setPatchedApps(List patchedApps) async { + Future setPatchedApps( + List patchedApps, + ) async { if (patchedApps.length > 1) { patchedApps.sort((a, b) => a.name.compareTo(b.name)); } @@ -237,15 +243,24 @@ class ManagerAPI { } Future downloadManager() async { - return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo); + return await _revancedAPI.getLatestReleaseFile( + '.apk', + defaultManagerRepo, + ); } Future getLatestPatcherReleaseTime() async { - return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo); + return await _revancedAPI.getLatestReleaseTime( + '.gz', + defaultPatcherRepo, + ); } Future getLatestManagerReleaseTime() async { - return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo); + return await _revancedAPI.getLatestReleaseTime( + '.apk', + defaultManagerRepo, + ); } Future getLatestManagerVersion() async { @@ -286,10 +301,12 @@ class ManagerAPI { final List unsavedApps = []; final bool hasRootPermissions = await _rootAPI.hasRootPermissions(); if (hasRootPermissions) { - final List installedApps = await _rootAPI.getInstalledApps(); + final List 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?; @@ -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?; @@ -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; } @@ -372,9 +392,11 @@ class ManagerAPI { Future 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); } @@ -383,7 +405,10 @@ class ManagerAPI { return !existsNonRoot; } - Future hasAppUpdates(String packageName, DateTime patchDate) async { + Future hasAppUpdates( + String packageName, + DateTime patchDate, + ) async { final List commits = await _githubAPI.getCommits( packageName, getPatchesRepo(), @@ -421,9 +446,13 @@ class ManagerAPI { return app != null && app.isSplit; } - Future setSelectedPatches(String app, List patches) async { + Future setSelectedPatches( + String app, + List patches, + ) async { final File selectedPatchesFile = File(storedPatchesFile); - final Map patchesMap = await readSelectedPatchesFile(); + final Map patchesMap = + await readSelectedPatchesFile(); if (patches.isEmpty) { patchesMap.remove(app); } else { @@ -433,7 +462,8 @@ class ManagerAPI { } Future> getSelectedPatches(String app) async { - final Map patchesMap = await readSelectedPatchesFile(); + final Map patchesMap = + await readSelectedPatchesFile(); return List.from(patchesMap.putIfAbsent(app, () => List.empty())); } diff --git a/lib/services/revanced_api.dart b/lib/services/revanced_api.dart index f7626d458c..af04b5bfda 100644 --- a/lib/services/revanced_api.dart +++ b/lib/services/revanced_api.dart @@ -3,11 +3,11 @@ 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'; @@ -15,9 +15,9 @@ 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), ); @@ -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); @@ -50,7 +51,7 @@ class RevancedAPI { Future clearAllCache() async { try { - await _dioCacheManager.clearAll(); + _cacheOptions.store!.clean(); } on Exception catch (e) { if (kDebugMode) { print(e); @@ -61,7 +62,7 @@ class RevancedAPI { Future>> getContributors() async { final Map> contributors = {}; try { - final response = await _dio.get('/contributors', options: _cacheOptions); + final response = await _dio.get('/contributors'); final List repositories = response.data['repositories']; for (final Map repo in repositories) { final String name = repo['name']; @@ -78,7 +79,7 @@ class RevancedAPI { Future> getPatches() async { try { - final response = await _dio.get('/patches', options: _cacheOptions); + final response = await _dio.get('/patches'); final List patches = response.data; return patches.map((patch) => Patch.fromJson(patch)).toList(); } on Exception catch (e) { @@ -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 tools = response.data['tools']; return tools.firstWhereOrNull( (t) => @@ -130,7 +131,10 @@ class RevancedAPI { return null; } - Future getLatestReleaseFile(String extension, String repoName) async { + Future getLatestReleaseFile( + String extension, + String repoName, + ) async { try { final Map? release = await _getLatestRelease( extension, diff --git a/lib/ui/views/contributors/contributors_viewmodel.dart b/lib/ui/views/contributors/contributors_viewmodel.dart index c8c7975fd8..9017bcadc6 100644 --- a/lib/ui/views/contributors/contributors_viewmodel.dart +++ b/lib/ui/views/contributors/contributors_viewmodel.dart @@ -13,12 +13,15 @@ class ContributorsViewModel extends BaseViewModel { Future getContributors() async { final Map> 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(); } } diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index ac55306146..78c8046820 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -25,12 +25,14 @@ import 'package:timezone/timezone.dart' as tz; @lazySingleton class HomeViewModel extends BaseViewModel { - final NavigationService _navigationService = locator(); + final NavigationService _navigationService = + locator(); final ManagerAPI _managerAPI = locator(); final PatcherAPI _patcherAPI = locator(); final GithubAPI _githubAPI = locator(); final Toast _toast = locator(); - final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + final flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); DateTime? _lastUpdate; bool showUpdatableApps = false; List patchedInstalledApps = []; @@ -41,8 +43,11 @@ class HomeViewModel extends BaseViewModel { const InitializationSettings( android: AndroidInitializationSettings('ic_notification'), ), - onSelectNotification: (p) => - DeviceApps.openApp('app.revanced.manager.flutter'), + onDidReceiveBackgroundNotificationResponse: (response) => + notificationTapBackground(response), + onDidReceiveNotificationResponse: (response) { + //TODO: Implement notification tap + }, ); flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< @@ -56,6 +61,11 @@ class HomeViewModel extends BaseViewModel { _managerAPI.reAssessSavedApps().then((_) => _getPatchedApps()); } + @pragma('vm:entry-point') + void notificationTapBackground(NotificationResponse response) { + DeviceApps.openApp('app.revanced.manager.flutter'); + } + void navigateToAppInfo(PatchedApplication app) { _navigationService.navigateTo( Routes.appInfoView, @@ -86,8 +96,10 @@ class HomeViewModel extends BaseViewModel { } Future hasManagerUpdates() async { - final String? latestVersion = await _managerAPI.getLatestManagerVersion(); - final String currentVersion = await _managerAPI.getCurrentManagerVersion(); + final String? latestVersion = + await _managerAPI.getLatestManagerVersion(); + final String currentVersion = + await _managerAPI.getCurrentManagerVersion(); if (latestVersion != null) { try { final int latestVersionInt = @@ -151,7 +163,9 @@ class HomeViewModel extends BaseViewModel { _toast.showBottom('homeView.updatesDisabled'); } - Future showUpdateConfirmationDialog(BuildContext parentContext) { + Future showUpdateConfirmationDialog( + BuildContext parentContext, + ) { return showModalBottomSheet( context: parentContext, isScrollControlled: true, diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index 65df575ec9..4d54f19508 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -17,7 +17,8 @@ import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; class SettingsViewModel extends BaseViewModel { - final NavigationService _navigationService = locator(); + final NavigationService _navigationService = + locator(); final ManagerAPI _managerAPI = locator(); final Toast _toast = locator(); @@ -62,8 +63,11 @@ class SettingsViewModel extends BaseViewModel { try { final File outFile = File(_managerAPI.storedPatchesFile); if (outFile.existsSync()) { - final String dateTime = - DateTime.now().toString().replaceAll(' ', '_').split('.').first; + final String dateTime = DateTime.now() + .toString() + .replaceAll(' ', '_') + .split('.') + .first; await CRFileSaver.saveFileWithDialog( SaveFileDialogParams( sourceFilePath: outFile.path, @@ -83,7 +87,8 @@ class SettingsViewModel extends BaseViewModel { Future importPatches() async { try { - final FilePickerResult? result = await FilePicker.platform.pickFiles( + final FilePickerResult? result = + await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['json'], ); @@ -111,7 +116,7 @@ class SettingsViewModel extends BaseViewModel { Future getSdkVersion() async { final AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo; - return info.version.sdkInt ?? -1; + return info.version.sdkInt; } Future deleteLogs() async { diff --git a/lib/utils/check_for_gms.dart b/lib/utils/check_for_gms.dart index 79474eae18..86a3a5f020 100644 --- a/lib/utils/check_for_gms.dart +++ b/lib/utils/check_for_gms.dart @@ -3,8 +3,9 @@ import 'package:device_apps/device_apps.dart'; Future checkForGMS() async { - bool isGMSInstalled = true; - isGMSInstalled = await DeviceApps.isAppInstalled('com.google.android.gms') || - await DeviceApps.isAppInstalled('com.android.vending'); + // bool isGMSInstalled = true; + final bool isGMSInstalled = + await DeviceApps.isAppInstalled('com.google.android.gms') || + await DeviceApps.isAppInstalled('com.android.vending'); return isGMSInstalled; } diff --git a/pubspec.yaml b/pubspec.yaml index 19c087728e..b7a9162dc8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,80 +10,82 @@ environment: sdk: ">=2.17.5 <3.0.0" dependencies: - animations: ^2.0.4 + animations: ^2.0.7 app_installer: ^1.1.0 - collection: ^1.16.0 + collection: ^1.17.0 cross_connectivity: ^3.0.5 cr_file_saver: ^0.0.2 device_apps: git: url: https://github.com/ponces/flutter_plugin_device_apps ref: revanced-manager - device_info_plus: ^4.1.2 - dio: ^4.0.6 - dio_brotli_transformer: ^1.0.1 - dio_http_cache_lts: ^0.4.1 - dynamic_color: ^1.5.4 + device_info_plus: ^8.1.0 + dio: ^5.1.1 + dio_cache_interceptor: ^3.4.1 + # dio_brotli_transformer: ^1.0.1 + # dio_http_cache_lts: ^0.4.1 + dynamic_color: ^1.6.2 dynamic_themes: ^1.1.0 expandable: ^5.0.1 file_picker: git: url: https://github.com/alexmercerind/flutter_file_picker ref: master - flex_color_scheme: ^6.0.0 + flex_color_scheme: ^6.1.2 flutter: sdk: flutter - flutter_background: ^1.1.0 + flutter_background: ^1.2.0 flutter_cache_manager: ^3.3.0 flutter_i18n: ^0.32.4 - flutter_local_notifications: ^9.8.0+1 + flutter_local_notifications: ^13.0.0 flutter_localizations: sdk: flutter - flutter_svg: ^1.1.1+1 - fluttertoast: ^8.0.9 - font_awesome_flutter: ^10.1.0 + flutter_svg: ^2.0.4 + fluttertoast: ^8.2.1 + font_awesome_flutter: ^10.4.0 get_it: ^7.2.0 - google_fonts: ^3.0.1 - http: ^0.13.4 - injectable: ^1.5.3 + google_fonts: ^4.0.3 + http: ^0.13.5 + injectable: ^2.1.1 intl: ^0.17.0 - json_annotation: ^4.6.0 + json_annotation: ^4.8.0 logcat: git: url: https://github.com/SuaMusica/logcat ref: feature/nullSafe - native_dio_client: ^0.0.1-dev+1 - package_info_plus: ^1.4.3+1 - path_provider: ^2.0.11 - permission_handler: ^10.0.0 + native_dio_adapter: ^0.1.0 + # native_dio_client: ^0.0.3 + package_info_plus: ^3.0.3 + path_provider: ^2.0.14 + permission_handler: ^10.2.0 pull_to_refresh: ^2.0.0 root: git: url: https://github.com/gokul1630/root ref: main share_extend: ^2.0.0 - shared_preferences: ^2.0.15 + shared_preferences: ^2.1.0 skeletons: ^0.0.3 stacked: ^3.2.0 - stacked_generator: ^1.0.0 + stacked_generator: ^1.0.1 stacked_services: ^1.0.0 - stacked_themes: ^0.3.9 - timeago: ^3.2.2 - timezone: ^0.8.0 - url_launcher: ^6.1.5 + stacked_themes: ^0.3.10 + timeago: ^3.3.0 + timezone: ^0.9.1 + url_launcher: ^6.1.10 wakelock: ^0.6.2 flutter_dotenv: ^5.0.2 - pub_release: ^8.0.3 - flutter_markdown: ^0.6.13 + # pub_release: ^8.1.1 + flutter_markdown: ^0.6.14 dev_dependencies: - json_serializable: ^6.3.1 + json_serializable: ^6.6.1 build_runner: any - flutter_launcher_icons: ^0.10.0 + flutter_launcher_icons: ^0.12.0 flutter_lints: ^2.0.1 flutter_test: sdk: flutter - injectable_generator: ^1.5.4 + injectable_generator: ^2.1.5