mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: potentially fix manager stuck on black screen
This commit is contained in:
parent
9e8c6383cc
commit
c2021d508e
@ -3,20 +3,23 @@ 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_adapter/native_dio_adapter.dart';
|
||||
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(),
|
||||
maxStale: const Duration(days: 1),
|
||||
priority: CachePriority.high,
|
||||
);
|
||||
|
||||
final Map<String, String> repoAppPath = {
|
||||
'com.google.android.youtube': 'youtube',
|
||||
'com.google.android.apps.youtube.music': 'music',
|
||||
@ -30,13 +33,29 @@ class GithubAPI {
|
||||
|
||||
Future<void> initialize(String repoUrl) async {
|
||||
try {
|
||||
if (Platform.isIOS || Platform.isMacOS || Platform.isAndroid) {
|
||||
final CronetEngine androidCronetEngine = await CronetEngine.build(
|
||||
userAgent: 'ReVanced Manager',
|
||||
enableBrotli: true,
|
||||
enableQuic: true,
|
||||
);
|
||||
_dio.httpClientAdapter =
|
||||
NativeAdapter(androidCronetEngine: androidCronetEngine);
|
||||
|
||||
_dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: repoUrl,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: repoUrl,
|
||||
),
|
||||
);
|
||||
|
||||
_dio.interceptors.add(_dioCacheManager.interceptor);
|
||||
_dio.interceptors.add(DioCacheInterceptor(options: _cacheOptions));
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
@ -46,7 +65,7 @@ class GithubAPI {
|
||||
|
||||
Future<void> clearAllCache() async {
|
||||
try {
|
||||
await _dioCacheManager.clearAll();
|
||||
await _cacheOptions.store!.clean();
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
@ -58,7 +77,6 @@ class GithubAPI {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'/repos/$repoName/releases',
|
||||
options: _cacheOptions,
|
||||
);
|
||||
return response.data[0];
|
||||
} on Exception catch (e) {
|
||||
@ -83,7 +101,6 @@ class GithubAPI {
|
||||
'path': path,
|
||||
'since': since.toIso8601String(),
|
||||
},
|
||||
options: _cacheOptions,
|
||||
);
|
||||
final List<dynamic> commits = response.data;
|
||||
return commits
|
||||
|
@ -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,10 +15,11 @@ 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(),
|
||||
maxStale: const Duration(days: 1),
|
||||
priority: CachePriority.high,
|
||||
);
|
||||
|
||||
Future<void> initialize(String apiUrl) async {
|
||||
@ -33,14 +34,25 @@ class RevancedAPI {
|
||||
);
|
||||
log('ReVanced API: Using default engine + $isGMSInstalled');
|
||||
} else {
|
||||
_dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: apiUrl,
|
||||
),
|
||||
)..httpClientAdapter = NativeAdapter();
|
||||
if (Platform.isIOS || Platform.isMacOS || Platform.isAndroid) {
|
||||
final CronetEngine androidCronetEngine = await CronetEngine.build(
|
||||
userAgent: 'ReVanced Manager',
|
||||
enableBrotli: true,
|
||||
enableQuic: true,
|
||||
);
|
||||
_dio.httpClientAdapter =
|
||||
NativeAdapter(androidCronetEngine: androidCronetEngine);
|
||||
|
||||
_dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: apiUrl,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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 +62,7 @@ class RevancedAPI {
|
||||
|
||||
Future<void> clearAllCache() async {
|
||||
try {
|
||||
await _dioCacheManager.clearAll();
|
||||
await _cacheOptions.store!.clean();
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
@ -61,7 +73,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'];
|
||||
@ -78,7 +90,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) {
|
||||
@ -94,7 +106,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) =>
|
||||
|
@ -20,9 +20,7 @@ dependencies:
|
||||
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
|
||||
dio: ^5.0.0
|
||||
dynamic_color: ^1.5.4
|
||||
dynamic_themes: ^1.1.0
|
||||
expandable: ^5.0.1
|
||||
@ -52,7 +50,7 @@ dependencies:
|
||||
git:
|
||||
url: https://github.com/SuaMusica/logcat
|
||||
ref: feature/nullSafe
|
||||
native_dio_client: ^0.0.1-dev+1
|
||||
native_dio_adapter: ^0.1.0
|
||||
package_info_plus: ^1.4.3+1
|
||||
path_provider: ^2.0.11
|
||||
permission_handler: ^10.0.0
|
||||
@ -75,6 +73,7 @@ dependencies:
|
||||
flutter_dotenv: ^5.0.2
|
||||
pub_release: ^8.0.3
|
||||
flutter_markdown: ^0.6.13
|
||||
dio_cache_interceptor: ^3.4.0
|
||||
|
||||
dev_dependencies:
|
||||
json_serializable: ^6.3.1
|
||||
|
Loading…
Reference in New Issue
Block a user